Skip to content
Last updated

Use the Profiles API With Marketo Web Personalization

You can integrate Treasure Data’s Profiles API Token with Marketo’s Web Personalization feature to provide a 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.

Create the Profiles API Token

Name Your New Token

  1. Open TD Console.
  2. Navigate to Audience Studio and select a segment.
  3. Select a folder.
  4. Select Create New.
  5. Select Profile API Token.

  1. Enter a name for your token and optionally enter a description. Select Next.

Configure the Token

The name and description carry over from when you named the token. You can make changes.

  1. Enter a Lookup Key.

A Lookup Key is a column with a unique value inside a parent segment. This key identifies the correct profile.

Note

Note: The lookup key update will take effect once the token workflow finishes.

When using td_global_id as the lookup key, the Profiles API retrieves the lookup value from the browser cookie instead of the API request's query param. For testing or verification purposes outside of a browser (eg, Postman), use a different column to pass in the lookup value manually.

  1. (Optional) Enter a maximum of five attributes.

Profile attributes can be returned from the profile token when queried.

  1. Choose one of the following:
  • Select Next to continue and add Segments.
  • Select Create to configure the token. (You can add segments later if you want.)

Add Segments to the Token

  1. Choose one of the following:
  • After you configure your token, select Next.
  • Navigate to Audience Studio > Folder > Profiles API Token.

  1. Add segments to your Profiles API Token.
  2. Select Save.

Integrating TD Profiles API with Marketo

Complete the steps in the following sections to integrate the Profiles API Token with Marketo:

  • Configure Marketo for use with the TD profile API

  • Create JavaScript DFP and Treasure Data Tags

Configure Marketo for use with the Profiles API Token

  1. Open Marketo.
  2. Select the Marketo icon.
  3. Select Web Personalization.

  1. Select Segments.

  1. Select Create New.

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

  1. Select Save.
  2. Navigate to Campaign. For example, select Marketo logo > Campaign.
  3. Select Create New Web Campaign.

  1. Select the segment name that you created in Treasure Data.
  2. 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 the Profiles API Token.
  3. Send the response to Marketo using the User Context feature of Marketo’s RTP tag.
  4. See examples below and refer to Marketo Documentation: User Context.
  5. 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 the Profiles API Token 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","blockEvents","fetchServerCookie","fetchGlobalID","fetchUserSegments","resetUUID","ready","setSignedMode","setAnonymousMode","set","trackEvent","trackPageview","trackClicks","unblockEvents"],n=0;n<s.length;n++){var c=s[n];e[t].prototype[c]=r(c)}var o=document.createElement("script");o.type="text/javascript",o.async=!0,o.src=("https:"===document.location.protocol?"https:":"http:")+"//cdn.treasuredata.com/sdk/2.14/td.min.js";var a=document.getElementsByTagName("script")[0];a.parentNode.insertBefore(o,a)}}("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>