Skip to main content

How to track Adblock users through Google Analytics 4

While ExoClick tracks the impressions, clicks and revenue generated by your ad zones, you have other tools at your disposal to measure the overall performance and activity from your website. One of these tools is Google Analytics, which gives you detailed insights on what's happening on your site.

You can set up a custom tracking event in Google Analytics that gives you some indication to how many users are visiting your website with Adblock enabled. This will help you get an idea of how much traffic you could be monetizing through ExoClick's Adblock solution.

Note that we will be referring to the Google Analytics 4 version since Universal Analytics will be discontinued on July 2023.

Step 1: Create the ad-units.js script and upload it to your server

In order to detect if the user is accessing our site with Adblock enabled, we will create a Javascript file called ad-units.js. This file declares that all the users who visit your website are not using Adblock. Since the term "ad-units" is blocked by Adblock, we will label the user as accesing with an adblocker extension whenever this file is not loaded.

The .js file just needs to contain the following:

isAdBlockActive=false;

Once you have created this file, upload it your website's server.

Step 2: Add the tracking code on each of your pages

The default tag from GA tracks basic events such as page views, sessions and users, among others. What we are going to do is to create a custom event using the GA API.

For this custom code, we are going to create the adblock_user recommended event. The code that you need to add on each page you want to track is the following:

<script type="text/javascript">var isAdBlockActive=true;</script>
<script src="ad-units.js" type="text/javascript"></script>
<script>
window.onload = function(e) {
if(isAdBlockActive){
gtag("event", "adblock_user", {
"user":"adblock"
})
console.log('Adblock user')
} else {
gtag("event", "adblock_user", {
"user":"standard"
})
console.log('Standard user')
}
};
</script>

Place this code after the body tag from each website you want to track. Let's go in detail about each part from this code:

  • First, we are declaring the variable isAdblockActive as true, meaning that every user who visits your website has adblock enabled. Immediately afterwards, we will call the ad-units.js script we created ealier, which will change this variable to false. This means that users will be treated as "standard" unless they have an adblocker that blocks the ad-units.js file, in which case they will be treated as "adblock".
  • Then, we are creating a custom event called adblock_user event based on whether the variable isAdblockActive is true or not. We added the user event parameter so that we can identify it quickly in GA. We will explain this in detail in the next section.

Make sure you have placed the basic GA tracking code in the head tag, otherwise the code won't work.

Step 3: Create the dimension and the custom event in GA

This step will help you have a better visualization of Adblock users in your GA dashboard. The dimension can be used as filter in your various reports, whereas the custom event will give you a specific page where you can check the amount of adblock users on your site.

Custom dimension

  1. Click on Admin > Custom definitions, then click on Create custom dimensions.

Custom Dimension Set Up 1

  1. Add Adblock as "Dimension name" and select Event as "Scope", then add description of your choice and input user as "event parameter".

Custom Dimension Set Up 2

  1. Hit Save.

The dimension won't work right away: it will start appearing in your reports once it has identified enough events/users after a few days. When it becomes available, you will be able to use it as to add a comparison with the report your are browsing:

Custom Dimension Comparison 1

Custom Dimension Comparison 2

Custom events

  1. Click on Admin > Events, then click on Create custom event.

Custom Event Set Up 1

  1. Click on Create. In custom event name, write adblock_user. Then, as matching conditions, write the following:

Custom Event Set Up 1

  1. Lastly, enable "copy parameters from the source event" and hit "Save".

The custom event won't work right away: it will start appearing in your reports once it has been fired several times after a few days. You can select this event for a more granular view of your adblock users.

Custom Event Results