• How Many Users Block Your Ads? Find Out!

    by  • Last modified:March 10, 2013 • Google Analytics, Piwik • 13 Comments

    Your Visitors Block Ads, But How Many?
    Have you ever been curious to know how many people are blocking ads on your site? I had try to measure this in the past, but today I have a much more elegant solution.

    Why Bother Tracking If People Don’t See Ads?
    One of the reasons I wanted to know how much adblocking was occurring is to make the determination if serving ads was even worthwhile. Sure if you have Adsense, you get a feel for the revenue, but do you know how many extra eyeballs never even see the ads? Maybe 90% of your users block ads? Maybe you need to get creative in your advertising? Maybe you should remove ads altogether if you need a source of revenue?

    Some Caveats About Ad Block Tracking
    If a user is intent on not being tracked, this solution will not work. In other words, if they are using no script or blocking trackers all together, they will not be counted. There are work-arounds for this, but there is a whole new set of problems with tracking noscript referrers. If you are not aware, bots do not read javascript so your log/analytics could get swamped by hits from bots, crawlers and other beings that may or may not be real. Nevertheless, taking this into account and having an adblock number can still give you some interesting insights about your visitors.

    Choose your solution
    No matter your analytics solution, either Google Analytics or Piwik Analytics, below is how you would find out if users are blocking ads.

    First Step: jQuery
    Please make sure you have your Google or Piwik tracking installed and working. You will also need the jQuery Library on your site. The easiest way
    to add this is use the Google hosted jQuery Library. Just add this code to your site:

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

    Second Step: Your Ads
    The next step is to mark up your Ads div. If you don’t want to mark up the div, or are not sure how to, just add the below to anywhere on the page.

    <div class="adsense"><p>&nbsp;</p></div>

    Third Step: Tracking – Google Analytics

    For Google Analytics you can do the tracking as an event or a custom variable. Just make sure the div is the same as denoted in this portion of the code: if ($(".adsense"). If you use our default implementation or your div name is “adsense” you are fine.

    Custom Variable Code

    /* Adblock Check */ 
    $(document).ready(checkAds());
    
    function checkAds() {
            if ($(".adsense").height() == "0") {
            document.write("<script> _gaq.push(['_setCustomVar', 5, 'Adblock','Blocked',2]);<\/sc" + "ript>");}    
    		else
    		{
    		document.write("<script> _gaq.push(['_setCustomVar', 5, 'Adblock','UnBlocked',2]);<\/sc" + "ript>");}	
    		}	
    /* End Adblock Check */ 
    

    Here is the Adblock Event Tracking Code:

    <!--Adblock Check-->
    <script>
    $(document).ready(checkAds());
    
    function checkAds() {
            if ($(".adsense").height() == "0") {
            document.write("<script>_gaq.push(['_trackEvent', 'Adblock', 'Blocked', 'true',,true]);<\/sc" + "ript>");}    
    		else
    		{
    		document.write("<script>_gaq.push(['_trackEvent', 'Adblock', 'Unblocked', 'false',,true]);<\/sc" + "ript>");}	
    		}	
    </script>
    <!--End Adblock Check-->
    

    Personally I would use the custom variable option. The benefit of using custom variables is you can easily use it to see behavioural differences of those that block ads vs. those who do not. Only do this if you have the slots in Google Analytics. If you were not aware, the free version of Google Analytics limits you to 5 custom variable slots per session. To account for this, I have set the code to take slot 5. If you need all 5 custom variable slots, use the event tracking. Don’t cry if you have to use the events code. You can still see how Adblock visits affect your traffic by using Advanced Segements. You can see here for more details on how to use Advanced Segments and Events.

    Sometimes, when you are using custom variables, it’s hard to place it within the core Google Tracking Code. If your adblocking check must happen later in the page, after the initial call to _gaq.push(['_trackPageview']);, there are two solutions: One is to use a virtual pageview, which you would filter out of the account (i.e. _gaq.push(['_trackPageview', '/fakepage]); ). The reason you would do this is to reinstantiate the tracker, by causing a tracking GIF request. This in turn will help to deliver the custom variable to your Google Analytics. The other, solution to refire the tracking GIF request is to call an event after you set the custom variable. Below is the sample code to do that.

    <!--GA Adblock Check-->
    <script>
    $(document).ready(checkAds());
    function checkAds() {
    if ($(".adsense").height() == "0") {
    document.write("<script>_gaq.push(['_setCustomVar',5,'Adblock','true',2]); _gaq.push(['_trackEvent','Adblock','true']);<\/sc" + "ript>");
    }    
    else
    {
    document.write("script>_gaq.push(['_setCustomVar',5,'Adblock','false',2]); _gaq.push(['_trackEvent','Adblock','false']);<\/sc"+"ript>");
    }	
    }	
    </script>
    <!--End Adblock Check-->
    

    Calling an event after the custom variable is set is also a preferred method noted by Google in their Custom Variable documentation.

    Third Step: Tracking – Piwik Analytics
    For Piwik Analytics the tracking is done as a custom variable. Just make sure the div is the same as denoted in this portion of the code: if ($(".adsense"). If you use our default implementation or your div name is “adsense” you are fine. Like Google Analytics, Piwik has 5 slots per scope. For this reason, I have selected index 5, to allow you for 4 more indexes.

    Place the below code INBETWEEN var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 1); and piwikTracker.trackPageView(); in your Piwik Tracking Code

     {...}
    $(document).ready(checkAds());
    
    function checkAds() {
            if ($(".adsense").height() == "0") {
           document.write("<script>piwikTracker.setCustomVariable(5, 'Adblock', 'True', 'page'); <\/sc" + "ript>");}    
    		else
    		{
    		document.write("<script>piwikTracker.setCustomVariable(5, 'Adblock', 'False', 'page');  <\/sc" + "ript>");}	
    		}	
    {...}
    

    So when done, it will look like this:

    <!-- Piwik --> 
    <script type="text/javascript">
    var pkBaseURL = (("https:" == document.location.protocol) ? "https://localhost/piwik/" : "http://localhost/piwik/");
    document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
    </script><script type="text/javascript">
    try {
    var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 1);
    
    /* Adblock Check */
    $(document).ready(checkAds());
    
    function checkAds() {
            if ($(".adsense").height() == "0") {
           document.write("<script>piwikTracker.setCustomVariable(5, 'Adblock', 'true', 'page'); <\/sc" + "ript>");}    
    		else
    		{
    		document.write("<script>piwikTracker.setCustomVariable(5, 'Adblock', 'false', 'page');  <\/sc" + "ript>");}	
    		}	
    
    /* end Adblock Check */
    
    piwikTracker.trackPageView();
    piwikTracker.enableLinkTracking();
    } catch( err ) {}
    </script><noscript><p><img src="http://localhost/piwik/piwik.php?idsite=1" style="border:0" alt="" /></p></noscript>
    <!-- End Piwik Tracking Code -->
    

    Once you are done you will be able to get some fun data like below:

    Piwik
    adblock tracking Piwik Analytics

    Google
    adblock-unblock-google-analytics

    There you go– now find out how many users actually see you ads and how each type behaves on your site.

    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.

    • Guest

      Thanks for your post but unfortunately it doesn’t work for me for my phpBB3 forum with Adsense. (Google Analytics is implemented and working properly for my forum).

      I edited my “overall_footer.html” and paste this code just before the :

      /* Adblock Check */
      $(document).ready(checkAds());

      /* Adblock Check */
      $(document).ready(checkAds());

      function checkAds() {
      if ($(“.adsense”).height() == “0”) {
      document.write(” _gaq.push([‘_setCustomVar’, 5, ‘Adblock’,’Blocked’,2]);”);}
      else
      {
      document.write(” _gaq.push([‘_setCustomVar’, 5, ‘Adblock’,’UnBlocked’,2]);”);}
      }
      /* End Adblock Check */

      ===

      ===

      ===

      When I purge the cache and refresh the page, it displays this line at the bottom of the page : /* Adblock Check */ $(document).ready(checkAds()); function checkAds() { if ($(“.adsense”).height() == “0”) { document.write(”

      Did I make something wrong?

    • Stephane

      Thanks for your post but unfortunately it doesn’t work for me for my phpBB3 forum with Adsense. (Google Analytics is implemented and working properly for my forum).

      I edited my “overall_footer.html” and paste this code just before the :

      /* Adblock Check */
      $(document).ready(checkAds());

      /* Adblock Check */
      $(document).ready(checkAds());

      function checkAds() {
      if ($(“.adsense”).height() == “0”) {
      document.write(” _gaq.push([‘_setCustomVar’, 5, ‘Adblock’,’Blocked’,2]);”);}
      else
      {
      document.write(” _gaq.push([‘_setCustomVar’, 5, ‘Adblock’,’UnBlocked’,2]);”);}
      }
      /* End Adblock Check */

      ===

      ===

      ===

      When I purge the cache and refresh the page, it displays this line at the bottom of the page : /* Adblock Check */ $(document).ready(checkAds()); function checkAds() { if ($(“.adsense”).height() == “0”) { document.write(”

      Did I make something wrong?

    • Guest

      Thanks for your post but unfortunately it doesn’t work for me for my phpBB3 forum with Adsense. (Google Analytics is implemented and working properly for my forum).

      I edited my “overall_footer.html” and paste this code just before the end of the body tag :

      /* Adblock Check */
      $(document).ready(checkAds());

      /* Adblock Check */
      $(document).ready(checkAds());

      function checkAds() {
      if ($(“.adsense”).height() == “0”) {
      document.write(” _gaq.push([‘_setCustomVar’, 5, ‘Adblock’,’Blocked’,2]);”);}
      else
      {
      document.write(” _gaq.push([‘_setCustomVar’, 5, ‘Adblock’,’UnBlocked’,2]);”);}
      }
      /* End Adblock Check */

      ===

      ===

      ===

      When I purge the cache and refresh the page, it displays this line at the bottom of the page : /* Adblock Check */ $(document).ready(checkAds()); function checkAds() { if ($(“.adsense”).height() == “0”) { document.write(”

      Did I make something wrong?

      • It’s because the second portion needs to be in a JavaScript tag as well

        • Stephane

          Thanks for your reply and support, nice to you.
          Ah ok so this code should be correct and placed into the “overall_footer.html” right?

          /* Adblock Check */
          $(document).ready(checkAds());

          /* Adblock Check */
          $(document).ready(checkAds());

          /* Adblock Check */
          $(document).ready(checkAds());

          function checkAds() {
          if ($(“.adsense”).height() == “0”) {
          document.write(” _gaq.push([‘_setCustomVar’, 5, ‘Adblock’,’Blocked’,2]);”);}
          else
          {
          document.write(” _gaq.push([‘_setCustomVar’, 5, ‘Adblock’,’UnBlocked’,2]);”);}
          }
          /* End Adblock Check */

          • Yes that should work

            • Stephane

              OK I did it and now there are no errors on my page.
              But when I check in Google Analytics, Content, Events, I have got nothing here (Total Events : 0).
              Does it needs some time for Google to update that? If yes how much time?
              THANKS a lot Adrian you’re a crack!!! It’s very important for me to check the % of users with/without AdBlock!

            • I checked your site, thanks for the private email. I am responding here for the value of others. You are using the new universal analytics. This code was written for the classic code. It needs a rewrite to work with it, as the functions are different. I don’t have time to look at it right now, but I will create the code you need. If you can’t wait, check out this document and see how events are treated differently: https://developers.google.com/analytics/devguides/collection/analyticsjs/events

            • Stephane

              Thanks for reply. So I will wait because I am not able to write such code, too complicated for me. A lot of people on Internet are asking the same, so there is no doubt that this code will help other people.
              I am so impatient to know how many percent of the users have Adblock but I will wait your reply with code.
              Thanks a lot for be active and responding to my comments and my private email.

            • I was inspired, here is an article on the new code for Google Analytics Universal: http://www.statstory.com/how-many-of-your-ads-are-being-blocked-updated/

    • Alan

      My custom code (don’t need jQuery) for Piwik 1.12 is:

      —–
      :)

      [….]

      <script…
      var _paq = _paq || [];

      /* ABP */
      function _abpde() {
      if (document.getElementById("AdDiv")==null || document.getElementById("AdDiv").offsetHeight<=0) {
      _paq.push(['setCustomVariable',1,"ABP","Enabled","page"]);
      } else {
      _paq.push(['setCustomVariable',1,"ABP","Disabled","page"]);
      }
      }
      window.onload=_abpde();
      /* /.ABP */
      _paq.push(["trackPageView"]);
      [….]

      It's a bit different. :D

    • buggyfunbunny

      I’ve yet to figure out why the advert/marketing crowd thinks that banning ad blocking visits gets them anywhere???? If I choose not to see ads, there’s a 100% chance I wouldn’t hover, click, or buy from your advert client. Never. Ever. If, as an advert vendor, you’ve managed to flummox product vendors into paying for disinterested eyeballs, well good for you. Still doesn’t help the product vendors at all, just lines your pockets.

      • This is not about blocking Adblock visits. It’s about knowing what % of your market is opting out of banner ads. If the % is higher than you want, maybe banner ads are not the best way to monetize. I agree, though, if someone does not want to see your ads, you should respect it — and decide how you can make your model work. I think what most people forget in the non-advert crowd is that banner ads for the most part allows content to be free. The adverts from this blog cover my costs for hosting for the year. If I were to stop showing banner ads, I would have to find a way to charge for content. Unfortunately this model also does not work. Most people do not want to pay for content because they are used to it being free. It’s a delicate balance to keep everyone happy I guess.