Skip to main content

OpenHarmony

Last updated 10/05/2026
tip

Before you integrate the SDK, read Pre-integration preparation.

The SDK requires a minimum system version of API 10

The SDK (har format) is about 56 KB in size

SDK name: ThinkingData SDK

Developer: 数数信息科技(上海)有限公司

Version: 2.0.0

Features: The SDK collects client logs in the form of events and user properties, and supports analysis of daily active users, usage duration, retention, and other behaviors.

Privacy statement: ThinkingData SDK Privacy Statement

Compliance guide: ThinkingData SDK Compliance Guide

Latest version: 2.0.0

Downloads: SDK download

SDK package name: @thinkingdata/analytics

MD5 value: 997d05310dbe82eb02b1536deeb4645f

Update time: 2026-08-19

1. Integrate the SDK​

  1. Import the SDK
  • Run the following commands
ohpm i @thinkingdata/analytics
  • Manually add the dependency under dependencies in oh-package.json5. The IDE then prompts you to run ohpm install. Click to install.
"dependencies": {
"@thinkingdata/analytics": "2.0.0",
}

2. Initialization​

import { TDAnalytics, TDConfig, TDMode } from '@thinkingdata/analytics';

//Method 1
TDAnalytics.init(context, "appId", "serverUrl")

//Method 2
let config = new TDConfig()
config.appId = 'appId'
config.serverUrl = 'serverUrl'
config.mode = TDMode.NORMAL
config.enableAutoCalibrated = true
TDAnalytics.initWithConfig(context, config)

When the SDK is initialized, it collects information such as the OS version, device manufacturer, operating system, screen resolution, device model, APP version, network status, network carrier, app install time, and system language for statistical analysis.

Parameters:

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

  • SERVER_URL: The URL that data is uploaded to

    • If you use the cloud service, view the Data Receiving URL in Project Settings -> Implementation.
    • If you use an on-premises deployment, you can customize the data collection URL.
  • mode: The SDK reporting mode. The default is Normal mode.

  • enableAutoCalibrated: Automatically enables time calibration.

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.

// The unique login identifier of the user, which corresponds to #account_id in the reported data. In this case, the value of #account_id is TA
TDAnalytics.login("TA");

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.

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

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.

3.3 Enable auto-tracking​

We recommend calling enableAutoTrack after onWindowStageCreate. The following sample code enables all auto-tracked events:

//APP install event TDAutoTrackEventType.APP_INSTALL
//APP start event TDAutoTrackEventType.APP_START
//APP end event TDAutoTrackEventType.APP_END
//APP view page event TDAutoTrackEventType.APP_VIEW_SCREEN
//APP control click event TDAutoTrackEventType.APP_CLICK
//APP crash event TDAutoTrackEventType.APP_CRASH
TDAnalytics.enableAutoTrack(context,TDAutoTrackEventType.APP_START | TDAutoTrackEventType.APP_INSTALL | TDAutoTrackEventType.APP_END | TDAutoTrackEventType.APP_VIEW_SCREEN | TDAutoTrackEventType.APP_CLICK | TDAutoTrackEventType.APP_CRASH)

3.4 Send events​

You can call track to upload events. We recommend setting event properties 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"
}
})

The event name is of the string type. It must start with a letter and can contain digits, letters, and underscores "_".

3.5 Set user properties​

For general user properties, you can call userSet to set them. Properties uploaded through this API overwrite the original property values. If the user property doesn't exist yet, a new user property is created with the same type as the value passed in. The following example sets the username:

// username is TA
TDAnalytics.userSet({
properties: {
username: "TA"
}
})
//username is AE
TDAnalytics.userSet({
properties: {
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, TDConfig, TDMode, TDAutoTrackEventType } from '@thinkingdata/analytics';
let config = new TDConfig()
config.appId = 'appId'
config.serverUrl = 'serverUrl'
config.enableAutoCalibrated = true
config.mode = TDMode.NORMAL
// Initialize
TDAnalytics.initWithConfig(context, config)
//Enable auto-tracking
TDAnalytics.enableAutoTrack(context,TDAutoTrackEventType.APP_START | TDAutoTrackEventType.APP_INSTALL | TDAutoTrackEventType.APP_END | TDAutoTrackEventType.APP_VIEW_SCREEN | TDAutoTrackEventType.APP_CLICK | TDAutoTrackEventType.APP_CRASH)
// The unique login identifier of the user, which corresponds to #account_id in the reported data. In this case, the value of #account_id is TA
TDAnalytics.login("TA");
//Set super properties
let superProperties = {
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
};
TDAnalytics.setSuperProperties(superProperties);
//Send an event
TDAnalytics.track({
eventName: "product_buy", // Event name
properties: {
product_name: "Product Name"
} //Event properties
});
//Set user properties
TDAnalytics.userSet({
properties: {
username: "AE"
}
});
Was this page helpful?