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
- Create the Profiles API Token
- Name Your New Token
- Configure the Token
- Add Segments to the Token
- Integrating TD Profiles API with Marketo
- Configure Marketo for use with the Profiles API Token
- Add a Marketo RTP Tag and Treasure Data Tag
- Examples
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.
- Open TD Console.
- Navigate to Audience Studio and select a segment.
- Select a folder.
- Select Create New.
- Select Profile API Token.

- Enter a name for your token and optionally enter a description. Select Next.
The name and description carry over from when you named the token. You can make changes.
- 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: 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.
- (Optional) Enter a maximum of five attributes.
Profile attributes can be returned from the profile token when queried.

- 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.)

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

- Add segments to your Profiles API Token.
- Select Save.

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
- Open Marketo.
- Select the Marketo icon.
- Select Web Personalization.

- Select Segments.

- Select Create New.

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

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

- Select the segment name that you created in Treasure Data.
- Set the contents. For example, Dialog, In Zone, and Widget.

- Load Market's Web Personalization JavaScript tag into your page. See examples below and refer to Marketo Documentation: Web Personalization
- Add a call to the Profiles API Token.
- 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.
- Test your code. For example:

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>