{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":[]},"redocly_category":"Products","product_name":"Audience Studio","type":"markdown"},"seo":{"title":"Use TD JavaScript SDK to Fetch Profile Segment Ids","description":"Treasure Data Product Documentation · Collect and Unify · Segment and Activate · Experiment and Analyze · Decisioning Automate with AI Scale and Trust.","siteUrl":"https://docs.treasuredata.com","lang":"en-US","llmstxt":{"hide":false,"sections":[{"title":"Table of contents","includeFiles":["**/*"],"excludeFiles":[]}],"excludeFiles":[]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"use-td-javascript-sdk-to-fetch-profile-segment-ids","__idx":0},"children":["Use TD JavaScript SDK to Fetch Profile Segment Ids"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["You can apply the segment IDs in your tools to push highly personalized communications to profiles or control what is shown to profiles in the specified segments. Typically, this requires that you work with our support or services team."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["You add Treasure Data SDK script into your client by including the following:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["API Request"]}]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["audienceToken: List of Profiles API Tokens"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["keys: List of key columns"]}]}]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["API Response"]}]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["values: Object of values, attributes, key, and audienceId"]}]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Your tool (such as Optimizely or Google Chrome Developer Tools) accesses the client to retrieve the segment IDs."]},{"$$mdtype":"Tag","name":"ol","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Copy the tokens that you created and add them to your JS SDK script as follows."]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"html","header":{"controls":{"copy":{}}},"source":"<!-- Treasure Data -->\n<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\",\"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/3.1/td.min.js\";var a=document.getElementsByTagName(\"script\")[0];a.parentNode.insertBefore(o,a)}}(\"Treasure\",this);\n</script>\n<script>\n  var td = new Treasure({...})\n\n  var successCallback = function (values) {\n    /* values format => [... {\n      key: {\n        [key]:value\n      },\n      values: [\"1234\"],\n      attributes: {\n        age: 30\n      },\n\n    } ... ]*/\n    // celebrate();\n  };\n\n  var errorCallback = function (error) {\n    // cry();\n  };\n\n  td.fetchUserSegments({\n    audienceToken: ['YOUR_PROFILES_API_TOKEN_1', 'YOUR_PROFILES_API_TOKEN_2'],\n    keys: {\n      someKey: 'someValue',\n      someOtherKey: 'someOtherValue',\n    }\n  }, successCallback, errorCallback)\n</script>\n","lang":"html"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"example-profile-output","__idx":1},"children":["Example Profile Output"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Here’s the example output with Google Chrome Developer Tools."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":[{"$$mdtype":"Tag","name":"img","attributes":{"src":"/assets/image2021-10-7_12-19-11.608b3a3670317c7c651b93c6431013570fdde76563605ef0d39184a440fe1266.cf3845cb.png","alt":""},"children":[]}]}]},"headings":[{"value":"Use TD JavaScript SDK to Fetch Profile Segment Ids","id":"use-td-javascript-sdk-to-fetch-profile-segment-ids","depth":1},{"value":"Example Profile Output","id":"example-profile-output","depth":2}],"frontmatter":{"seo":{"title":"Use TD JavaScript SDK to Fetch Profile Segment Ids"}},"lastModified":"2026-05-14T07:31:32.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/products/customer-data-platform/audience-studio/profiles/use-td-javascript-sdk-to-fetch-profile-segment-ids","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}