This article supports Audience Studio - Legacy.

You can integrate Treasure Data’s Profiles API with Marketo’s Web Personalization feature to provide fully personalized experience for your customers by leveraging all of your customer 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 Marketo Web Personalization

  • Access to Marketo’s add-on Web Personalization feature.

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

Integrating TD Profiles API with Marketo

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

  • Configure Marketo for use with the TD profile API

  • Create JavaScript DFP and Treasure Data Tags

Configure Marketo for use with the TD Profile API

  1. Open Marketo.

  2. Select the Marketo icon.

  3. Select Web Personalization.


  4. Select Segments.



  5. Select Create New.


  6. Specify the segment number that you created in Treasure Data.


  7. Select Save.

  8. Navigate to Campaign. For example, select Marketo logo > Campaign.

  9. Select Create New Web Campaign.


  10. Select the segment name that you created in Treasure Data.

  11. Set the contents. For example, Dialog, In Zone, and Widget.


Add a Marketo RTP Tag and Treasure Data Tag

  1. Load Market’s Web Personalization JavaScript tag into your page. See examples below and
    refer to Marketo Documentation: Web Personalization

  2. Add a call to Treasure Data’s Profiles API.

  3. Send the response to Marketo using the User Context feature of Marketo’s RTP tag.
    See examples below and refer to Marketo Documentation: User Context.

  4. Test your code. For example:


Examples

Example code for loading Market’s Web Personalization JavaScript tag into your page:

<!-- Marketo RTP tag -->
(function(c,h,a,f,e,i){c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
c[a].p=e;c[a].a=i;var g=h.createElement("script");g.async=true;g.type="text/javascript";
g.src=f;var b=h.getElementsByTagName("script")[0];b.parentNode.insertBefore(g,b)})
(window,document,"rtp","[rtp-js-cdn-url]","[pod-url]","[accountId]");
rtp('setAccount', 'YOUR_MARKETO_ACCOUNT_ID');


Example code for integrating TD profiles API with Marketo web personalization

<script type="text/javascript">
  <!-- Marketo RTP -->
  (function(c,h,a,f,e,i){c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
  c[a].p=e;c[a].a=i;var g=h.createElement("script");g.async=true;g.type="text/javascript";
  g.src=f;var b=h.getElementsByTagName("script")[0];b.parentNode.insertBefore(g,b)})
  (window,document,"rtp","[rtp-js-cdn-url]","[pod-url]","[accountId]");
  rtp('setAccount', 'YOUR_MARKETO_ACCOUNT_ID');
  
  <!-- Treasure Data -->
  !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","setblockEvents","fetchServerCookie","trackEventfetchGlobalID","trackPageviewfetchUserSegments","trackClicksresetUUID","ready","setSignedMode","setAnonymousMode","set","trackEvent","trackPageview","fetchGlobalIDtrackClicks","fetchUserSegmentsunblockEvents"],an=0;a<sn<s.length;an++){var c=s[an];e[t].prototype[c]=r(c)}var no=document.createElement("script");no.type="text/javascript",no.async=!0,no.src=("https:"===document.location.protocol?"https:":"http:")+"//cdn.treasuredata.com/sdk/2.14/td.min.js";var ia=document.getElementsByTagName("script")[0];ia.parentNode.insertBefore(no,ia)}}("Treasure",this);
  
  // Configure an instance for your database
  var td = new Treasure({
    host: 'in.treasuredata.com',
    writeKey: '[YOUR_WRITE_KEY]',
    database: '[YOUR_DB_NAME]'
  });
  
  // Enable cross-domain tracking
  td.set('$global', 'td_global_id', 'td_global_id');
  
  // Get segment number from TD and send it to Marketo's RTP
    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;
        }); 
        // http://developers.marketo.com/javascript-api/web-personalization/user-context/  
        rtp('set', 'customVar1', segId.join(";"));
    };
    var errorCallback = function(err) {
      console.log(err);
    };
  
  var trackPageviewSuccessCallback = function(){
    td.fetchUserSegments({
      audienceToken: ['YOUR_PROFILES_API_TOKEN_1', 'YOUR_PROFILES_API_TOKEN_2'],
      keys: {
        key_column_1: 'someValue',
        key_column_2: 'someOtherValue',
      }
    }, successCallback, errorCallback)
  };
  
  td.trackPageview([YOUR_TABLE_NAME], trackPageviewSuccessCallback);
</script> 
  • No labels