How to track how many visitors are blocking ads

You might like it or not, but more and more people are blocking ads using plugins such as AdBlock. I’ve always wanted to know how many of my visitors actually did this so finally I got around to add some tracking to get some good numbers.

For the main websites I run I’ve now added some code that add Google Analytics events for every visitor (and I’ve added this tracking to a representative set of the pages). If the user is blocking ads it will be tracked as AdBlock and if not the event is No_AdBlock. This way I can easily get a ratio of how many people is in the AdBlock category.

I fully realize this method does not track those that also block Google Analytics tracking, but it will nonetheless give a good indication of the number of visitors blocking ads. You will also have to be using Google Adsense for this code to make sense.

Add this code in the footer of your page, it will wait 3 seconds for the Google AdSense ads to load and then run it’s check.

<script> 
 window.onload = function() { 
   setTimeout(function() { 
     var ad = document.querySelector("ins.adsbygoogle");
     if (ad && ad.innerHTML.replace(/s/g, "").length == 0) {
       if (typeof ga !== 'undefined') {
         ga('send', 'event', 'Adblock', 'Yes', {'nonInteraction': 1}); 
         } 
      else if (typeof _gaq !== 'undefined') {
        _gaq.push(['_trackEvent', 'Adblock', 'Yes', undefined, undefined, true]);
        } 
      }
    else {
      if (typeof ga !== 'undefined') {
        ga('send', 'event', 'No_Adblock', 'Yes', {'nonInteraction': 1}); 
        } 
      else if (typeof _gaq !== 'undefined') {
        _gaq.push(['_trackEvent', 'No_Adblock', 'Yes', undefined, undefined, true]);
        } 
      }
    }, 3000); 
   };  
</script>

Share This Post