• How Many Of Your Ads Are Being Blocked? Updated!

    by  • Last modified:September 8, 2013 • Google Analytics • 7 Comments

    Background of Adblocking with Google Analytics
    A while ago I shared some code for webmasters who wanted to know how many of their users were blocking ads. The code I created was for Piwik and Google Classic analytics. As more users make their way to using the Universal Analytics, this code did not work. Below is a complete rewrite of the code for Google Analytics Universal. It does however require a couple more steps. Follow them along and you will have accurate Adblock number shortly.

    Setting up decoy file

    The first step is to create a file called “adcheck.js”, but to be honest you can call it whatever you want. Inside, paste the below:

    document.write('<div id="faker"><p>&nbsp;</p></div>');
    

    Save it, and load it to your sever. This file will test if adblock is on or not.

    Adding the Google Analytics Tracking

    Now that you have the file on your server, you just need to update the below code with the path of where the “adcheck.js” is located (as noted by the comments).

    <!--change path to adcheck.js-->
    <script type="text/javascript" src="http://www.yoursite.com/adcheck.js"></script> 
    <!--do not alter below-->
    
    <script type="text/javascript">
    if (document.getElementById("faker") != undefined)
    {
    ga('send', {
      'hitType': 'event',          // Required.
      'eventCategory': 'adblock',   // Required.
      'eventAction': 'view',      // Required.
      'eventLabel': 'false',
    })
    }
    else{
    ga('send', {
      'hitType': 'event',          // Required.
      'eventCategory': 'adblock',   // Required.
      'eventAction': 'view',      // Required.
      'eventLabel': 'true',
    });
    }
    </script>
    

    The above code can be placed anywhere on the page below your Google Analytics tracking code.

    The last step is to add the below to your CSS

    #faker{display:none;}
    

    Results
    After you got it working, you will be able to see results under content in the events window. Below is an example of what you will see. As you can see it will show you how many ads were blocked. I prefer the pie view:

    adblock events check google analytics

    To make getting these results faster, this file has all you need to get started.

    A note of caution
    With Universal Analytics you have much more flexibility, but writing code makes it more complex as each setup will now be different. Therefore as it stands now, the above code will only track number of pageviews with ads blocks, not the number of users blocking ads. To do this you need to create a “custom dimension” in the backend of your Google Analytics admin. This is beyond the scope of this article. In short, I would use the “user scope”, fill in the parameters and add above code as appropriate below. Here is an example of what that looks like

    var adblock = 'true';
    ga('set', 'dimension1', 'adblock');
    

    You can read more about custom dimensions here. This portion has not been tested, but should work.

    One final word
    Enjoy this code and have fun. Make sure to test in your environment, with the handy GA Debugger tool. And finally remember this will only track users who have Javascript enabled. Those using no script will not be counted, but at least you will have a better idea of how many people are seeing your ads. Happy tracking!

    About

    About The Author: Adrian has over 12 years experience in Digital Marketing and Analytics. He currently works as a Marketing Manager at Vanilla Forums, a modern forum software platform that allows clients to connect and engage their communities and customers. Adrian has extensive experience with Google and Piwik Analytics. He lives and works in Montreal.

    • Stephane

      Great and thanks Adrian, you’re a crack! I implemented this code and it works perfectly, the code took effect directly into Google Analytics. Finally I just replaced “false” by “off”, and “true” by “on” because it speaks better to me. Well, the code only track the number of page views and this is what I was looking for.

      So now, I am so curious to see after several days what is the conclusion, if most of my visitors are using Adblock or not! Well, thanks 1000 times this code will be very useful for me.

      the above code will only track number of pageviews with ads blocks

    • Hi @adriansonline:disqus

      I’m running my site on the Google Blogger Platform which does not allow me to add a file to their servers.

      Is there anyway to modify the above code to work so that I can still track the adblocks numbers without uploading a file?

      • You can use the old code from the previous article mentioned. The above code is for universal google analytics. Most people are using classic Google Analytics. The other option is to host the JavaScript remotley. There are many services to do that. Personally, this to me has been the most effective way to test Adblock.

        • @adriansonline:disqus Thanks for getting back so quickly ;)

          Cool, I was not sure if the old worked still. I’ll give that a go.

          Many thanks.

    • Shelly Renee

      What’s the best way to contact you, Adrian? I have a couple of questions concerning Analytics for my site, MissedStitches.com. An article of yours that I am currently implementing the code snippet from (the subject material, not the article itself) is giving me issues. I look forward to your reply.