Skip to main content

React Native

Last updated 10/03/2026

This guide shows you how to use the SDK features in React Native.

Latest version: v3.2.1

Update time: 2026-05-14

Downloads: Source code

Note

This document applies to v3.0.0 and later. For earlier versions, see ReactNative Integration Guide (V2)

1. Integrate the SDK​

react-native-thinking-data can be integrated automatically or manually. Automatic integration is recommended

1.1 Automatic integration​

Add react-native-thinking-data to the package.json file

"dependencies": {
"react-native-thinking-data": "3.2.1"
}

2. Initialize the SDK​

The following sample code initializes the SDK:

import TDAnalytics,{TDAutoTrackEventType} from "react-native-thinking-data";
TDAnalytics.init({
appId: "xxx",
serverUrl: "https://xxx"
});

Parameters:

  • appId: The APPID of your project, which you can find on the Project Settings page in the AE backend

  • serverUrl: 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

Android 9.0 and later restrict HTTP requests by default, so make sure you use HTTPS.

3. Common features​

Before you use the common features, we recommend that you read the user identification rules. By default, the SDK generates a random number as the distinct ID and stores it locally. Before a user logs in, the distinct ID is used as the user's identifier. Note: The distinct ID changes when the user reinstalls the app or switches devices.

3.1 Set the account ID​

When a user logs in, you can call login to set the user's account ID. The AE platform uses the account ID as the identifier, and the account ID you set is kept until logout is called. Calling login multiple times overwrites the previous account ID.

TDAnalytics.login("TA")

login can be called multiple times. Each call checks whether the passed account ID is the same as the previously saved ID. If it is the same, the call is ignored; otherwise, the previous ID is overwritten.

This method does not upload a login event

3.2 Set super properties​

Super properties are properties that every event carries. You can call setSuperProperties to set super properties. We recommend setting super properties before you send events. Some important properties, such as a user's membership level and source channel, need to be set in every event; in this case, you can set them as super properties.

TDAnalytics.setSuperProperties({
'channel': 'ta',//String
'age': 1,//Number
'isSuccess': true,//Boolean
'birthday': new Date(),//Time
'object': {
'key': 'value'
},//Object
'object_arr': [
{ 'key': 'value' }
],//Object group
'arr': ['value']//Array
})

Super properties are saved in the cache, so you don't need to call this every time the app starts. If you call setSuperProperties to upload a super property that was set before, the new value overwrites the previous one.

  • Key is the name of the property and is of the string type. It must start with a letter, can contain only digits, letters, and underscores "_", and can be up to 50 characters long. Keys are not case-sensitive; AE converts all letters to lowercase
  • Value is the value of the property. Supported types are string, number, Boolean, time, object, object group, and array

Event properties and user properties have the same requirements as super properties

3.3 Enable auto-tracking​

The following sample code enables auto-tracking of the install, start, and close events. To learn more about auto-tracked events, see Auto-tracking overview

TDAnalytics.enableAutoTrack(TDAutoTrackEventType.APP_START | TDAutoTrackEventType.APP_END | TDAutoTrackEventType.APP_CRASH | TDAutoTrackEventType.APP_INSTALL)

3.4 Send events​

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

TDAnalytics.track({
eventName:"product_buy",
properties:{
'product_name':'Product Name'
}
})

3.5 Set user properties​

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 did not exist before, it is created with the same type as the value passed in. The following example sets the user name:

//username is now TA
TDAnalytics.userSet({ username:"TA"})
//username is now AE
TDAnalytics.userSet({ username:"AE"})

4. Best practices​

The following sample code includes all of the operations above. We recommend using them in the following order:

import TDAnalytics,{TDAutoTrackEventType} from "react-native-thinking-data";
if (isPrivacyPolicyAccepted) // The user has agreed to the Privacy Policy
{
//Initialize the SDK
TDAnalytics.init({appId: "xxx",serverUrl: "https://xxx",});
//Enable auto-tracking
TDAnalytics.enableAutoTrack(TDAutoTrackEventType.APP_START | TDAutoTrackEventType.APP_END | TDAutoTrackEventType.APP_CRASH | TDAutoTrackEventType.APP_INSTALL)
//If the user has logged in, you can set the user's account ID as the unique identifier
TDAnalytics.login("TA")
//After super properties are set, every event carries them
TDAnalytics.setSuperProperties({
'channel': 'ta',//String
'age': 1,//Number
'isSuccess': true,//Boolean
'birthday': new Date(),//Time
'object': {'key': 'value'},//Object
'object_arr': [{ 'key': 'value'}],//Object group
'arr': ['value']//Array
})
//Send an event
TDAnalytics.track({
eventName:"product_buy",
properties:{
'product_name':'Product Name'
}
})
//Set user properties
TDAnalytics.userSet({ username:"TE"})
}
Was this page helpful?