• 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',
    ga('send', {
      'hitType': 'event',          // Required.
      'eventCategory': 'adblock',   // Required.
      'eventAction': 'view',      // Required.
      'eventLabel': 'true',

    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


    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 The Author: Adrian has over 12 years experience in Digital Marketing and Analytics. He currently works as a Marketing Head of Community 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 (Matomo) Analytics. He lives and works in Montreal.