This article supports Audience Studio - Legacy.

You can integrate Treasure Data’s Profiles API with Google DFP (DoubleClick for Publishers). This integration allows advertisers to put ads on the segments you have defined in Treasure Data.

Prerequisites

  • Basic knowledge of JavaScript and HTML

  • Basic knowledge of Treasure Data

  • Basic knowledge of Treasure Data JavaScript SDK

  • Basic knowledge of Treasure Data Profiles API

  • Basic knowledge of Google DFP (DoubleClick for Publishers)

Use of Treasure Data JavaScript SDK might require the direction of Treasure Data Support or Services team.

Integrating TD Profiles API with Google DFP

Complete the steps in the following sections to integrate the TD profiles API with Google DFP:

Configure Google DFP for use with the TD profile API

  1. In your web browser, navigate to Google DFP.

  2. Navigate to Inventory > Key-values.

  3. Select New Key.

  4. Complete the Name and Display name fields.


  5. Select Add Values.

  6. List all Treasure Data segment IDs, line-by-line. For example, 257, 258, 259.


  7. Select Apply.

  8. Optionally, add Display name to specific segment IDs.


  9. Select Inventory > Ad units.

  10. Select Ad Unit

  11. Complete the Code and Name fields.


  12. Select Save.

  13. Select Delivery > Orders.

  14. Select New Order to create a new order.


  15. Edit the fields. For example, Name, Advertiser, Name, Start time, End time, Quantity, and Rate.

  16. Scroll down to locate the Key-values section.

  17. Specify the Key-value that you created. For example, td_kv_wp.


  18. Select the list of Segment IDs that you created. For example:


  19. Select Inventory.

  20. Select the advertisement unit that you created. For example, td-dfp-test-ad. An order object is created. For example:


  21. Navigate to Delivery > Line Items, to register the creatives.

  22. Select Add Creatives.


  23. Select the creative type you’d like to create. For example, an image creative.


  24. Specify the Name and Destination.

  25. Upload an image file for the creative.

  26. Specify a Destination. For example, https://www.treasuredata.com/.


Create JavaScript DFP and Treasure Data Tags

To generate Google DFP’s JavaScript tag:

  1. In your web browser, navigate to Google DFP.

  2. Navigate to Inventory > Ad units.

  3. Select Generate Tags.

  4. Select the advertising units that you created. For example, td-dfp-test-ad.


  5. Select Google Publisher Tag as the Tag Type.


  6. Select Continue. A JavaScript tag is generated for the HTML header and body.


  7. Save your work.


To combine the DFP tag and your Treasure Data JavaScript tag:

  1. Open the file where you want to combine your Treasure Data JavaScript and DFP tags.

  2. Call googletag.pubads().setTargeting() function to pass Treasure Data’s segment IDs to Google DFP.

For example, the following 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 type="text/javascript">
!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/2.1/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 (values) {  var segIdAll = [];  for (var i = 0; i < values.length; i++) {    segIdAll = segIdAll.concat(values[i].values);  };  var segId = segIdAll.filter(function (x,i,self) {return self.indexOf(x) === i;});  console.log(JSON.stringify(segId));  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',segId);     googletag.enableServices();     googletag.cmd.push(function() { googletag.display('div-gpt-ad-XYZ-0')});   }); };
var errorCallback = function (error) { console.log(err); };

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

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

<title>Web Profiles 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>

To test, access the HTML above, and review the result.



  • No labels