Google Analytics: How Many Visitors are Blocking Ads on Your Website

Do you own a blog or a website that depends on Adsense revenue? Are you noticing the drop in your AdSense revenue and believe that ad impressions are dropping despite no drop in website traffic?

In situations like these or times when you may want to check if the visitors on your website are using some Ad blocking plugin/service, this can be done easily with a few lines of code using in association with the Google Analytics.

Google Analytics: How Many Visitors are Blocking Ads on Your Website

Google Analytics: How Many Visitors are Blocking Ads on Your Website

What is Adblock

AdBlocking services such as AdBlock, AdPlus Plus and AdBlock Pro (yes they are all unrelated) are becoming very prevalent among users and are now mainstream applications. In the year-2015 alone ad blocking has cost around $22 billion (see a pdf report on Adblock prepared by pagefair in partnership with adobe). The situation is grave for tech-savvy websites where users are more aware of such techniques.

Find Out AdBlock Visitors with the Help of Google Analytics

For best results copy and paste the following code BEFORE the closing body tag. This will search for any AdBlock software running on visitors browser and once detected pass the information to Google Analytics, which you can view from your Google Analytics dashboard.

 window.onload = function() {
 // Delay to allow the async Google Ads to load
 setTimeout(function() {
 // Get the first AdSense ad unit on the page
 var ad = document.querySelector("ins.adsbygoogle");
 // If the ads are not loaded, track the event
 if (ad && ad.innerHTML.replace(/\s/g, "").length == 0) {
 if (typeof ga !== 'undefined') {
 // Log an event in Universal Analytics
 // but without affecting overall bounce rate
 ga('send', 'event', 'Adblock', 'Yes', {
 'nonInteraction': 1
 } else if (typeof _gaq !== 'undefined') {
 // Log a non-interactive event in old Google Analytics
 _gaq.push(['_trackEvent', 'Adblock', 'Yes', undefined, undefined, true]);
 }, 2000); // Run ad block detection 2 seconds after page load

So this is all that you need to do. Whether you are using Universal Analytics or the older version of Google Analytics (which is using the _gaq object), this should work just fine.

Beware that if a user is blocking Google Analytics JavaScript file as well, then this code will not work as this code uses Google’s javascript object defined in the JavaScript file. Few Adblocking services such as Ghostery, Disconnect, μBlock and Privacy Badger etc. fall in this category and will go undetected.

Final Thoughts

This method is good for all practical purposes but fails when user’s browser decline to load Google Analytics JavaScript file using some adblocking software. If you find that a thick percentage of your website’s users that are blocking ads and your ad revenue is taking a hit, you may want to ask users to whitelist your website or disable the ad blocking tool.

Deepak Pal
Follow Me:

Deepak Pal

Owner at
Deepak is a web enthusiast who loves to write on technology related topics. He runs two educational platforms, Lofoya and GyanPal dedicated to the promotion of FREE EDUCATION.
Deepak Pal
Follow Me:

One comment

  • Deepak but how we will get the information and where we will get?Is there no plugin for this work and second how this code will work for blogpost and weebly blog?

Leave a Reply

Your email address will not be published.