TQ
dev.com

Blog about software development

Subscribe

Ad block detection

19 Aug 2016 - by 'Maurits van der Schee'

More and more people use ad blockers and more and more sites try detect them. Sites say that their visitors are stealing their content, by not "paying" by viewing ads, while visitors claim that sites do not comply with the law and blocking third party contents is the only way to protect their privacy when using the Internet.

Nothing against ads

I have nothing against ads, but the practices of the "ad tech" industry are appalling. The "ad tech" industry mainly consists of ad "brokers". The most well-known player in that market is "Google ads". Some of these brokers (if not all) allow their clients to run scripts on the sites the site owners request ads for.

That's not really what we agreed right? The "paid ads" deal to the uninitiated sounds more like "I will get money for you showing ads" and not "I will get money so that you can extensively track/profile the unsuspecting visitors of my site using arbitrary code". This arbitrary code can either be flash or JavaScript and it can find out great deal about you.

How we should fix the web

I'm not the type of guy that would complain about something without presenting a solution, so here it goes. I feel a new type of ad broker should arise, that would simply do what we expect from ad brokers: serve images (not scripts/flash) from their domain to your visitors on behalf of their clients and report the traffic to both parties. What is so hard about that? It should use pattern analysis and reputation databases to detect fraud instead of fighting a JavaScript obfuscation war. NB: I would call the company "White Ads" (which is a reference to "White Hats": hackers with good intentions).

Warn users that do NOT use ad blockers

Below you find an easy ad blocker detection script, so that you can warn your users that they put their privacy at risk by not enabling an ad blocker.

Are ads blocked?

You should see the answer to the question in either red (No) or green (Yes). The code for this detection is:

<script>var adsAreBlocked=true</script> <script src="/js/ads.js"></script> <script>document.write(adsAreBlocked?'<p style="color:green">Yes</p>':'<p style="color:red">No</p>')</script> <noscript><p style="color:green">Yes</p></noscript>

The URL "/js/ads.js" points to a javascript file on the server containing the following content:

adsAreBlocked=false;

With the above JavaScript you can help your visitors become more aware of their privacy.


PS: Liked this article? Please share it on Facebook, Twitter or LinkedIn.