> 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/exoclick-agego.md).

# 如何将 ExoClick 与 AgeGO 集成

本指南旨在说明：

* 如何向 AgeGO 提交网站。
* 如何向 ExoClick 传递年龄验证参数，并在广告位上屏蔽广告。
* 如何将 AgeGO 和 ExoClick 广告位整合在一起，以便在用户验证年龄之前向其展示 SFW 广告。

## 如何向 AgeGO 提交网站

要向 AgeGO 提交网站，请登录 [AgeGO 控制面板](https://dashboard.agego.com/login)。然后，进入“我的网站”并点击“新建网站”：

![ExoClick AgeGO 1](/files/f1fadc547cb79bdfced7f7565fc97d271d060243)

在这些设置中，你至少需要添加 **名称** 和 **顶级域名**。完成这些设置后，点击“创建”。网站将添加到你的账户。

默认情况下，所有网站在创建时都会处于“就绪”状态。不过，这并不意味着你的网站现在就能使用 AgeGO。要在你的网站上启用 AgeGO，你需要 [**通过他们的联系表单联系 AgeGO**](https://www.agego.com/contact-us-business) **并提供与你的网站对应的站点 ID。**

你可以在网站名称旁边找到站点 ID：

![ExoClick AgeGO 2](/files/ee51ff1e0c172cc18fdefcd3f7ba0cdc1448ebf7)

一旦你的网站获得批准，其状态将变为“运行中”，然后你就可以按照集成说明在你的网站上集成 AgeGO。该解决方案目前提供两种方法， **Modal（简单或高级）** 和 **S2S**，且每种方法的设置说明都可在 AgeGO 控制面板中找到。为了本指南的目的，我们将介绍 **Modal** 方法。

## 如何传递年龄验证状态并展示 SFW 广告

当使用年龄验证系统（AgeGO 或其他提供商）时，你可能希望继续向所有用户展示广告（无论是未验证年龄的用户还是已验证年龄的用户）。

要识别某个用户是否已通过年龄验证，请在你的广告位上使用 `data-ex_av` 参数。该参数允许 3 个值：

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

然后，为了向某些用户（在此上下文中，即那些未验证年龄的用户）屏蔽广告，请使用 `data-block-ad-types` 参数。该参数允许多个值，但在本指南中我们只使用值 `101`.

因此，如果你想投放一个 SFW 广告，并想将该用户识别为尚未验证年龄的人，你可以像这样集成这些参数：

* **异步广告格式（横幅、FPI、多格式等）：**

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

* **流内广告**: `https://s.magsrv.com/v1/vast.php?idzone=XXXXXX&ex_av=2&block_ad_types=101`
* **弹出底层广告（链接）**: `https://s.pemsrv.com/v1/link.php?cat=&idzone=XXXXX&type=8&ex_av=2&block_ad_types=101`
* **直接链接**: `https://s.zlinkt.com/v1/d.php?z=XXXXXXX&ex_av=2&blocked_ad_types=101`

**注意**：你必须同时使用 `data-ex_av` 和 `data-block-ad-types` 在投放 SFW 广告时，否则用户将无法被正确识别，广告也不会被屏蔽。

如果你想向已验证年龄的用户展示所有类型的广告，则可以像这样投放：

* **异步广告格式（横幅、FPI、多格式等）：**

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

* **流内广告**: `https://s.magsrv.com/v1/vast.php?idzone=XXXXXXXX&ex_av=1`
* **弹出底层广告（链接）**: `https://s.pemsrv.com/v1/link.php?cat=&idzone=XXXXXXX&type=8&ex_av=1`
* **直接链接**: `https://s.zlinkt.com/v1/d.php?z=XXXXXXX&ex_av=`

## 如何创建 SFW 体验

以下教程将说明如何创建“SFW 体验”，也就是如何确保在用户尚未验证年龄时只投放 SFW 广告。请注意，此方法只是一个建议，如果你需要遵循不同的用户流程，也可以修改设置。

在此设置中，我们需要创建一个单独的脚本文件。在这个示例中，我们将其命名为 `main.js`:

```javascript
function getCookie(name) {
  const value = `${document.cookie};`;
  const parts = value.split(`${name}=`);
  if (parts.length !== 2) return false;
  const token = parts.pop().split(";").shift();
  const format = token.split(".");
  if (format.length !== 3) return false;
  try {
    format.slice(0, 2).forEach(part => {
      const padded = part + "=".repeat((4 - part.length % 4) % 4);
      atob(padded.replace(/-/g, "+").replace(/_/g, "/"));
    });
    return true; 
  } catch (e) {
    return false; 
  }
}

function verifier(event, container) {
    window.AGEGO = window.AGEGO || function () {
	(AGEGO.e = AGEGO.e || []).push(arguments)
	};
     AGEGO('configure', {
	siteId: XXXXXXX, // 你的网站在 AgeGO 中的站点 ID
	autoBlur: true,
	verifyMode: 'inline', 
	requireAgeVerification: true, 
	allowDirectContinue: false, 
	overlay: {
		logo: 'wlogo.png', // 你网站的标志
		theme: 'auto'
		},
	events: {
		onVerificationFlowEnd() {
			console.log("验证成功");
			window.location.reload();
			},
            	onVerificationFlowFailed() {
			console.log("验证失败，错误代码：" + error);
			},
            	onAgeVerify() {
			console.log("开始年龄验证流程");
			},
            	onDirectContinue() {
			console.log("直接继续操作");
			},
            	onUnderageSkip() {
			console.log("已跳过");
			},
            	onVerifiedBefore() {
			console.log("此前已验证");
			}
		}
	       }
	);

            var n = document.createEvent("Event");
            n.initEvent("DOMContentLoaded", !0, !0),
            document.dispatchEvent(n);
}

const TARGET_SELECTOR = '.main, .footer; // 替换为将拦截点击的类

function intercept(e) {
   const container = e.target.closest(TARGET_SELECTOR);
   if (!container) return; 
        
   e.preventDefault();
   e.stopImmediatePropagation(); 
   e.stopPropagation();

   verifier(e, container);
}
```

此文件包含三个函数：一个用于检测 cookie 的函数、一个用于加载 AgeGO 覆盖层的函数，以及一个用于检测对特定类的点击的函数。在本例中，我们使用的类是 `.main` 和 `.footer`.

然后，在你网站的 HTML 中，你需要放入以下内容：

```html
<!-- 来自 AgeGo 的代码-->
<script src="https://verifycdn.agego.com/v1/verify.js"></script>

<!-- 自定义函数代码-->
<script src="main.js"></script>

<!-- 广告提供商代码-->
<script async type="application/javascript" src="https://a.magsrv.com/ad-provider.js"></script>

<!-- 广告位。XXXX 和 YYYYY 对应管理员面板提供的类和广告位 ID。 -->
<div id="videontv">
  <ins class="XXXXXX" data-zoneid="YYYYYY" data-block-ad-types="101"  data-ex_av="2"></ins> 
  <ins class="XXXXXX" data-zoneid="YYYYYY" data-block-ad-types="101"  data-ex_av="2"></ins> 
</div>

<!-- 使用正确参数投放广告的代码-->
<script>
	const agegoValue = getCookie("agego_aver");
	if (agegoValue !== false)  {
               console.log("用户已验证");
        	   const adInsElements = document.querySelectorAll("ins");
        	   adInsElements.forEach(ins => {
            	ins.setAttribute("data-ex_av", "1");
            	ins.setAttribute("data-block-ad-types", "0");
        		});
    	   }
             else {
                 console.log("用户未验证");
                 ['pointerdown', 'click', 'touchstart'].forEach(type => {
                 document.addEventListener(type, intercept, { capture: true });
                 });
             }
	(AdProvider = window.AdProvider || []).push({"serve": {}});
</script>
```

在这个示例中， **默认情况下，广告在用户验证年龄之前都是 SFW**。当用户点击我们前面提到的所选类时，AgeGO 覆盖层就会出现。用户验证年龄后， **页面将正常加载，这次不会屏蔽任何广告**.

***

关于本教程的几点说明：

1. 此设置依赖于 `agego_aver` 由 AgeGO 设置的 cookie。不过，这可以更改：你可以使用 AgeGO 脚本的事件在 localStorage 中设置一个值，然后根据该值决定显示哪些广告。
2. 这两种方法都只关注广告投放。此代码不考虑视频缩略图和网站的其他内容。
3. 目前，AgeGO 没有内置的国家/地区检测功能。你需要决定何时显示这段代码。

***

如果你想根据你选择的不同事件来设置 `data-ex_av` 和 `data-block-ad-types` ，那么请考虑查看我们的其他教程： [动态屏蔽广告类型](/tutorials/tutorials/publishers-tutorials/dynamically-block-ads-using-data-block-ad-types.md), [在流内广告位中动态屏蔽广告类型](/tutorials/tutorials/publishers-tutorials/dynamically-block-ad-types-for-exoclick-in-stream-zones.md).

最后，若想了解与年龄验证解决方案进行更通用的广告位集成，请查看 [另一个教程。](/tutorials/tutorials/publishers-tutorials/serve-sfw-ads.md)


---

# 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/exoclick-agego.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.
