修改GPT setTargeting
API呼叫 modify-the-gpt-settargeting-api-call
Audience Manager新增if陳述式以在呼叫 Google Publisher Tag .setTargeting
方法。
使用檢查Audience ManagerCookie IF
陳述式
此 .setTargeting
方法會從Audience Manager目的地Cookie和不重複使用者ID Cookie ( aam_uuid
)。 但是,如果 .setTargeting
之前叫用的次數 DIL 寫入這些Cookie,或Cookie是空的,您可能會在頁面載入時看到錯誤。 為協助避免此問題,請換行 .setTargeting
中的方法 if
檢查這些Cookie的陳述式。 若未設定,此陳述式會防止 .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"));
};
IMPORTANT
視您想要與整合的方式而定 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
Int
傳回Audience Manager的使用者ID,例如
12345
.recommendation-more-help
de293fbf-b489-49b0-8daa-51ed303af695