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=""
<!-- test -->
<ins class="adsbygoogle"
     (adsbygoogle = window.adsbygoogle || []).push({});

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

window.onload = 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:

Here is another way to detect ad-blockers:
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:


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