The TD library works by creating an instance per database and sending the data into tables.
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 import only or full access on it, otherwise, you will be unable to send events.
You can send as many events as you like. Each event will fire off asynchronously.
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.
Get your write-only API key.
Log in to Treasure Data and go to your profile. The API key should show up right next to your full-access key.
Install the library. For example, use:
npm install --save td-js-sdk- Initialize using code similar to the following:
var <db_name> = new Treasure({
database: '<db_name>',
writeKey: 'your_write_only_key'
});- Configure an instance for your database by adding a variable similar to the following:
var company = new Treasure({...});- Create a data object with the properties you want to send. For example:
var sale = {
itemId: 101,
saleId: 10,
userId: 1
};- Send the data to a table. For example, send data to a sales table:
company.addRecord('sales', sale);