{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":["admonition"]},"redocly_category":"Products","product_name":"Integration Hub","type":"markdown"},"seo":{"title":"Getting Started With Tracking and the TD JavaScript SDK","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":"getting-started-with-tracking-and-the-td-javascript-sdk","__idx":0},"children":["Getting Started With Tracking and the TD JavaScript SDK"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The TD library works by creating an instance per database and sending the data into tables."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["If you're an administrator, databases are automatically be created for you. Otherwise, you'll need to ask an administrator to create the database and grant you ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["import only"]}," or ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["full access"]}," on it, otherwise, you will be unable to send events."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["You can send as many events as you like. Each event will fire off asynchronously."]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/products/customer-data-platform/integration-hub/streaming/td-javascript-sdk/getting-started-with-tracking-and-the-td-javascript-sdk#installing-the-td-javascript-library-and-creating-the-database"},"children":["Installing the TD JavaScript Library and Creating the Database"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/products/customer-data-platform/integration-hub/streaming/td-javascript-sdk/getting-started-with-tracking-and-the-td-javascript-sdk#sending-events"},"children":["Sending Events"]}]}]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"info"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Treasure Data recommends you verify the implementation of any new features or functionality at your site using the Treasure Data JavaScript SDK version 3 before you start using it in production. It manages cookies differently. Be aware when referring to most of these articles that you need to define the suggested event collectors and Treasure Data JavaScript SDK version 3 calls in your solutions.For example, change //cdn.treasuredata.com/sdk/2.5/td.min.js to //cdn.treasuredata.com/sdk/3.0.0/td.min.js."]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"installing-the-td-javascript-library-and-creating-the-database","__idx":1},"children":["Installing the TD JavaScript Library and Creating the Database"]},{"$$mdtype":"Tag","name":"ol","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Get your write-only API key."]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Log in to Treasure Data and go to your profile. The API key should show up right next to your full-access key."]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Install the library. For example, use:"]}]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"npm install --save td-js-sdk\n","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"ol","attributes":{"start":4},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Initialize using code similar to the following:"]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"javascript","header":{"controls":{"copy":{}}},"source":"var <db_name> = new Treasure({\n  database: '<db_name>',\n  writeKey: 'your_write_only_key'\n});\n","lang":"javascript"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"sending-events","__idx":2},"children":["Sending Events"]},{"$$mdtype":"Tag","name":"ol","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Configure an instance for your database by adding a variable similar to the following:"]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"javascript","header":{"controls":{"copy":{}}},"source":"var company = new Treasure({...});\n","lang":"javascript"},"children":[]},{"$$mdtype":"Tag","name":"ol","attributes":{"start":2},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Create a data object with the properties you want to send. For example:"]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"javascript","header":{"controls":{"copy":{}}},"source":"var sale = {\n  itemId: 101,\n  saleId: 10,\n  userId: 1\n};\n","lang":"javascript"},"children":[]},{"$$mdtype":"Tag","name":"ol","attributes":{"start":3},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Send the data to a table. For example, send data to a sales table:"]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"javascript","header":{"controls":{"copy":{}}},"source":"company.addRecord('sales', sale);\n","lang":"javascript"},"children":[]}]},"headings":[{"value":"Getting Started With Tracking and the TD JavaScript SDK","id":"getting-started-with-tracking-and-the-td-javascript-sdk","depth":1},{"value":"Installing the TD JavaScript Library and Creating the Database","id":"installing-the-td-javascript-library-and-creating-the-database","depth":1},{"value":"Sending Events","id":"sending-events","depth":1}],"frontmatter":{"seo":{"title":"Getting Started With Tracking and the TD JavaScript SDK"}},"lastModified":"2026-05-14T07:31:32.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/products/customer-data-platform/integration-hub/streaming/td-javascript-sdk/getting-started-with-tracking-and-the-td-javascript-sdk","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}