修改GPT setTargeting
API调用
最近更新: 2024年7月22日
在调用Google Publisher Tag .setTargeting
方法之前添加if语句以检查Audience ManagerCookie。
使用IF
语句检查Audience ManagerCookie
.setTargeting
方法从Audience Manager目标Cookie和唯一用户ID Cookie ( aam_uuid
)获取数据。 但是,如果在DIL写入这些Cookie之前调用了.setTargeting
,或者Cookie为空,则您可能会在页面加载时看到错误。 为避免出现这种情况,请将.setTargeting
方法包装在检查这些Cookie的if
语句中。 如果未设置这些参数,此语句将阻止.setTargeting
调用AamGpt
函数。
IF
语句代码示例
在此示例中,Audience Manager目标Cookie名称为Sample
。 在Audience Manager用户界面中创建目标Cookie时设置此名称。 DIL设置aam_uuid
Cookie,且名称无法更改。
if(typeof AamGpt.getCookie("Sample") != "undefined"){
googletag.pubads().setTargeting(AamGpt.getKey("Sample"),AamGpt.getValues("Sample"));
};
if(typeof AamGpt.getCookie("aam_uuid") != "undefined" ){
googletag.pubads().setTargeting("aamId", AamGpt.getCookie("aam_uuid"));
};
根据您希望如何与Google Ad Manager集成,您只需要上述代码示例中的某些行:
- 客户端集成:仅使用第1-3行。
- 服务器端集成:无需任何线路。
- 摄取Google Ad Manager日志文件以在Audience Manager中报告:仅使用第4-6行。 此代码会将
aam_uuid
Cookie的值插入日志,以便将其摄取用于报表。
AamGpt
函数和数据类型
定义if
语句中使用的键变量。
函数 | 类型 | 描述 |
---|---|---|
AamGpt.getKey | 字符串 | 返回键值区段对中的键。 例如,如果您的键值对由 color=blue 组成,则返回 color 。 |
AamGpt.getValues | 字符串数组 | 返回数组中的值,如 ["value1","value2"] 。 |
AamGpt.getCookie | 整数 | 返回Audience Manager的用户ID,例如 12345 。 |
Related Articles
Audience Manager
- Audience Manager 指南
- Real-Time CDP的演变指南
- 迁移到Web SDK
- 概述
- 功能
- 报表
- API和SDK代码
- Data Integration Library (DIL) API
- 实施和集成指南
- 参考
- 常见问题解答
- 帮助和法律信息
- 主要客户支持问题
- 文档更新
- 术语表