Since version 2.0.73 plugin Simple Ads Manager supports caching plugins . He really supports ALL caching plugins and it’s great . But there is a small fly in the ointment. This fly is javascript function {javascript}document.write(){/javascript}.
This function can be used only in the process of building DOM (Document Object Model) and it absolutely can not be used after the DOM has already been built. However, when SAM is used in caching plugins compatibility mode, it inserts advertisements into a document using AJAX requests after the browser is already built DOM of document. Inserting function {javascript}document.write(){/javascript} in the output document at this point, guaranteed kills this document!
How to deal with this problem I want to talk about in this article. If you do not use javascript codes as codes of advertisements, then you have nothing to worry about. Otherwise, you should read this article.
The only true way to combat this scourge, is the removal of function {javascript}document.write(){/javascript} from code of the ad. For this purpose it is necessary to inspect an ad code regarding this function. For example, survey the code of Yandex Direct ads:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<script type="text/javascript"> //<![CDATA[ yandex_partner_id = 00000; yandex_site_bg_color = 'FFFFFF'; yandex_ad_format = 'direct'; yandex_font_size = 1.1; yandex_direct_type = 'flat'; yandex_direct_limit = 2; yandex_direct_title_font_size = 3; yandex_direct_title_color = 'CC0000'; yandex_direct_url_color = '000000'; yandex_direct_text_color = '000000'; yandex_direct_hover_color = 'FF0000'; yandex_direct_favicon = true; yandex_no_sitelinks = true; document.write('<sc'+'ript type="text/javascript" src="//an.yandex.ru/system/context.js"></sc'+'ript>'); //]]> </script> |
What to do? Just replace the {javascript}document.write(){/javascript} with what they wanted to write to the document during its creation:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<script type="text/javascript"> //<![CDATA[ yandex_partner_id = 00000; yandex_site_bg_color = 'FFFFFF'; yandex_ad_format = 'direct'; yandex_font_size = 1.1; yandex_direct_type = 'flat'; yandex_direct_limit = 2; yandex_direct_title_font_size = 3; yandex_direct_title_color = 'CC0000'; yandex_direct_url_color = '000000'; yandex_direct_text_color = '000000'; yandex_direct_hover_color = 'FF0000'; yandex_direct_favicon = true; yandex_no_sitelinks = true; //]]> </script> <script type="text/javascript" src="//an.yandex.ru/system/context.js"></script> |
It’s very simple … If the function is defined clearly… And if not?
If not, create a test HTML document and paste the code into it. For example (Text Links Ads):
1 2 3 4 5 6 |
<script type="text/javascript"> /* <![CDATA[ */ function affiliateLink(str){ str = unescape(str); var r = ''; for(var i = 0; i < str.length; i++) r += String.fromCharCode(4^str.charCodeAt(i)); document.write(r); } affiliateLink('8e%24lvab9%26lppt%3E++sss*pa%7Cp%29hmjo%29e%60w*gki+%3Bvab976523%3C%26%3A8mic%24wvg9%26lppt%3E++sss*pa%7Cp%29hmjo%29e%60w*gki+miecaw+fejjavw+fqmh%60%2936%3C%7C%3D4*cmb%26%24fkv%60av9%264%26%24ehp9%26Pa%7Cp%24Hmjo%24E%60w%26+%3A8+e%3A'); /* ]]> */ </script> |
Open the document code, it is possible, in any browser, and see what came of it:
1 |
<a href="//www.text-link-ads.com/?ref=321678"><img src="//www.text-link-ads.com/images/banners/build-728x90.gif" border="0" alt="Text Link Ads"></a> |
This code is not difficult to transform to data for image mode of plugin:
That’s it. If you always will follow these instructions, you will not have problems with Simple Ads Manager caching plugins compatibility mode.
Good luck!
© 2014, minimus. All rights reserved.
Since the update I have the problem, that with active SAM i cannot choose the image sizes of the images which i will to insert into an article. With deactivation of SAM everything works fine.
Total Comments by Jerry: 2
Try 2.1.77 – bug is resolved…
Hi,
I tried to install and make SAM run on my site. If I let it run in PHP mode, all is fine… but since I have a caching plugin, I need to let it run in js mode. Here I have trouble: I get the error 403 forbidden all the time and the widget does not display.
The console log I have, is the following:
jquery.js?ver=1.10.2:5
jquery.js?ver=1.10.2:5
sam-layout.min.js?ver=2.2.80:1
jquery.js?ver=1.10.2:3
jquery.js?ver=1.10.2:3
sam-layout.min.js?ver=2.2.80:1
jquery.js?ver=1.10.2:3
jquery.js?ver=1.10.2:3
jquery.js?ver=1.10.2:3
I’m using WP super cache and BWP minify, but I get the same error even though I disable them both. The only way I can make it work is with SAM in PHP mode but because of the caching it’s not working properly (always displaying the same ad..)
Any suggestion? Thank you!
Total Comments by Diego: 8
403 – Access is denied. Check access permissions to the folder and files of plugin. Should be 755 or 644.
Thanks for the answer! Sorry I forgot to mention that I checked the plugin’s permissions and all folders and files are 755 or 644.
Total Comments by Diego: 8
Read here and try to resolve this problem using all methods from article.
Thanks again for your time,
I tried again following your instructions and the document you suggested me. I’ve also setup a local version of wordpress and run it locally. On the local instance I run WP version 3.8 and the latest version of your plugin. In this case it does not give me the 403 error but it just does not display the ad images. Any more suggestions? What else could I do to make it work in caching compatible mode?
Thank you
Total Comments by Diego: 8
Now I set all the permissions for the plugins’ files to be 755. If I access the file sam-ajax-loader.php directly from the URL bar, it gives me back the value -1 (if I set the permissions as 777 it says forbidden). But on my site’s page I still have a 403 message in my console…
Therefore the GET request passes through while the POST request does not… Is it possible that the permissions filter on 2 different levels the requests? But if so, why other plugins I have do not have these issues?
Just trying to tickle my brain to come to a solution..
Total Comments by Diego: 8
So the problem seems to be the POST request… do you know if it can be turned into a GET in the code?
Thanks
Total Comments by Diego: 8
YAY! Solution found, it was something on the .htaccess file that had to be modified to allow POST requests on PHP modules. This code:SecFilterEngine OffSecFilterScanPOST Off [/xml]
[xml]
The service provider is Netsons.
Thank you for your patience and help!
Total Comments by Diego: 8
Excellent! Good news.
…and it does not work 🙁
Total Comments by Diego: 8
Hi minimus,
thanks for your great work! How about dynamically loading AdSense codes on cached pages like when I have 2 banners I want to test?
Thanks
Thomas
Total Comment by Thomas: 1
Hi!
I am using W3 Total Cache and SAM – but sadly those two deliver the same ad for all 4 adsblock I have defined – and not one of the 12 others mixed into it ^^
Oh, nevermind – it works now. It seems the two have a problem with each other if I freshly empty the cache.
Total Comments by Franz Sauerstein: 2
Ребята, на WP 3.9 не пашет кнопочка в визуальном редакторе, можете подправить , выпустить обновление?
Так люблю ваш плагин!
Total Comment by lorlus: 1
Since I updated to WP 3.9, I have lost the pulldown on the “New Post” page. I can’t simply select which AdPlace to use. I now have to copy and paste from an older post. What am I doing wrong? Thanks for this excellent plugin! -Steve
Total Comment by Steve: 1
[…] Read here… […]
[…] I understood almost nothing, but maybe you need to read this article. […]