Advanced guide
1. Initialization parameters
Cocos Creator passes in configuration through TDRemoteConfig.init. Web and mini games use the JS channel. Native Android / iOS / HarmonyOS packages bridge the parameters to the native TDRemoteConfig.
1.1 Configuration options
| Property name | Type | Description |
|---|---|---|
| appId | String | app id of the project created in the AE backend. Required |
| serverUrl | String | server url of the project created in the AE backend. Required |
| debugMode | String | SDK running mode. See 1.2. The native channel only recognizes 'debug' |
| enableLog | Boolean | Whether to enable log printing. Only controls logging and doesn't enter test mode |
| templateCode | String | Template code. Optional |
| customFetchParams | Object | Custom Fetch parameters carried during initialization. Optional |
TDRemoteConfig.init({
appId: 'YOUR-APP-ID',
serverUrl: 'https://your-server-url',
enableLog: true,
debugMode: 'debug',
customFetchParams: { channel: 'cocos' }
});
1.2 SDK running modes
| Value | Description |
|---|---|
| Not passed / other values | Normal mode. Fetches configurations based on online strategies, and the data is stored. |
| debug | Test mode. The device must be added to the test device list in the AE console. The client fetches test strategies at a shorter interval, so you can verify template tests or strategy tests in the AE Engage module. |
| debugOnly | Supported only on the Web / mini game JS channel. Native Android / iOS / HarmonyOS doesn't recognize this value, and the effect is the same as normal mode. |
2. Customize fetch timing
2.1 Automatic fetching
The SDK automatically fetches remote configuration data in the following scenarios.
Web / mini games (JS channel)
- After the SDK is initialized successfully
- The app switches between foreground and background, and more than 6 hours have passed since the last fetch
- The TDAnalytics SDK account system changes, for example, on login or logout
Android / iOS / HarmonyOS (native channel)
After initialization, the native TDRemoteConfig fetches automatically and follows the app lifecycle and account changes. Initialize the analytics SDK first and then Config Center, so that account changes are synced to configuration fetching.
2.2 Manual fetching
Call the SDK method manually to fetch remote configuration at any time. The native channel forwards the call to TDRemoteConfigProxyApi.
TDRemoteConfig.fetch();
// With multiple instances, you can specify appId / templateCode
TDRemoteConfig.fetch(appId, templateCode);
This API has internal rate limiting. Avoid fetching too frequently.
3. Customize Fetch parameters
Fetch parameters are parameters that the client SDK can use when it requests values from the AE server. You can customize Fetch parameters and add them as environment parameters of config channels. You can then use the Fetch parameters to customize the target audience when you configure strategies.
3.1 Add
TDRemoteConfig.setCustomFetchParams({
demo_param: 'from_demo'
}, appId);
3.2 Delete
Delete by the specified key
TDRemoteConfig.removeCustomFetchParam('demo_param', appId);
4. Client Params
Starting from v1.3.1, Cocos Creator supports Client Params. Like Fetch parameters, client parameters can also be used in remote strategy matching. The difference is that client parameters are stored locally on the client and carried by the SDK in requests. The Android / iOS / HarmonyOS native bridges have been updated accordingly.
TDRemoteConfig.addClientParams({
client_tag: 'demo',
client_count: 1
});
TDRemoteConfig.removeClientParam('client_tag');
TDRemoteConfig.accumulateNum('client_count', 1);
const tag = TDRemoteConfig.getClientParamValueForKey('client_tag');
const all = TDRemoteConfig.getClientParams();

