// Add to head
Ad Block
Data Management

How To Track AdBlock Users Via Google Analytics?

1
Rohan Sharma
September 11, 2024
September 11, 2024

Ads are the core of many online businesses, especially of premium publishers like you. But here's the harsh reality, in 2024, over 1.3 billion people are wielding the dreaded ad blocker, translating to a whopping 42% of internet users worldwide giving our carefully crafted ads the silent treatment (Source: Marketing Scoop).  That's billions of dollars vanishing from the advertising industry annually!

But why the ad-apocalypse?  

Users have their reasons. They want a clean, clutter-free experience, protection from malicious content, and a tighter hold on their privacy.  And guess what? Ad blockers not only block those pesky ads but also prevent those sneaky trackers from loading. This throws a wrench in your ability to measure campaign effectiveness – not exactly a recipe for profits,  is it?

Let’s Fight Back With Google Analytics!

Google Analytics, is a  tool you're likely already relying on to track visitor behavior and content performance can be a powerful tool in the fight against ad blockers too.  

Chances are you're already using it. But today, we will delve into two battle-tested methods for tracking ad-block users using Google Analytics, empowering you to mitigate the impact these blockers have on your digital advertising efforts. Stay tuned – it's about to get strategic!

Method 1:

Step #1: Add JavaScript code to the website’s header

Add the below JavaScript code to the website’s header to determine if a visitor has installed an ad blocker on their browser.

<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: Set up a custom dimension in Google Analytics

As detecting users with ad blockers is a customized need, you need to create a custom dimension in Google Analytics. Setting up the custom dimension will enable you to reflect the data captured by the aforementioned code snippet on the Analytics dashboard. Follow the below steps to perform this task:

  1. Click on the Admin icon on the left-hand sidebar and click on Custom Definitions > Custom Dimensions.
  2. Click on the + NEW CUSTOM DIMENSION and give it a name, e.g. Ad Block Users. Save the dimension.

Now that you’ve created the custom dimension, it’s time to analyse the users with ad blockers. For this, you can use advanced segments features. In Google Analytics, advanced segments are more selective than dashboard filters, which simply subtract a specified traffic source from your website’s total traffic amount. So, let’s create a new segment to narrow down analytics reporting based on the traffic that has installed ad-blockers.

  1. Go to Home > Audience > Overview.
  2. Click on +Add Segment > +New Segment On left-hand sidebar, click on Conditions under Advanced section.
Add Segments for Ad Blocks in Google Analytics

      3. In the Ad Content filter, select the custom dimension i.e. Blocked Ads from the drop-down menu.

Blocked Ads in Google Analytics

      4. Now, select exactly matches in the next drop-down menu. At last, enter 1 and save the settings to count the number of users with ad blockers.

Further, to compare the behavior of all users with ad block users, you can create a custom report in Google Analytics. Here’s how to do this:

  1. Go to Home > Acquisitions > All traffic > Source/Medium.
  2. Now, click on +Add Segment and select Blocked Ads. At last, click on Apply to generate the report.

Method 2

Step #1: Add a DIV code to the web pages to detect ad blockers

To detect ad blockers on the user’s browser, add the following JavaScript code to the CSS of your website. 

The condition test.offsetHeight tells about if the user has installed an ad blocker or not. On the other hand, the CSS class adsbox triggers an alarm in the ad blockers to hide it for 400 milliseconds on the page so that you can urge users to disable the ad blocker. This is one of the preferred techniques for publishers trying to recover ad block revenue.

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);

Step #2: Record the ad blockers in Google Analytics

So you asked the users to disable the ad blockers, but not all users whitelisted your website. Now what? Data visualization. Copy the below code and add it to the above JS code to collect data in Google Analytics and make better decisions regarding users navigating with ad blockers.

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 in Google Analytics, you need to create Events. Here’s how to do it:

  1. Go to Admin > Goals > +New Goal.
  2. Click on Custom and give a name to the goal e.g. Blocked Ads. Select the type Event.
Event Setup in GA

      3. In the Goal details, fill the details for Category, Action, and Label. Ensure that you’ve passed the same values as you entered in the function ga ().

Once done, to verify if the code and set-up are working correctly, go to Home > Realtime > Events. Under the Active users’ section, you should see the number of users who’ve installed ad blockers.

Goal Details

What’s Next?

Measuring mobile ad block traffic and desktop ad block traffic allows you to measure the effect the use of ad blockers is having on your ad revenue. This information is much more reliable than simply asking users if they are using an ad blocker. Learning more about these users, you can improve how your content and ads are delivered, and gently encourage them to disable the ad blockers. If asking for whitelisting still doesn’t work, here are a few methods that will help you recover ad-block revenue.

Looking to in-house your publishing needs?
We are right here to help
Related Reads
Read More →
Data Management
Manage Ad Stack

Insertion Order (IO) – Everything You Need to Know

July 23, 2024

Data Management
Manage Ad Stack

Privacy Laws: 2024 Updates for Publishers

March 11, 2024