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 owner 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, thus I’ve made my own. 🙂

I use google ads, thus I only detect if those specific ads are blocked.
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)

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);
};

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…




Here is another way to detect ad-blockers: https://www.detectadblock.com
While my version checks if ad is shown, this version tries to check, if there is any ad-blocker at all.
It might not always work right away, 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?

2 thoughts on “Javascript Adblock detector”

Leave a Reply