setTargeting
API调用在调用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集成的方式,您只需要上面代码示例中的一些行:
aam_uuid
Cookie的值插入日志,以便可以摄取这些值以进行报告。AamGpt
函数和数据类型定义if
语句中使用的键变量。
函数 | 类型 | 描述 |
---|---|---|
|
字符串 |
返回键值区段对中的键。 例如,如果键值对包含 |
|
字符串数组 |
返回数组中的值,例如 |
|
整数 |
返回Audience Manager用户ID,例如 |