How to Track Ad Block Users Via Google Analytics

Reading time: 4 minutes

The number of users with ad blockers has steadily decreased over the past decade. Currently, there are more than 76 million users in the US alone that have installed ad blockers to their browsers — costing the ad tech industry upwards of $16 billion in losses. 

There are plenty of reasons why a user would install an ad blocker. Let’s be honest, A LOT of users hate dealing with ads while they browse through different websites. Most ads tend to be intrusive, not to mention, they often slow down the page, making it very frustrating for anyone to get through the content. Of course, there are also privacy concerns and malware to avoid. 

The point is, installing ad blockers has become a growing trend. 

Ad blockers don’t just target ads either. They also target other website trackers to prevent publishers from tracking the users across multiple sites and even services by preventing the trackers from loading. It’s a real issue for digital publishers as it gets in the way of how they measure the efficiency of their online advertising campaigns while undercutting their profits. 

Fortunately, Google Analytics can give publishers insight into whether their visitors are using ad blockers which helps solve the issue almost entirely. (It’ll help you measure your ad campaigns more effectively but it won’t change the fact that people are still using ad blockers). 

There are actually two ways you can go about tracking ad-block users with Google Analytics, and we’re going to explain both of them.

Read on to learn more.

The First Way

The first method of tracking ad blockers involves using JavaScript coding and using a custom dimension within Google Analytics. 

Here are the steps:

Step #1: Use JavaScript code in the website’s header

The JavaScript code listed out below should be put directly into your website’s header to assess whether a visitor has an ad blocker installed:

<script>

(function(i,s,o,g,r,a,m){i[‘GoogleAnalyticsObject’]=r;i[r]=i[r]||function(){

(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),

m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)

})(window,document,’script’,’https://www.google-analytics.com/analytics.js’,’ga‘);

// Creates an adblock detection plugin.

ga(‘provide’, ‘adblockTracker’, function(tracker, opts) {

var ad = document.createElement(‘ins’);

ad.className = ‘AdSense’; //Name of ad partner you’re working with.

ad.style.display = ‘block’;

ad.style.position = ‘absolute’;

ad.style.top = ‘-1px’;

ad.style.height = ‘1px’;

document.body.appendChild(ad);

tracker.set(‘dimension’ + opts.dimensionIndex, !ad.clientHeight);

document.body.removeChild(ad);

});

ga(‘create’, ‘UA-XXXXX-Y’, ‘auto’); //Replace UA-XXXXX-Y with your tracking ID.

ga(‘require’, ‘adblockTracker’, {dimensionIndex: 1});

ga(‘send’, ‘pageview’);

</script>

Step #2: Create a custom dimension in Google Analytics

By setting up the custom dimension, you’ll be able to utilize the data captured by the code snipped from above right on the Analytics dashboard. 

Here’s how to do it:

  • Enter into the Admin setting then click Custom Definitions > Custom Dimensions
  • Click on + NEW CUSTOM DIMENSION and name it manually

Once you’ve created the custom dimension, you’ll want to analyze your ad-blocking visitors, which means you’ll have to use the advanced segments features

A quick note about advanced segments — they’re more selective compared to typical dashboard filters, which traditionally subtract specified traffic sources from your total traffic amount. Therefore, you’ll need to create a new segment to narrow down the analytics reporting based on the ad-blocking traffic. 

Here’s how to do this:

  • Click on Home > Audience > Overview
  • Now, click on +Add Segment > +New Segment and then click on Advanced > Conditions on the left-hand sidebar
  • Select Blocked Ads from the drop-down menu under Ad Content
  • Now, select exact matches from the subsequent drop-down menu and enter the number 1, and save your new settings

If you want to take things a step further to compare ad-blocking user behavior, you can also create custom reports in Google Analytics:

  • Go to Home > Acquisitions > All traffic > Source/Medium
  • From there, click +Add Segment and select Blocked Ads
  • Lastly, click on Apply to generate your report

The Second Way

The second method involves adding a DIV code to your web pages. 

Here are the steps:

Step #1: Add a DIV code to your web pages

In the CSS of your website, add the following JavaSCript code

var test = document.createElement(‘div’);

test.innerHTML = ‘&nbsp;’;

test.className = ‘adsbox’;

document.body.appendChild(test);

window.setTimeout(function() {

    if (test.offsetHeight === 0) {

        document.body.classList.add(‘adblock’);

            }

  test.remove();

}, 400);

By implementing the condition test.offsetHeight, you’ll learn if the user has installed an ad blocker. Additionally, the CSS class adsbox will signal to the ad blocker to hide for a certain amount of time so you can encourage the users to disable their ad blockers. This is actually the preferred technique among publishers. 

Step #2: Record the ad blockers via Google Analytics

Not all users will respond to you asking them to disable their ad blockers. So, your next step is taking over data visualization.

Add the following code to the JS code listed in step one to collect data on ad blocking users’ navigation:

ga(‘send’, ‘event’, ‘Ads Setting’, ‘Adblock’, ‘Enabled’);

The above code is for Universal Analytics users. If you’ve old version of GA (classic GA), copy the following code:

_gaq.push([‘_trackEvent’, ‘Ad Setting’, ‘AdBlock’, ‘Enabled’);

Now, your complete code should look like this:

var test = document.createElement(‘div’);

test.innerHTML = ‘&nbsp;’;

test.className = ‘adsbox’;

document.body.appendChild(test);

window.setTimeout(function() {

    if (test.offsetHeight === 0) {

        document.body.classList.add(‘adblock’);

        ga(‘send’, ‘event’, ‘Ad Setting’, ‘Adblock’, ‘Enabled’);

    }

  test.remove();

}, 400);

Step #3: Set up custom events in Google Analytics

To reflect the data you’ll be collecting in Google Analytics, you’ll need to create Events

Here’s how it’s done:

  • Click on Admin > Goals > +New Goal
  • Click on Custom and name the goal
  • Select type: Event
  • In Goal Details, fill in the information for Category, Action,  and Label. Be sure to use the same values that you entered in the function ga ()
  • Now go to Home > Realtime > Events. Under the active Users’ section, you should see the total number of users that are using ad blockers

When you measure your ad-block traffic, you’re measuring the effects the use of ad blockers is having directly on your ad revenue. It’ll also help you figure out how you can improve your content and the ads delivered to recover that ad blocked revenue.

Recent Articles

Stay connected

Don't miss out on the latest news, events and special announcements.

By submitting this form, you agree that you've read and accept our Privacy Policy as well as to receive communications from HeaderBidding.com. You may unsubscribe at any time.

Related Articles

Leave A Reply

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Stay connected

Don't miss out on the latest news, events and special announcements.

By submitting this form, you agree that you've read and accept our Privacy Policy as well as to receive communications from HeaderBidding.com. You may unsubscribe at any time.