How to Track Ad Blockers in Google Analytics

Ad Blockers are becoming ever increasingly popular among web visitors. This guide will show you how to track ad blockers in Google Analytics

By Tim Trott | (Java|Type)Script / jQuery | June 24, 2017

Ad Blockers are becoming ever increasingly popular among web visitors. While they are mainly installed to reduce obnoxious or obtrusive adverts, they are indiscriminate and often block subtle ads which hurt web publishers. This guide will show you how to log ad blockers blocking Adsense traffic in Google Analytics.

Ad blocking is a huge problem for both ad publishers and content writers. Content writers usually offset the cost of server hosting and time to create content with the revenue from advertisements. Ad blockers seriously impact this revenue to the point where some writers cannot afford to keep services running or content updated. Personally, my income from Adsense is a third of what it was 5 years ago. While it cannot be all attributed to ad blockers, they certainly do not help.

There is a simple trick which you can use to track ad blockers and detect if Adsense codes have been blocked. This method relies on a few JavaScript variables which Adsense uses. If Adsense is blocked, then these variables are not set. We can test from this and send an event to Analytics for logging. Once you have some data on the percentages of ad-blocked visitors you can take steps to mitigate the problem.

Of course, if the Ad Blocker is also blocking Analytics this method won't work, but you could adapt it to log elsewhere. You can also adapt the code to work on other ad publishing platforms.

For these examples, you will need Google Analytics and a Google Adsense account.

Ad Blocker Detection Code

The code is quite simple and can be copied and pasted into your website without changes. This is usually in the footer of the page, after your Analytics tracking script.

javascript
if(typeof adsbygoogle !== "undefined") 
{
if(typeof ga !== "undefined") 
{
  if(typeof adsbygoogle.loaded === "undefined") 
  {
ga('send', 'event', { eventCategory: 'Income', eventAction: 'Adsense', eventLabel: 'Adsense Blocked', eventValue: 1});
  }
  else 
  {
ga('send', 'event', { eventCategory: 'Income', eventAction: 'Adsense', eventLabel: 'Adsense Not Blocked', eventValue: 1});
  }
}
}

With this script logging an event to Analytics with the title "Ads blocked" or "Ads not blocked" you can then see in Google Analytics reports the proportion of page views which are ad blocked and how many are not blocked.

This script will wait until the page has finished loading then check for the adsbygoogle variable. It then basically checks the existence of the adsense and analytics codes and fires off an event depending on if the adsbygoogle is loaded or not.

Track Ad Blockers in Google Analytics

Now that the track ad blockers script has been added to the page, we need to wait a few days for the tracking data to start coming through. Once it does, you can view the events from the Behaviour > Events screen in Analytics reporting.

Track Visitors who block Adsense in Analytics
Track Visitors who block Adsense in Analytics
Was this article helpful to you?
 

Related ArticlesThese articles may also be of interest to you

CommentsShare your thoughts in the comments below

If you enjoyed reading this article, or it helped you in some way, all I ask in return is you leave a comment below or share this page with your friends. Thank you.

There are no comments yet. Why not get the discussion started?

We respect your privacy, and will not make your email public. Learn how your comment data is processed.