Sending targeting key values to AdManager

We send targeting segments to AdManager in the form of key-values. Key values allow real-time targeting, flexible reporting on available reporting, and they are accessible through %PATTERN:key% macros inside creatives. This makes it the most flexible way to send targeting data to AdManager.

 

The one technical limitation is that key-values need to be added to Google Publisher Tag before the .display() function is called on placements.

 

Below you can find the snippet that needs to be added to the website so it fires on all pages, and that before Google Publisher Tag requests ads from DFP. It is a zero latency script. Usually it is 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 works in accompaniment with the SAK script. The SAK script is usually loaded in Google Tag Manager, and you can add the above 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>

NB!: Please be aware that "clientId" needs to be switched out with your company's personalized ID. Please contact support@audienceproject.com if you are in doubt what your ID is. 

Testing

The integration is performed by the development team on the publisher side. Therefore we have ensured that the integration can be tested in a non-production environment.

We have implemented the following debug helper to verify the implementation. You can fill the cache with fake data by entering the following parameter on a page where the script is present:  ?__sak_fakeads=1101,1500,random5 like http://example.com/?__sak_fakeads=1101,1500,random5. This will cache key-values with ids 1, 3, 5 and random 5 from syncing. You can 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