Sending targeting key values to AdManager

We allow to send targeting segments in AdManager in form of key-values. Key values allows realtime targeting, flexible reporting on available reporting, key-values are accessible through %PATTERN:key% macro inside creatives, so it is most flexible to send targeting data to AdManager.

 

There is one technical limitations, that key-values needs to be added to Google Publisher Tag before .display() function is called on placements.

 

Below you can find snippet needs to be added to website to fire on all page before Google Publisher Tag requests ads from DFP. It is zero latency script. It is usually fine to deploy through Google Tag Manager, in <head> or inside Google Publisher Tag implementation.

<script>
function getAudienceProjectTargetingData() { "use strict"; var CACHE_KEY = "apr_tdc"; try { var json = window.localStorage.getItem(CACHE_KEY); if (json) { var cache = JSON.parse(json); if (cache.exp > Date.now()) { return cache.d; } else { window.localStorage.removeItem(CACHE_KEY); } } } catch (err) { window.localStorage.removeItem(CACHE_KEY); } return {}; } (function () { var setTargeting = function () { var targetingData = getAudienceProjectTargetingData(); for (var key in targetingData) { if (targetingData.hasOwnProperty(key)) { window.googletag.pubads().setTargeting(key, targetingData[key]); } } }; window.googletag = window.googletag || {}; window.googletag.cmd = window.googletag.cmd || []; if (window.googletag.cmd.unshift) { window.googletag.cmd.unshift(setTargeting); } else { window.googletag.cmd.push(setTargeting); } })();
</script>

 

This script makes works in accompaniment with SAK script. SAK script is usually loaded in Google Tag Manager, and you can add this snippet before SAK, so it looks like this

 

<script>
function getAudienceProjectTargetingData() {
  "use strict";

  var CACHE_KEY = "apr_tdc";
  try {
    var json = window.localStorage.getItem(CACHE_KEY);
    if (json) {
      var cache = JSON.parse(json);
      if (cache.exp > Date.now()) {
        return cache.d;
      }
      else {
        window.localStorage.removeItem(CACHE_KEY);
      }
    }
  }
  catch (err) {
    window.localStorage.removeItem(CACHE_KEY);
  }
  return {};
}

(function () {
  var setTargeting = function () {
    var targetingData = getAudienceProjectTargetingData();
    for (var key in targetingData) {
      if (targetingData.hasOwnProperty(key)) {
        window.googletag.pubads().setTargeting(key, targetingData[key]);
      }
    }
  };

  window.googletag = window.googletag || {};
  window.googletag.cmd = window.googletag.cmd || [];
  if (window.googletag.cmd.unshift) {
    window.googletag.cmd.unshift(setTargeting);
  }
  else {
    window.googletag.cmd.push(setTargeting);
  }
})();
</script>
<script src="https://sak.userreport.com/clientId/launcher.js" async></script>

 

Testing

Integration is performed by the development team on publisher side, therefore we ensured that integration can be tested on non-production environment.

On our end we implemented the following debug helper to verify the implementation. You can fill the cache with fake data by entering page with our script present with parameter ?__sak_fakeads=1101,1500,random5 like http://example.com/?__sak_fakeads=1101,1500,random5. It will put key-values with ids 1, 3, 5 and random 5 from synced. You can find find your key-values in AdManager's key-management section.

Test scenario would be following:

  1. Implement snippet in GTM or inside Google Publisher Tag
  2. Enter http://example.com/?__sak_fakeads=1101,1500 so something is put into cache
  3. Reload the page, so snippet will capture data from cache and send to AdManager

 

Attachments

Comments

Powered by Zendesk