Skip to main content

Advanced guide

Last updated 08/27/2026

1. Send events​

After the SDK is initialized, you can start tracking data to collect user behavior. In most cases, regular events meet business needs. You can also use first events, updatable events, and other event types based on your actual business scenarios.

1.1 Regular events​

You can call track to upload events. We recommend setting event properties and the conditions for sending events according to the document you prepared earlier. The following example tracks a user purchasing a product:

let trackEvent = {
accountId: '2222',
distinctId: '1111',
event: 'test_event',
time: new Date(),
ip: '202.38.64.1',
properties: {
prop_double: 134.1,
},
callback(e) {
if (e) {
console.log(e);
}
}
};

teSDK.track(trackEvent)

1.2 First events​

A first event is an event that is recorded only once for a given device or an ID of another dimension. For example, in some scenarios you may want to record the activation event on a device; you can report this data as a first event.

let trackFirstEvent = {
accountId: '2222',
distinctId: '1111',
event: 'test_event',
firstCheckId: 'first_check_id',
time: new Date(),
properties: {
prop_date: new Date(),
prop_double: 134.1,
prop_string: 'hello world',
prop_int: 67,
},
callback(e) {
if (e) {
console.log(e);
}
}
};

teSDK.trackFirst(trackFirstEvent);

Note: Because the first-event check is performed on the server, first events are stored with a 1-hour delay by default.

1.3 Updatable events​

You can use updatable events to modify event data in specific scenarios. An updatable event requires an ID that identifies the event, which you pass in when you create the updatable event object. The AE backend determines which data to update based on the event name and event ID.

let trackUpdateEvent = {
accountId: '2222',
distinctId: '1111',
event: 'test_event',
eventId: 'event_id',
time: new Date(),
properties: {
prop_date: new Date(),
prop_double: 134.1,
prop_string: 'hello world',
prop_int: 67,
},
callback(e) {
if (e) {
console.log(e);
}
}
};

teSDK.trackUpdate(trackUpdateEvent);

1.4 Overwritable events​

Overwritable events are similar to updatable events, except that an overwritable event completely overwrites historical data with the latest data. In effect, the previous record is deleted and the latest data is ingested. The AE backend determines which data to update based on the event name and event ID.

let trackOverwriteEvent = {
accountId: '2222',
distinctId: '1111',
event: 'test_event',
eventId: 'event_id',
time: new Date(),
properties: {
prop_date: new Date(),
prop_double: 134.1,
prop_string: 'hello world',
prop_int: 67,
},
callback(e) {
if (e) {
console.log(e);
}
}
};

teSDK.trackOverWrite(trackOverwriteEvent);

2. User properties​

The user property APIs supported by the AE platform are: userSet, userSetOnce, userAdd,

userUnset、userDel、userAppend、userUniqAppend。

2.1 userSet​

For general user properties, you can call userSet to set them. Properties uploaded through this API overwrite the existing property values. If the user property does not exist yet, it is created with the same type as the value passed in. The following example sets the user name:

let userSetData = {
accountId: 'node_test',
properties: {
prop_date: new Date(),
prop_double: 134.12,
prop_string: 'hello',
prop_int: 666,
prop_array: ['str1', 'str2'],
},
callback(e) {
if (e) {
console.log(e);
}
}
};

teSDK.userSet(userSetData);

2.2 userSetOnce​

If a user property only needs to be set once, you can call userSetOnce to set it. If the property already has a value, this call is ignored. Again, take setting the user name as an example:

teSDK.userSetOnce({
accountId: 'node_test',
properties: {
setOnceProperty: "set_once",
}
});

2.3 userAdd​

To upload a numeric property, you can call userAdd to accumulate it. If the property hasn't been set yet, it is assigned 0 before the calculation. You can pass in a negative value, which is equivalent to subtraction. The following example accumulates the total payment amount:

teSDK.userAdd({
accountId: 'node_test',
properties: {
prop_double: 0.6,
prop_int: 222,
}
});

The property key is a string, and the Value can only be a number.

2.4 userAppend​

You can call userAppend to append elements to an array-type user property.

teSDK.userAppend({
accountId: 'node_test',
properties: {
prop_array: ['str3', 'str4']
}
});

2.5 userUniqAppend​

You can call userUniqAppend to append values to a user property of the array type. userUniqAppend deduplicates the appended user property values, whereas userAppend doesn't, so the user property may contain duplicates.

teSDK.userUniqAppend({
accountId: 'node_test',
properties: {
prop_array: ['str3', 'str4']
}
});

2.6 userUnset​

To clear the value of a user property, you can call userUnset to clear the specified property. If the property hasn't been created in the cluster yet, userUnset doesn't create it

teSDK.userUnset({
accountId: 'node_test',
property: 'set_once_property'
});

UserUnset: the value passed in is the key of the property to be cleared.

2.7 userDel​

To delete a user, you can call userDel. After that, you can no longer query the user's user properties, but the events generated by the user can still be queried. This operation may have irreversible consequences, so use it with caution

teSDK.userDel({
// Account ID (optional)
accountId: "node_test",
// Distinct ID (optional). Account ID and distinct ID cannot both be empty
distinctId: "node_distinct_id"
});

3. Other features​

3.1 BatchMode​

Note

When the data volume is too large or the network is abnormal, data may be lost. We don't recommend using it in the production environment

Transfers data to the AE server in batches in real time, without a transfer tool.

let teSDK = ThinkingData.initWithBatchMode('APP_ID', 'SERVER_URL', {
batchSize: 2,
compress: false // enable compress or not, default true
});

Parameters:

  • APP_ID: The APP ID of your project, which you can find on the project management page in the AE backend

  • SERVER_URL: The URL that data is uploaded to

    • If you use the cloud service, enter: https://global-receiver-ta.thinkingdata.cn
    • If you use an on-premises deployment, bind a domain name to the data collection URL and configure an HTTPS certificate: https://your-domain-for-data-collection
Was this page helpful?