> 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/zh/guang-gao-lan-jie/track-adblock-users-ga.md).

# 如何通过 Google Analytics 4 跟踪广告拦截用户

虽然 ExoClick 会跟踪广告位产生的展示次数、点击和收入，但您还可以使用其他工具来衡量网站的整体表现和活动情况。其中一个工具是 [**Google Analytics**](https://support.google.com/sites/answer/97459?hl=en)，它能为您提供关于网站上发生情况的详细洞察。

您可以在 **自定义跟踪事件** 中进行设置，它能让您大致了解有多少用户开启了 Adblock 访问您的网站。这将帮助您估算有多少流量可以通过 [**ExoClick 的 Adblock 解决方案**](/publishers/zh/guang-gao-lan-jie/neverblock.md).

请注意，我们将引用 **Google Analytics 4** 版本，因为 [Universal Analytics 将于 2023 年 7 月停用](https://support.google.com/analytics/answer/11583528?hl=en\&ref_topic=10094551).

{% stepper %}
{% step %}

## 创建 ad-units.js 脚本并将其上传到您的服务器

为了检测用户是否在开启 Adblock 的情况下访问我们的网站，我们将创建一个名为 `ad-units.js`的 Javascript 文件。该文件声明所有访问您网站的用户都没有使用 Adblock。由于“ad-units”这个词会被 Adblock 屏蔽， **当此文件未加载时，我们会将该用户标记为使用了广告拦截器扩展**.

这个 .js 文件只需要包含以下内容：

```html
isAdBlockActive=false;
```

创建此文件后，将其上传到您网站的服务器。
{% endstep %}

{% step %}

## 在您的每个页面上添加跟踪代码

GA 的默认标签会跟踪一些基本事件，例如 [页面浏览量、会话和用户等](https://support.google.com/analytics/answer/9234069?hl=en\&ref_topic=13367566)。我们要做的是创建一个 [**自定义事件**](https://support.google.com/analytics/answer/12229021) ，并使用 GA API。

对于这段自定义代码，我们将创建 `adblock_user` 推荐事件。您需要添加到每个要跟踪的页面上的代码如下：

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

请将此代码放在 `body` 标签之后，也就是放在您想要跟踪的每个网站的相应位置。让我们详细看看这段代码的每一部分：

* 首先，我们声明变量 `isAdblockActive` 为 `true`，这意味着每个访问您网站的用户都开启了 adblock。紧接着，我们会调用之前创建的 `ad-units.js` 脚本，它会将这个变量改为 `false`。这意味着用户会被视为“standard”，除非他们使用了会阻止 `ad-units.js` 文件的广告拦截器，在这种情况下，他们会被视为“adblock”。
* 然后，我们会创建一个名为 `adblock_user` 的自定义事件，其取决于变量 `isAdBlockActive` 是否为 true。我们添加了 `user` 事件参数，以便我们能在 GA 中快速识别它。我们将在下一节详细说明这一点。

请确保您已经将 [**基础 GA 跟踪代码**](https://support.google.com/analytics/answer/9304153#add-tag\&zippy=%2Cadd-the-google-tag-directly-to-your-web-pages) 放在 `head` 标签中，否则代码将无法工作。
{% endstep %}

{% step %}

## 在 GA 中创建维度和自定义事件

这一步将帮助您 **在 GA 仪表板中更好地查看 Adblock 用户**。 **维度** 可用作您各类报告中的过滤器，而 **自定义事件** 则会为您提供一个特定页面，您可以在那里查看网站上的 adblock 用户数量。

### 自定义维度

{% stepper %}
{% step %}
点击 **管理** > **自定义定义**，然后点击 **创建自定义维度**.

![自定义维度设置 1](/files/0a661f6bc29eb8d457ff6b895ab1c5e1f61a0eed)
{% endstep %}

{% step %}
添加 **Adblock** 作为“维度名称”，并选择 **事件** 作为“范围”，然后添加您想要的描述，并输入 **user** 作为“事件参数”。

![自定义维度设置 2](/files/43e312459d08cf9f3fd66eab469037feeaf91948)
{% endstep %}

{% step %}
命中 **保存**.

该维度不会立即生效：在几天后，当它识别出足够多的事件/用户时，它才会开始出现在您的报告中。等它可用后，您就可以将其用作 **添加比较** 并应用到您正在浏览的报告中：

![自定义维度比较 1](/files/9de6aa0bf49f19712bfc5f1cce13bd427d8693cc)

![自定义维度比较 2](/files/141f19510cac52dfa3be7ca8e741a46ae4418ce6)
{% endstep %}
{% endstepper %}

### 自定义事件

{% stepper %}
{% step %}
点击 **管理** > **事件**，然后点击 **创建自定义事件**.

![自定义事件设置 1](/files/40603365cba420b93607b173aedd5493a76edf95)
{% endstep %}

{% step %}
点击 **创建**。在自定义事件名称中，填写 **adblock\_user**。然后，在匹配条件中填写以下内容：

![自定义事件设置 1](/files/ad13d091f6c81e96ccc2a61690e1f6d7a7756158)
{% endstep %}

{% step %}
最后，启用“从来源事件复制参数”，然后点击“保存”。

该自定义事件不会立即生效：在几天后，当它被触发多次后，它才会开始出现在您的报告中。您可以选择此事件，以更细粒度地查看您的 adblock 用户。

![自定义事件结果](/files/6b006a42eba3c2d7e8b1caba148c50b36bd84cb9)
{% 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/zh/guang-gao-lan-jie/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.
