Dynamic Configuration and Dynamic Update Endpoints¶
This document describes the capabilities of the React Native SDK for remote configuration, proactive updates, and dynamic update reporting endpoints.
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.
/**
* Listens for remote configuration updates automatically triggered by the native SDK.
* The Promise returned by calling the proactive synchronization method for dynamic configuration 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);
});
Proactive Synchronization of Dynamic Configuration¶
Use FTMobileReactNative to proactively synchronize dynamic configuration. When automatic updates do not meet requirements, you can adjust the update timing by proactively calling this method.
/**
* Proactively updates remote configuration. The call frequency is affected by FTMobileConfig.remoteConfigMiniUpdateInterval.
*/
updateRemoteConfig(): Promise<FTRemoteConfigResult>;
/**
* Proactively updates 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 proactive synchronization update (subject to global minimum interval limit)
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 regular 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 user scenarios based on a fixed key, such as vip_user_id. The server-side corresponding field can return any of the following formats for a match:
- 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 Reporting Endpoints¶
Use FTMobileReactNative to dynamically switch the data reporting endpoint while the SDK is running. After successful setting, 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 Case Description¶
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 reasonably set cache limits based on business scenarios.
/**
* Dynamically sets the Datakit reporting endpoint. After successful setting, the SDK will continue uploading data to the new Datakit address.
*/
setDatakitURL(datakitUrl: string): Promise<void>;
/**
* Dynamically sets the Dataway reporting endpoint and clientToken. After successful setting, 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://openway.guance.com',
'your-client-token',
);
| Method Name | Type | Required | Meaning |
|---|---|---|---|
| setDatakitURL | string | Yes | Dynamically sets the Datakit reporting endpoint. After successful setting, the SDK will continue uploading data to the new Datakit address. |
| setDatawayURL | string, string | Yes | Dynamically sets the Dataway reporting endpoint and clientToken. After successful setting, the SDK will continue uploading data to the new Dataway address. |