Javascript Adblock detector

As most of my games revenue is coming from ads including website ads shown at Pozirk Games, I need to make sure those ads are actually working.
Ad-blockers cause some troubles for website owners like me, and even though I don’t like ads myself, there is nothing free in this world.
If it’s not advertisers who pay, then it should me or players. I prefer advertisers.
I’ve searched and tried different ways to detect ad-blockers, but I couldn’t find an universal javascript snippet that works for any ad-blocker, so I’ve made my own. 🙂

I use google ads, thus I only detect if those specific ads are blocked. You can definitely change that to any other ads.
As of today, my code can detect that an ad was blocked by the following ad-blockers:
– Adblock
– Adblock Plus
– Ghostery
– uBlock Origin – was hardest to detect
– Vivaldi build-in blocker
– Firefox built-in blocker (strict mode)
– Edge built-in blocker (strict mode)
– Brave Shields

My test banner code:

<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-2519721047713075"
     crossorigin="anonymous"></script>
<!-- inside.pozirk.com test -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-2519721047713075"
     data-ad-slot="9121244729"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>

And here is my javscript code to detect ad-blockers:

window.onload = function()
{
  setTimeout(function()
  {
    var ad = document.querySelector('ins.adsbygoogle');
    if(ad == null || ad.innerHTML.length == 0 || ad.offsetWidth == 0 || ad.offsetHeight == 0)
    {
      //ad-blocker detected
    }
  }, 5000);
};

Quite simple, right? I have timer set to 5 seconds to wait for the ad to load, you can change that to your liking.

The code above in action:
AD-BLOCK DETECTOR: RESULTS IN 5 SECONDS…




There is another way to detect ad-blockers: Detect Adblock.
While my version checks if ad is shown, this version tries to check, if there is any ad-blocker at all.
There are might be some technical issues to implement this method, like in my case I have JS Minify, so sailthru.js file should be added to the exclusion list first.
In the future this file name might be changed and excluded from filters.
Also, detector will stop working, but ads still will be blocked if, for example, I add the following line to uBlockOrigin filter:

@@||www.detectadblock.com/sailthru.js$script,domain=www.detectadblock.com

In the end what do you want to check, that visitors have an ad-blocker or that they see your ad?

4 thoughts on “Javascript Adblock detector”

  1. Well, still looks like my way is better, because “sailthru.js” is not on a block list anymore, but “kampyle.js” is.
    After some time it might be a different file again, thus adblock detection, suggested by Detect Adblock, will stop working and you have to change the file name again.

  2. Also, Detect Adblock does not detect Tracking prevention (Strict) by MS Edge.
    While my version still detects it with no problems.
    Unlike Balanced, Strict mode blocks Google Adsense, so this is important.

Leave a Reply