> 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/tutorials/zh/jiao-cheng/fa-bu-shang-jiao-cheng/serve-sfw-ads.md).

# 如何使用 ExoClick 投放 SFW 广告

随着各国开始推行年龄验证法律，发布商需要找到一种既能遵守这些法律、又能尽量减少这些法律对收入影响的方法。这就是 ExoClick 引入了一些可添加到广告位中的参数的原因，它们不仅能帮助发布商屏蔽 NSFW 产品，还能跟踪这些用户是否真的成功完成了年龄验证。在本教程中，我们将向你展示如何使用这些参数。

## data-ex\_av

该 `data-ex_av 参数` 用于确定用户是否已完成年龄验证，并允许 3 个值：

* `"0"`: 未进行年龄验证（未定义）
* `"1"`: 年龄验证 - 已验证
* `"2"`: 年龄验证 - 未验证（SFW）

代码示例：

```html
<script async type="application/javascript" src="https://a.magsrv.com/ad-provider.js"></script> 
 <ins class="eas6a97888e2" data-zoneid="5209020"  data-ex_av="2"></ins> 
 <script>(AdProvider = window.AdProvider || []).push({"serve": {}});</script>
```

## data-block-ad-types

该 `data-block-ad-types` 参数允许你动态屏蔽特定的广告类型标签。为了屏蔽 NSFW 广告，我们只会在此参数中使用值 `"101"` 。

代码示例：

```html
<script async type="application/javascript" src="https://a.magsrv.com/ad-provider.js"></script> 
 <ins class="eas6a97888e2" data-zoneid="5209020"  data-block-ad-types="101"></ins> 
 <script>(AdProvider = window.AdProvider || []).push({"serve": {}});</script>
```

## 使用这些参数

考虑到我们前面所解释的内容，如果你想投放一则 SFW 广告，并且希望将该用户识别为尚未验证年龄的人，你可以像这样集成这些参数：

```html
<script async type="application/javascript" src="https://a.magsrv.com/ad-provider.js"></script> 
 <ins class="eas6a97888e2" data-zoneid="5209020" data-ex_av="2"  data-block-ad-types="101"></ins> 
 <script>(AdProvider = window.AdProvider || []).push({"serve": {}});</script>
```

{% hint style="info" %}
**注意**: 重要的是你要同时使用这两个参数。
{% endhint %}

如果你想向已验证用户投放 NSFW 广告，可以这样设置：

```html
<script async type="application/javascript" src="https://a.magsrv.com/ad-provider.js"></script> 
 <ins class="eas6a97888e2" data-zoneid="5209020" data-ex_av="1"></ins> 
 <script>(AdProvider = window.AdProvider || []).push({"serve": {}});</script>
```

下一部分包含一些示例，说明如何将这些参数动态添加到你的广告位中。根据你所使用的年龄验证方式，用户可能通过 cookie、URL 参数或其他方式完成验证。最终， **由你负责检测用户的验证状态，并相应地实施这些参数。**

### 示例 1：根据 cookie 值更改参数

假设你会为成功完成年龄验证的用户分配一个名为“verified\_user”、值为“yes”的第一方 cookie。在这种情况下，你可以像这样动态添加 ex\_av 和 data-block-ad-types 参数：

```html
//横幅广告位
<script async type="application/javascript" src="https://a.magsrv.com/ad-provider.js"></script>
<div id=”adspot1”>
<ins class="eas6a97888e2" data-zoneid="5409832" data-block-ad-types="101" data-ex_av="2"></ins>
<div id=”adspot2”>
<ins class="eas6a97888e2" data-zoneid="5632512" data-block-ad-types="101" data-ex_av="2"></ins>
<div id=”adspot3”>
<ins class="eas6a97888e2" data-zoneid="57382911" data-block-ad-types="101" data-ex_av="2"></ins>

//fpi 广告位
<script async type="application/javascript" src="https://a.pemsrv.com/ad-provider.js"></script> 
<ins class="eas6a97888e35" data-zoneid="5045990" data-block-ad-types="101"  data-ex_av="2"></ins>

//基于 cookie 的动态函数
<script>
function getCookie(name) {
const value = `; ${document.cookie}`;
const parts = value.split(`; ${name}=`);
if (parts.length === 2) return parts.pop().split(';').shift();
}

const verifiedUser = getCookie("verified_user");
if (verifiedUser === "verifiedUser") {
const adInsElements = document.querySelectorAll("ins");
adInsElements.forEach(ins => {
ins.setAttribute("data-ex_av", "1");
ins.setAttribute("data-block-ad-types", "0");
});
}
(AdProvider = window.AdProvider || []).push({"serve": {}});
</script>
```

这段脚本将允许你向那些带有“user\_verified” cookie 的用户投放 NSFW 广告。请注意，在用户完成年龄验证后，你需要刷新页面，以便脚本能够正确检测到 cookie。

### 示例 2：根据 URL 参数更改参数

在这个示例中，我们假设当用户成功完成年龄验证时，URL 会获得一个名为“user\_verified=yes”的参数。

```html
<script async type="application/javascript" src="https://a.magsrv.com/ad-provider.js"></script>
<div id="ad-container">
      <ins class="eas6a97888e20" data-zoneid="5662140" data-block-ad-types="101" data_ex_av="2"></ins>
</div>
    <script>
      (AdProvider = window.AdProvider || []).push({ serve: {} });
    </script>
    <script>
      const userVerified = new URLSearchParams(window.location.search).get(
        "user_verified"
      );
      if (userVerified === "yes") {
        let container = document.getElementById("ad-container");

        container.innerHTML = "";

        let newIns = document.createElement("ins");
        newIns.className = "eas6a97888e20";
        newIns.setAttribute("data-zoneid", "5662140");
        newIns.setAttribute("data-block-ad-types", "");
        newIns.setAttribute("data-ex_av","1");
        container.appendChild(newIns);

        (AdProvider = window.AdProvider || []).push({ serve: {} });
      }
    </script>
```

{% hint style="info" %}
**记住**: 这些代码示例仅供参考。你应与年龄验证工具讨论用户是如何被验证的，并相应地调整你的脚本。
{% endhint %}


---

# 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/tutorials/zh/jiao-cheng/fa-bu-shang-jiao-cheng/serve-sfw-ads.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.
