> 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)。然后前往“My Sites”，并点击“New Site”：

![ExoClick AgeGO 1](https://content.gitbook.com/content/GoSwRYjxsR1XS6va6yLj/blobs/bB1LSjp55HpIccLbeC8G/assets/hires/agego-1.png)

在这些设置中，至少需要填写 **名称** 和 **顶级域名**。完成这些设置后，点击“Create”。该网站便会添加到你的账户中。

默认情况下，所有新建网站的状态都是“Ready”。不过，这并不意味着你的网站已经可以使用 AgeGO。要在网站上启用 AgeGO，你需要 [**通过联系表单联系 AgeGO**](https://www.agego.com/contact-us-business) **并提供与你的网站对应的 Site ID。**

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

![ExoClick AgeGO 2](https://content.gitbook.com/content/GoSwRYjxsR1XS6va6yLj/blobs/GMJYtpAAJvSxFMxPWlpc/assets/hires/agego-2.png)

网站获批后，其状态会变为“Running”，你就可以按照集成说明在网站上集成 AgeGO。目前此解决方案提供两种方法： **Modal（简单或高级）** 和 **S2S**。每种方法的设置说明都可以在 AgeGO 控制面板中查看。本指南将介绍 **Modal** 方法。

## 如何传递年龄验证状态并投放 SFW 广告

使用年龄验证系统（AgeGO 或其他服务提供商）时，你可能希望继续向所有用户展示广告，包括未验证年龄和已验证年龄的用户。

要标识用户是否已通过年龄验证，请在广告位上使用 `data-ex_av` 参数。该参数支持以下 3 个值：

* “0”：未进行年龄验证（未定义）
* “1”：年龄验证——已验证
* “2”：年龄验证——未验证

接下来，要屏蔽向特定用户（在此情形下，即未验证年龄的用户）展示广告，请使用 `data-block-ad-types` 参数。该参数支持多个值，但本指南只使用值 `101`.

因此，如果你想投放适合所有年龄段的广告，并将该用户标识为尚未验证年龄的用户，可以按如下方式集成这些参数：

* **异步广告格式（横幅、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&block_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("Verification successfull");
			window.location.reload();
			},
            	onVerificationFlowFailed() {
			console.log("Verification failed with errorcode:" + error);
			},
            	onAgeVerify() {
			console.log("Begin Age Verification process");
			},
            	onDirectContinue() {
			console.log("DirectContinue action");
			},
            	onUnderageSkip() {
			console.log("Skipped");
			},
            	onVerifiedBefore() {
			console.log("Verified Before");
			}
		}
	       }
	);

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

const TARGET_SELECTOR = '.main, .footer; // replace with classes where click will be intercepted

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("user verified");
        	   const adInsElements = document.querySelectorAll("ins");
        	   adInsElements.forEach(ins => {
            	ins.setAttribute("data-ex_av", "1");
            	ins.setAttribute("data-block-ad-types", "0");
        		});
    	   }
             else {
                 console.log("user not verified");
                 ['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` 可以参考我们的其他教程： [动态屏蔽广告类型](https://docs.exoclick.com/tutorials/zh/jiao-cheng/mei-ti-zhu-jiao-cheng/dynamically-block-ads-using-data-block-ad-types.md), [在插播广告区域动态屏蔽广告类型](https://docs.exoclick.com/tutorials/zh/jiao-cheng/mei-ti-zhu-jiao-cheng/dynamically-block-ad-types-for-exoclick-in-stream-zones.md).

最后，如果想了解如何将广告区域与年龄验证解决方案进行更通用的集成，请参阅 [这篇其他教程。](https://docs.exoclick.com/tutorials/zh/jiao-cheng/mei-ti-zhu-jiao-cheng/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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.exoclick.com/publishers/zh/exoclick-agego.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
