Modify the GPT setTargeting API Call modify-the-gpt-settargeting-api-call
Add an if statement to check for Audience Manager cookies before calling the Google Publisher Tag .setTargeting method.
Check for Audience Manager Cookies With an IF Statement
The .setTargeting method gets data from the Audience Manager destination cookie and the unique user ID cookie ( aam_uuid). However, if .setTargeting gets invoked before DIL writes these cookies, or the cookies are empty, you may see errors when the page loads. To help avoid this, wrap the .setTargeting method in an if statement that checks for these cookies. If they鈥檙e not set, this statement prevents .setTargeting from calling the AamGpt function.
IF Statement Code Sample
In this example, the Audience Manager destination cookie name is Sample. You set this name when you create the destination cookie in the Audience Manager user interface. DIL sets the aam_uuid cookie and the name cannot be changed.
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"));
};
- Client-side integration: use lines 1-3 only.
- Server-side integration: none of the lines are needed.
- Ingest Google Ad Manager log files for reporting in Audience Manager: use lines 4-6 only. This code inserts the value of the
aam_uuidcookie into the logs so they can be ingested for reporting.
AamGpt Functions and Data Types
Defines the key variables used in the if statement.
AamGpt.getKeycolor=blue , this returns color .AamGpt.getValues["value1","value2"] .AamGpt.getCookie12345 .