> For the complete documentation index, see [llms.txt](https://docs.exoclick.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.exoclick.com/publishers/adblock/track-adblock-users-ga.md).

# 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**](https://support.google.com/sites/answer/97459?hl=en), 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**](/publishers/adblock/neverblock.md).

Note that we will be referring to the **Google Analytics 4** version since [Universal Analytics will be discontinued on July 2023](https://support.google.com/analytics/answer/11583528?hl=en\&ref_topic=10094551).

{% stepper %}
{% step %}

## 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:

```html
isAdBlockActive=false;
```

Once you have created this file, upload it your website's server.
{% endstep %}

{% step %}

## 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](https://support.google.com/analytics/answer/9234069?hl=en\&ref_topic=13367566). What we are going to do is to create a [**custom event**](https://support.google.com/analytics/answer/12229021) 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:

```html
<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**](https://support.google.com/analytics/answer/9304153#add-tag\&zippy=%2Cadd-the-google-tag-directly-to-your-web-pages) in the `head` tag, otherwise the code won't work.
{% endstep %}

{% step %}

## 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

{% stepper %}
{% step %}
Click on **Admin** > **Custom definitions**, then click on **Create custom dimensions**.

![Custom Dimension Set Up 1](/files/26b6d726405504d24b7781373d9dbb3274bf5746)
{% endstep %}

{% step %}
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](/files/de541676ec31519f5009b68dfd021e456980f8f1)
{% endstep %}

{% step %}
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](/files/e031592c937e977b1f495424378a572d1e17705a)

![Custom Dimension Comparison 2](/files/c417a15499d28af4283a37b91ff8bbca45629d3b)
{% endstep %}
{% endstepper %}

### Custom events

{% stepper %}
{% step %}
Click on **Admin** > **Events**, then click on **Create custom event**.

![Custom Event Set Up 1](/files/2ee31fb21f6dcafd62fa3621ade02f41b7e5b7bd)
{% endstep %}

{% step %}
Click on **Create**. In custom event name, write **adblock\_user**. Then, as matching conditions, write the following:

![Custom Event Set Up 1](/files/57e2e353cb397841620e30abeeb4f09a8d88c3a9)
{% endstep %}

{% step %}
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](/files/e6f133bb4a83433e09541a73a6a8c0b3ef3f511c)
{% endstep %}
{% endstepper %}
{% endstep %}
{% endstepper %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.exoclick.com/publishers/adblock/track-adblock-users-ga.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
