Skip to main content

HarmonyOS

Last updated 09/03/2026
tip

The HarmonyOS Strategy SDK is integrated as a HAR and requires DevEco Studio 5.0+ and a HarmonyOS API 12+ project environment. Complete the Analytics SDK initialization before integration.

Latest version: v1.0.0

Update time: 2026-07-24

Downloads: Download

1. Overview​

Starting from AE 4.4, the Engage module provides the client-triggered task feature, which supports millisecond-level triggering in in-app scenarios such as new user registration and character creation, as well as real-time A/B splitting. On the client side, the ThinkingData SDK communicates with the AE backend to fetch and evaluate tasks.

Integrate the ThinkingData SDK into your app. On the app side, you only need to handle interactions with the ThinkingData SDK and don't need to care about task details in the AE backend.

2. Integration​

2.1 Integrate the SDK with ohpm​

Run the following command in the root directory of the host project (the directory that contains oh-package.json5):

ohpm install @thinkingdata/strategy

@thinkingdata/analytics and @thinkingdata/remoteconfig are declared in the dependencies of Strategy and are installed automatically with @thinkingdata/strategy, so you don't need to install them separately.

Declare the dependency in the module's oh-package.json5:

"dependencies": {
"@thinkingdata/strategy": "1.0.0"
}

2.2 Integrate the HAR manually​

Client-triggered tasks depend on the following ThinkingData SDKs:

SDK nameDescriptionVersion requirement
TDAnalyticsCollects and processes data1.9.0
TDRemoteConfigFetches configuration from the AE backend1.0.0
TDStrategyProvides client-side triggering1.0.0
  1. Get the HAR packages (TDStrategy.har, TDAnalytics.har, TDRemoteConfig.har)
  2. Put the HARs in the host project (for example, entry/libs/)
  3. Declare the file dependencies in oh-package.json5:
"dependencies": {
"@thinkingdata/strategy": "file:./libs/TDStrategy.har",
"@thinkingdata/analytics": "file:./libs/TDAnalytics.har",
"@thinkingdata/remoteconfig": "file:./libs/TDRemoteConfig.har"
}

3. Initialization​

Initialization order: TDAnalytics.init first, then TDStrategy.init.

Initialize the Analytics SDK:

import { common } from '@kit.AbilityKit';
import { TDAnalytics } from '@thinkingdata/analytics';

const context = getContext(this) as common.UIAbilityContext;
await TDAnalytics.init(context, 'AppId', 'ServerUrl');
TDAnalytics.login('your_client_user_id');

Initialize the Strategy SDK:

import {
TDStrategy,
TDStrategyMode,
TDStrategySettings,
} from '@thinkingdata/strategy';

const settings = new TDStrategySettings('AppId', 'ServerUrl');
settings.mode = TDStrategyMode.NORMAL;
TDStrategy.init(context, settings);

// Actively fetch the latest task configuration (optional)
TDStrategy.fetch();

4. Set a callback listener​

After initializing Analytics and before calling TDStrategy.init, set a callback listener for the TDStrategy SDK.

import {
TDStrategy,
TDStrategyResult,
TDStrategyResultListener,
} from '@thinkingdata/strategy';

const listener: TDStrategyResultListener = {
onTriggerResult: (result: TDStrategyResult) => {
// A task is hit. Handle the push content here
},
};
TDStrategy.setTriggerListener(listener);

4.1 Callback data model​

export class TDStrategyResult {
appId: string;
taskId: string;
channelMsgType: string;
pushId: string;
content: Record<string, Object>;
userParams: Record<string, Object>;
opsProperties: Record<string, Object>;
}

Property description

Property nameTypeDescription
channelMsgTypestringChannel message type
appIdstringThe app id of your AE project
pushIdstringChannel send ID of the operation task
taskIdstringID of the operation task
contentRecord<string, Object>Push content of the operation task
userParamsRecord<string, Object>Custom parameters in the client channel
opsPropertiesRecord<string, Object>Channel information carried by the client-triggered task, used as receipt parameters for touch funnel events
Was this page helpful?