Stop Ad-Block Plus from removing AdSense Ads
Ronald MacDonald <firstname.lastname@example.org>
And so you run a website. Like me. Probably a small one. Like me. And you run Google AdSense. Like me. Yet, somehow, the numbers just don’t add up.
This technique redirects your visitor to a pre-designated page if they happen to access your site with an ad-blocker. We don’t change any of Google’s code and so your Terms of Service with Google should be safe.
No redirection will occur on a non-JS browser, though non-JS clients would not see Google’s ads anyway, so it’s no great loss.
The script relies on the fact that the regex used by AdBlock Plus is quite loose and so will block any script sitting within any file called adsense.js. I’ve also changed a couple of the options to include other blocking applications into the work-around.
- The script will fail to work if the maintainers of ABP etc tighten their regexes.
- DNS lookups can take some time, depending on where your server is and which DNS servers you use. Think carefully before deploying this technique across your entire site.
- Corporate users may not be able to change their block-lists. Again, think carefully, or you might end up blocking many from using your site.
- The script can be modified to provide a Goodwill feature - ie. users will be able to revisit your page without the ads, on the basis of them affirming they’ve no way of unblocking the adverts.
- PHP/FastCGI etc
- Some form of web server (I use nginx)
TITLEWe’re looking up the reverse DNS of the remote client. That means our lookups have to be super-quick. A quick
dig google.comon the web server should show how fast your upstream DNS server’s initial response is. Remember on a public DNS server that a site like Google will be requested frequently and as such, answered from the DNS’s cache. So try a couple of other names just to check.
We’re wanting the code to look something like this:
$redirect is set to TRUE [in adverts.js]: $redirect is set to FALSE (if JS is loaded) if $redirect is TRUE then redirect_to_page
- Code seems to work OK
- Users need to be taken back to the original page
- $_SESSION or encrypted $_GET would be best (2-way RC4?)
Create the file /adsense/adsense.js on the root of the site you wish to protect from ABP and similar applications and put the following line in it:
Now, if you’re also wishing to undermine Squid’s AdZapper application, add the following line as well:
The script, situated at
example.com/adsense/adsense.js, should read as follows:
At the bottom of each page you wish to 'protect'
|Make sure the path is correct.|
|Remember to replace example.com with your own domain and path.|
|Change the encrypting phrase to something of your own choice.|
Upon being redirected, users with ABP etc enabled are shown this page. You can be as explicit as you like but the page should contain a link which they can us so as to return to the last page.
Using the same encryption phrase as before, the link to return could be returned as follows:
<a href="http://www.example.com<?php $rc4 = new rc4crypt; echo rawurldecode($rc4->endecrypt("Bollocks.", urldecode(base64_decode($_GET['url'])))); ?>">Disable AdBlock for this site before clicking here to return</a>
|Yes, even that extra '.' will stop the whole thing working properly ;-)|
This line sets the trap to FALSE so that the redirect does not occur. Then:
- Gets the hostname of the connecting client
- Compares it to .googlebot.com
- Upon match, keeps the trap 'disabled'
Redirects users who have not loaded the fake adsense.js to a custom page, explaining why it’s a good idea to keep adverts enabled.
The return-address is encrypted and hashed using a string that only we know (in this case, something about sheep). Encryption mitigates XSS attacks and hashing ensures URL contains only 'legal' characters.