How To Track AdBlock Users Via Google Analytics?

Updated on: January 8, 2024
If you think that you're losing your ad revenue because of ad blockers, then Google Analytics can help you through! Here's a quick guide on how to identify ad-block users through Google Analytics and make informed decisions.

The percentage of web traffic that uses ad blockers has increased massively over a decade. eMarketer says that over 76 million US users installed ad blockers in their browsers, costing the advertising industry about 16 billion dollars in losses in 2020 (Src). More and more people are installing ad blockers on their browsers for various reasons.

Some people don’t like ads, some may use them to get rid of malicious behavior, and some may even want to block the ads for privacy concerns. Whatever the reason is, there is a growing trend of users who have an ad blocker installed on their browser.

Ad-blockers target not only ads but also other trackers on the websites. This happens because ad-blockers prevent the publishers from tracking their users across multiple sites or services, by preventing those trackers from loading on a page. This is a real problem for digital publishers, as it disrupts their ability to measure the effectiveness of their online advertising campaigns, and sometimes cut their profits by half.

For this reason, knowing whether your visitors are using ad blockers is important. The good news is that Google Analytics can give you some insight into this. Most publishers already know the importance of Google Analytics as their first line to identify visitors’ behavior and content performance. However, some do not realize that they can actually use Google Analytics to their advantage in solving the ad-block issue

If you’re in the same boat, this blog post is intended to help you understand tracking ad-block users with Google Analytics via two methods.

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.



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



// 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. = ‘block’; = ‘absolute’; = ‘-1px’; = ‘1px’;


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



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

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

ga(‘send’, ‘pageview’);


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.

Free Consultation Banner

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


window.setTimeout(function() {

    if (test.offsetHeight === 0) {




}, 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’;


window.setTimeout(function() {

    if (test.offsetHeight === 0) {


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



}, 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.

News and Tips for Publishers

Get the inside scoop on publishing and programmatic with our 5-minute newsletter.