Dynamic Configuration and Dynamic Update Endpoints¶
This document describes the capabilities for remote configuration, proactive updates, and dynamic endpoint updates for the React Native SDK.
Dynamic Configuration¶
Prerequisites¶
Dynamic configuration capabilities only take effect when FTMobileConfig.remoteConfiguration = true.
Listening for Remote Configuration Updates¶
After enabling remote configuration, you can listen for remote configuration update results automatically triggered by the SDK.
/**
* Listen for remote configuration updates automatically triggered by the native SDK.
* The Promise returned by calling the manual sync dynamic configuration method will not be returned via this event callback.
*/
addRemoteConfigListener(
listener: (result: FTRemoteConfigResult) => void,
): EmitterSubscription;
Usage Example¶
FTMobileReactNative.addRemoteConfigListener((result) => {
console.log('Automatic remote configuration update result:', result);
});
Manual Sync Dynamic Configuration¶
Use FTMobileReactNative to manually sync dynamic configuration. When automatic updates do not meet requirements, you can adjust the update timing by calling this method proactively.
/**
* Proactively update remote configuration. The call frequency is affected by FTMobileConfig.remoteConfigMiniUpdateInterval.
*/
updateRemoteConfig(): Promise<FTRemoteConfigResult>;
/**
* Proactively update remote configuration, ignoring the global minimum update interval configuration.
* If the time since the last update is less than the specified interval, the update operation will not be performed.
* @param interval Minimum update interval, unit: seconds
* @param rules Remote configuration override rules
*/
updateRemoteConfigWithMiniUpdateInterval(
interval: number,
rules?: Array<FTRemoteConfigOverrideRule>,
): Promise<FTRemoteConfigResult>;
Usage Example¶
// Basic manual sync update (subject to global minimum interval restriction)
FTMobileReactNative.updateRemoteConfig();
const rule: FTRemoteConfigOverrideRule = {
id: 'test_rule',
match: {
customKeys: {
custom_key: 'custom_value',
vip_user_id: {
contains: 'test_user_1001',
},
},
},
override: {
rumSampleRate: 1,
traceSampleRate: 1,
logSampleRate: 1,
logLevelFilters: ['info', 'warn'],
},
};
const result = await FTMobileReactNative.updateRemoteConfigWithMiniUpdateInterval(0, [rule]);
console.log('updateRemoteConfigWithMiniUpdateInterval result ', result);
FTMobileReactNative.updateRemoteConfigWithMiniUpdateInterval(0, null);
When the value of customKeys is a plain value, it is treated as an exact match; when the value is { contains: value }, it is treated as a contains match.
contains is mainly suitable for matching specified users by a fixed key, such as vip_user_id. The corresponding field on the server side can match if it returns any of the following formats:
- A single string, e.g.,
"test_user_1001" - A JSON array, e.g.,
["test_user_1001", "test_user_1002"] - A JSON string array, e.g.,
"[\"test_user_1001\",\"test_user_1002\"]"
Dynamic Update Endpoints¶
Use FTMobileReactNative to dynamically switch the data reporting endpoint while the SDK is running. After successful setup, subsequent data will continue to be uploaded to the new address.
Supported in React Native SDK >= 0.4.1. Use either
setDatakitURLorsetDatawayURL. When usingsetDatawayURL, a newclientTokenmust also be provided.
Use Cases Explanation¶
FTMobileConfig supports initialization without passing datakitUrl or datawayUrl. In this scenario, the SDK will perform data collection first but will not upload it.
When FTMobileReactNative.setDatakitURL(...) or FTMobileReactNative.setDatawayURL(..., ...) is subsequently called to dynamically set the reporting endpoint, the SDK will start consuming the local cache and perform data reporting.
It is important to note that data collected during the period when no upload address is set is still subject to local cache limits. The cache limit is primarily affected by the following configurations:
FTLogConfig.logCacheLimitCountFTRUMConfig.rumCacheLimitCount- The database cache limit corresponding to
FTMobileConfig.enableLimitWithDbSize
If the cache reaches its limit, data beyond the limit may be discarded. Therefore, it is recommended to promptly provide an upload address in this mode, or set cache limits appropriately based on business scenarios.
/**
* Dynamically set the Datakit reporting endpoint. After successful setup, the SDK will continue uploading data to the new Datakit address.
*/
setDatakitURL(datakitUrl: string): Promise<void>;
/**
* Dynamically set the Dataway reporting endpoint and clientToken. After successful setup, the SDK will continue uploading data to the new Dataway address.
*/
setDatawayURL(datawayUrl: string, clientToken: string): Promise<void>;
Usage Example¶
await FTMobileReactNative.setDatakitURL('http://10.0.0.1:9529');
await FTMobileReactNative.setDatawayURL(
'https://open.dataway.url',
'your-client-token',
);
| Method Name | Type | Required | Meaning |
|---|---|---|---|
| setDatakitURL | string | Yes | Dynamically set the Datakit reporting endpoint. After successful setup, the SDK will continue uploading data to the new Datakit address. |
| setDatawayURL | string, string | Yes | Dynamically set the Dataway reporting endpoint and clientToken. After successful setup, the SDK will continue uploading data to the new Dataway address. |