Visit our new documentation site! This documentation page is no longer updated.

Personalization API with Google DFP (DoubleClick for Publishers)

Integrate Treasure Data’s Personalization API with Google DFP (DoubleClick for Publishers) to enable advertisers to put ads on the specific segments created on the Treasure Data Platform.

Table of Contents

Prerequisites

  • Basic knowledge of JavaScript / HTML
  • Basic knowledge of Treasure Data
  • Basic knowledge of Treasure Data JavaScript SDK
  • Basic knowledge of Treasure Data Personalization API
  • Basic knowledge of Google DFP (DoubleClick for Publishers)

Step 1: Google DFP Settings

Step 1-1: Register Treasure Data’s SegmentIDs

First, select Key-values menu under Inventory. Then, click New Key. Complete the Name and Display name fields, and then click Add Values.

List all Treasure Data segment IDs, line-by-line (in this case, 257, 258, 259).

You can also add Display name to specific segment IDs.

Step 1-2: Create an Advertisement Unit

Let’s create an advertisement unit. Click Ad units menu under Inventory, and then click New ad unit. Complete the Code and Name fields.

Step 1-3: Create Order and Advertisement Information

Click Orders under Delivery, and then click New Order to create a new order.

Fill in the fields such as Name, Advertiser, Name, Start time, End time, Quantity, and Rate.

Under Add targeting, there’s a section called Key-values. Here you can create the Key-value created at Step 1-1 (in this example, td_kv_wp).

Select a list of Treasure Data segment IDs as defined at Step 1-1.

Under Inventory tab, select the advertisement unit registered in Step 1-2 (in this example, td-dfp-test-ad).

As a result, an order object is created as shown in the following example.

Step 1-4: Register the Creatives

The next step is to register the creative. Click Line Items under Delivery, and click Add Creatives.

Then, select the creative you’d like to apply. In this example, we’ll choose the image creative.

Specify the Name and Destination, and upload the image file for the creative.

Step 2: JavaScript Tag Implementation

Step 2-1: Generate DFP JavaScript Tag

Now let’s generate Google DFP’s JavaScript Tag. Go to Ad units under Inventory, select Generate Tags tab, and select your advertising units created at Step 1-2 (in this example, td-dfp-test-ad).

Select Google Publisher Tag as the Tag Type.

As a result, you will have a JavaScript tag generated for both HTML document header and body.

Step 2-2: Combine DFP Tag and Treasure Data Tag

Finally, let’s combine both Google DFP Tag and Treasure Data JavaScript Tag. The key is to call googletag.pubads().setTargeting() function to pass Treasure Data’s segment IDs to Google DFP.

Below is the example HTML contains the integration code between DFP JavaScript Tag and TD JavaScript Tag.

<!DOCTYPE html><html>
<head>

<!-- Load DFP Tag -->
<script async='async' src='https://www.googletagservices.com/tag/js/gpt.js'></script>

<!-- Load Treasure Data Tag -->
<script>
!function(t,e){if(void 0===e[t]){e[t]=function(){e[t].clients.push(this),this._init=[Array.prototype.slice.call(arguments)]},e[t].clients=[];for(var r=function(t){return function(){return this["_"+t]=this["_"+t]||[],this["_"+t].push(Array.prototype.slice.call(arguments)),this}},s=["addRecord","set","trackEvent","trackPageview","trackClicks","ready","fetchGlobalID","fetchUserSegments"],a=0;a<s.length;a++){var c=s[a];e[t].prototype[c]=r(c)}var n=document.createElement("script");n.type="text/javascript",n.async=!0,n.src=("https:"===document.location.protocol?"https:":"http:")+"//cdn.treasuredata.com/sdk/1.9.2/td.min.js";var i=document.getElementsByTagName("script")[0];i.parentNode.insertBefore(n,i)}}("Treasure",this);
</script>

<!-- Header Script Tag: Start-->
<script>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];

var td = new Treasure({...})
var successCallback = function (key, segments) {
  console.log({
    'td_global_id': key,
    'td_user_segments': segments,
  });
  googletag.cmd.push(function() {
    googletag.defineSlot('/YOUR_NUMBER_/td-dfp-test-ad', [200, 200], 'div-gpt-ad-YOUR-XYZ-0').addService(googletag.pubads());
    googletag.pubads().enableSingleRequest();
    googletag.pubads().setTargeting('td_kv_wp', segments);
    googletag.enableServices();
    googletag.cmd.push(function() { googletag.display('div-gpt-ad-XYZ-0')});
  });
};
var errorCallback = function (error) { console.log(err); };

td.fetchUserSegments({
  audienceToken: ['YOUR_PERSONALIZATON_API_TOKEN_1', 'YOUR_PERSONALIZATON_API_TOKEN_2'],
  keys: {
    key_column_1: 'someValue',
    key_column_2: 'someOtherValue',
  }
}, successCallback, errorCallback)

</script>
<!-- Header Scriopt Tag: End -->
</head>

<title>Web Personalization API</title>
<body>
<b>Hello Treasure Data!</b>

<!-- DFP Body Tag: Start -->
<div id='div-gpt-ad-YOUR-XYZ-0' style='height:200px; width:200px;'></div>
<!-- DFP Body Tag: End -->

</body>
</html>

Finally, access the HTML above, and review the result.


Last modified: Mar 26 2018 19:43:08 UTC

If this article is incorrect or outdated, or omits critical information, let us know. For all other issues, access our support channels.