We’ve migrated our documentation to a new site, which means some URLs have changed.
Audience

GAM Ad Tag modification: Custom targeting

There are several cases:

Examples are below.

Case 1: You have no Piano segment integration configured

To match GAM impressions/clicks against Performance events, we need to know: your Piano Audience site ID, prnd and Piano user ID. They are passed via GAM custom targeting (note ".setTargeting(...)" calls in the modified tags).

Source version

(... skipping code that loads the google ad script ...)
<head>
<script type='text/javascript'>
googletag.cmd.push(function() {
googletag.defineSlot('/42072717/TestUnit', [400, 150], 'div-gpt-ad-1421314147467-0').addService(googletag.pubads());
googletag.enableServices();
});
</script>
</head>

<body>
<!-- the code that places the ad -->
<div id='div-gpt-ad-1421314147467-0'>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1421314147467-0'); });
</script>
</div>
</body>

Modified version

(... skipping code that loads the google ad script ...)

TODO: If the Cxense analytics script is not on the page where this tag runs, then a dummy analytics event has to be sent to link the user cross sites

<head>
<script type='text/javascript'>
var cX = cX || {}; cX.callQueue = cX.callQueue || [];
cX.callQueue.push(['invoke', function() {
googletag.cmd.push(function() {
googletag.defineSlot('/42072717/TestUnit', [400, 150], 'div-gpt-ad-1421314147467-0')
.addService(googletag.pubads())
.setTargeting("cxprnd", cX.getPageContext().pageViewRandom)
.setTargeting("cxid", cX.getUserId())
.setTargeting("cxsiteid", "12345"); //replace '12345' with actual CX site id
googletag.enableServices();
});
}]);

// Async load of cx.js
(function(d,s,e,t){e=d.createElement(s);e.type='text/java'+s;e.async='async';
e.src='http'+('https:'===location.protocol?'s://s':'://')+'cdn.cxense.com/cx.js';
t=d.getElementsByTagName(s)[0];t.parentNode.insertBefore(e,t);})(document,'script');
</script>
</head>

<body>
<!-- the code that places the ad -->
<div id='div-gpt-ad-1421314147467-0'>
<script type='text/javascript'>
cX.callQueue.push(['invoke', function() {
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1421314147467-0'); });
}]);
</script>
</div>
</body>

Synchronous ad tag

<!DOCTYPE html>
<html>
<head>
<title>Google DFP sync tag</title>
<!-- Load the Google script synchronously -->
<script type="text/javascript">
(function() {
var useSSL = 'https:' == document.location.protocol;
var src = (useSSL ? 'https:' : 'http:') + '//www.googletagservices.com/tag/js/gpt.js';
document.write('<scr' + 'ipt src="' + src + '"></scr' + 'ipt>');
})();
</script>
<!-- Load the Cxense script synchronously -->
<script type="text/javascript">
document.write('<scr' + 'ipt type="text/javascript" src="http' +
(location.protocol === 'https:' ? 's://s' : '://') + 'cdn.cxense.com/cx.js"></scr' + 'ipt>');
</script>
<!-- Setup the ad slots and targeting -->
<script type="text/javascript">
googletag.defineSlot('/42072217/TestUnit', [400, 150], 'div-gpt-ad-14213141474671-0')
.addService(googletag.pubads())
.setTargeting("cxprnd", cX.getPageContext().pageViewRandom)
.setTargeting("cxid", cX.getUserId())
.setTargeting("cxsiteid", "12345"); //replace '12345' with actual CX site id

googletag.pubads().enableSingleRequest();
googletag.pubads().enableSyncRendering();
googletag.enableServices();
</script>
</head>
<body>
<!-- The actual rendering of the ad -->
<div id="div-gpt-ad-14213141474671-0" style="width: 400px; height: 150px">
<script type="text/javascript">
googletag.display("div-gpt-ad-14213141474671-0");
</script>
</div>
</body>
</html>

Case 2: You already have segments integration with Piano

Source code with Piano segments

(... removed the code that loads the google ad script ...)

TODO: If the Cxense analytics script is not on the page where this tag runs, then a dummy analytics event has to be sent to link the user cross sites

<head>
<script type='text/javascript'>
var cX = cX || {}; cX.callQueue = cX.callQueue || [];
cX.callQueue.push(['invoke', function() {
googletag.cmd.push(function() {
googletag.defineSlot('/42072717/TestUnit', [400, 150], 'div-gpt-ad-1421314147467-0').addService(googletag.pubads()).setTargeting("CxSegments",cX.getUserSegmentIds({persistedQueryId:'1234567890'})).;
googletag.enableServices();
});
}]);

// Async load of cx.js
(function(d,s,e,t){e=d.createElement(s);e.type='text/java'+s;e.async='async';
e.src='http'+('https:'===location.protocol?'s://s':'://')+'cdn.cxense.com/cx.js';
t=d.getElementsByTagName(s)[0];t.parentNode.insertBefore(e,t);})(document,'script');
</script>

</head>

<body>

<!-- the code that places the ad -->
<div id='div-gpt-ad-1421314147467-0'>
<script type='text/javascript'>
cX.callQueue.push(['invoke', function() {
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1421314147467-0'); });
}]);
</script>
</div>

</body>

Modified tag with Piano segments

(... removed the code that loads the google ad script ...)

TODO: If the Cxense analytics script is not on the page where this tag runs, then a dummy analytics event has to be sent to link the user cross sites

<head>
<script type='text/javascript'>
var cX = cX || {}; cX.callQueue = cX.callQueue || [];
cX.callQueue.push(['invoke', function() {
googletag.cmd.push(function() {
googletag.defineSlot('/42072717/TestUnit', [400, 150], 'div-gpt-ad-1421314147467-0').addService(googletag.pubads()).setTargeting("CxSegments",cX.getUserSegmentIds({persistedQueryId:'1234567890'})).
.setTargeting("cxprnd", cX.getPageContext().pageViewRandom)
.setTargeting("cxid", cX.getUserId())
.setTargeting("cxsiteid", "12345"); //replace '12345' with actual CX site id

googletag.enableServices();
});
}]);

// Async load of cx.js
(function(d,s,e,t){e=d.createElement(s);e.type='text/java'+s;e.async='async';
e.src='http'+('https:'===location.protocol?'s://s':'://')+'cdn.cxense.com/cx.js';
t=d.getElementsByTagName(s)[0];t.parentNode.insertBefore(e,t);})(document,'script');
</script>

</head>

<body>

<!-- the code that places the ad -->
<div id='div-gpt-ad-1421314147467-0'>
<script type='text/javascript'>
cX.callQueue.push(['invoke', function() {
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1421314147467-0'); });
}]);
</script>
</div>

</body>

Last updated: