setTargeting
API CallAdd an if statement to check for Audience Manager cookies before calling the Google Publisher Tag .setTargeting
method.
IF
StatementThe .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’re not set, this statement prevents .setTargeting
from calling the AamGpt
function.
IF
Statement Code SampleIn 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"));
};
Depending on how you want to integrate with Google Ad Manager, you only need some of the lines in the code sample above:
aam_uuid
cookie into the logs so they can be ingested for reporting.AamGpt
Functions and Data TypesDefines the key variables used in the if
statement.
Function | Type | Description |
---|---|---|
|
String |
Returns the key in the key-value segment pair. For example, if your key-value pair consisted of |
|
Array of strings |
Returns values in an array, e.g., |
|
Int |
Returns the Audience Manager user ID, e.g., |