Track the use of AdBlock in Google Analytics

As a publisher that is highly dependent on ad revenue, it is important to know how many people are blocking your ads with a browser extension as AdBlock. It it possible to track how many users are using this software in Google Analytics with some help from the Google Tag Manager.

The trick is loading some Html which is blocked by AdBlock. With some Javascript we detect if this Html is blocked whether or not.  I have used a solution that is mentioned on

First we have to create a new Custom Html tag. Inside it we have our fake Advertisement.

After this we include jQuery, and our script to dectect if our fake advertisement is shut down by determining the height of our div.

adblock tag script

We wil fire this tag on All pages.

And the code:

Code explanation

If our fake advertisement is reduced to a height of zero there’s an AdBlocker in town. When this is the case we would update our dataLayer. We instantiate a new event called adBlock and set adBlockDetected to 1. When there isn’t a Adblocker we set adBlockDetected to 0.

To retrieve the value of our updated dataLayer we could create a new Data Layer variable. We are searching for the adBlockDetected variable name. Besides we set a default value of 0 in case the variable isn’t updated.

datalayer variable adblock detected

Next step is setting up a new trigger based on a Custom Event. We will fire it when our event, named adBlock, occurs.


trigger event adblock

To store the information we could use Google Universal Analytics. With a custom dimension it is possible to store this info on a User scope.

Browse in the Google Universal Analytics admin to Custom Dimensions. Create a new Custom dimension here. Set the scope to User and make it active.

admin google analytics custom dimension


After creating it, we have to remember the index. In my example it is number 9.custom dimension

Now we have set the Custom Dimension we could use it to setup our Google Universal Analytics tag.

universal analytics event adblock

Set Non-Interaction Hit to True. Because this event should not affect your bounce rate.  Tap More settings and add the below given settings. Use your own index number!

custom dimensions more settings google analytics

Fire this tag with our Event – Adblock trigger.

universal analytics event adblock fire on


Test if everything works fine.


preview mode adblock testing

Now our info will be stored in Google Analytics after a couple of hours (about three)!

adblockers events google analytics


Was it interesting? Share it, so someone else can read this too!Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

19 thoughts on “Track the use of AdBlock in Google Analytics”

  1. I do consider all the concepts you’ve offered in your post.
    They’re very convincing and can definitely work. Nonetheless, the posts are very short for beginners.
    Could you please lengthen them a bit from next time?
    Thanks for the post.

    1. For sure! I’m trying to find a balance between the length of a post and the amount of info to keep it readable for non-beginners. I will serve additional explanations on a later moment!

  2. Hi Marthijn,

    this is a nice one! Haven’t test it yet but does the custom HTML also working with an older jquery libary?

    Thank you!

  3. Hi Marthijn,
    I have used your method on several websites and always see 0.01% of Internet Explorer users using Adblock. Do you have any idea what the problem can be?

    It seems to work fine with other browsers (18% on Firefox).


  4. Thanks for sharing, Marthijn!
    Why would you need the if (bottomad.length == 1) and window.settimeout though? Shouldn’t if(bottomad.height == 0) be sufficient? And what’s the point of delaying your code for 1 millisecond.

    1. Hi David, to prevent javascript errors, just in case jQuery wasn’t loaded.

      For the timeout i have to refer to the Stackoverflow topic:

      As can be seen, I’m using setTimeout with at least a timeout of 1ms. I’ve tested this on various browsers and most of the time, directly checking for the element in ready always returned 0; no matter whether the adblocker was active or not. I was having two ideas about this: either rendering wasn’t yet done or Adblock didn’t kick in yet. I didn’t bother to investigate further.

  5. People have the right to circumvent the use of tracking on the Internet. Adverts are served by companies who track Internet users- I don’t want to see their advertisements…

Leave a Reply

Your e-mail address will not be published. Required fields are marked *