# 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](/products/customer-data-platform/audience-studio/profiles/use-the-profiles-api-with-marketo-web-personalization#h1_1644201065)
* [Create the Profiles API Token](/products/customer-data-platform/audience-studio/profiles/use-the-profiles-api-with-marketo-web-personalization#h1__441927612)
* [Name Your New Token](/products/customer-data-platform/audience-studio/profiles/use-the-profiles-api-with-marketo-web-personalization#h2_251609309)
* [Configure the Token](/products/customer-data-platform/audience-studio/profiles/use-the-profiles-api-with-marketo-web-personalization#h2_196158072)
* [Add Segments to the Token](/products/customer-data-platform/audience-studio/profiles/use-the-profiles-api-with-marketo-web-personalization#h1__1028383756)
* [Integrating TD Profiles API with Marketo](/products/customer-data-platform/audience-studio/profiles/use-the-profiles-api-with-marketo-web-personalization#h1__182532925)
* [Configure Marketo for use with the Profiles API Token](/products/customer-data-platform/audience-studio/profiles/use-the-profiles-api-with-marketo-web-personalization#h2_1294540003)
* [Add a Marketo RTP Tag and Treasure Data Tag](/products/customer-data-platform/audience-studio/profiles/use-the-profiles-api-with-marketo-web-personalization#h2_2234673)
* [Examples](/products/customer-data-platform/audience-studio/profiles/use-the-profiles-api-with-marketo-web-personalization#h1__1406500097)


# 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](https://docs.marketo.com/display/public/DOCS/Understanding+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**.


![](/assets/create_profile_api_token.d07368447c21f911e4cd104cea3710cce089327674fbd36df615c051711ff6c9.cf3845cb.png)

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](/assets/note.767ca0ca6d076817a978148fbb7dd2a68ca7d067ced0ff61bfb3be582d0426d9.cf3845cb.png)

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

![](/assets/cptoken_lookupkey.a4fdda5f033ac9bc65803145af0187498c5a29fec6d8dae8ceb8fb94771598ff.cf3845cb.png)

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


![](/assets/config_token.0d19c72c2bfbc57a48198756674abe5a80f6f4782cc23b744568f79f354be71d.cf3845cb.png)

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


![](/assets/segmentselect.125e8e424498ad8117a756c58875a8ee9d5d7999c778df16ae54e4307c739a18.cf3845cb.png)

1. Add segments to your Profiles API Token.
2. Select **Save**.
![](/assets/use-the-profiles-api-with-facebook-custom-audience-2024-02-08.6d199d43e89e4355f3218d3b5e63a8105d8656d109565e985d922b15621a62e8.cf3845cb.png)


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


![](/assets/image-20190829-000347.ffb085130c7b0a84ff1dd699dc588a7ade40a267fce6e108df1b463b48fd6409.cf3845cb.png)

1. Select Segments.


![](/assets/image-20190829-000239.99622038b8e54f1e82d7b1f7b9c32366541eb8e0fc04ebad62633d6022c68a59.cf3845cb.png)

1. Select Create New.


![](/assets/image-20190829-000032.8506b4d8da21bb63f5ec1f0efb32e8ced4217c77463ef9aa3d4e88688c391c94.cf3845cb.png)

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


![](/assets/image-20190828-235909.ac60440369551b0d5812bc2ca30b343e77ceca43a3538ffcded425dfefc3c6b7.cf3845cb.png)

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


![](/assets/image-20190828-235832.4e81bb76dc62523e0028099ffa009770454c2198700a0a93bda456574ad588f6.cf3845cb.png)

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


![](/assets/image-20190828-235754.08546d531bf44f2c90d77ea2575fca9128f01bcdaaa87ffb6c20842d602c2b89.cf3845cb.png)

## 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](http://developers.marketo.com/javascript-api/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](http://developers.marketo.com/javascript-api/web-personalization/user-context/).
5. Test your code. For example:


![](/assets/image-20191209-220910.f90bb9f2d24e925667372b768bd654cdff3f98db46dc45fdbcd9160f0e2364be.cf3845cb.png)

# Examples

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


```javascript
<!-- 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


```html
<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>
```