Dynamic Configuration and Dynamic Reporting URL Updates¶
This document describes the remote configuration, manual update, and dynamic reporting URL update capabilities of the React Native SDK.
Dynamic Configuration¶
Prerequisites¶
Dynamic configuration capabilities take effect only when FTMobileConfig.remoteConfiguration = true.
Listen for Remote Configuration Updates¶
After remote configuration is enabled, you can listen for the results of remote configuration updates automatically triggered by the SDK.
/**
* Listen for remote configuration updates automatically triggered by the native SDK.
* Results returned by the Promise of the manual sync methods are not delivered through this event callback.
*/
addRemoteConfigListener(
listener: (result: FTRemoteConfigResult) => void,
): EmitterSubscription;
Example¶
FTMobileReactNative.addRemoteConfigListener((result) => {
console.log('Automatic remote configuration update result:', result);
});
Manually Sync Dynamic Configuration¶
Use FTMobileReactNative to manually sync dynamic configuration. When automatic updates do not meet your needs, you can adjust the update timing by calling these methods manually.
/**
* Actively update the remote configuration. The call frequency is limited by FTMobileConfig.remoteConfigMiniUpdateInterval.
*/
updateRemoteConfig(): Promise<FTRemoteConfigResult>;
/**
* Actively update the remote configuration, ignoring the global minimum update interval.
* If the time since the last update is less than the specified interval, no update is performed.
* @param interval Minimum update interval, in seconds
* @param rules Remote configuration override rules
*/
updateRemoteConfigWithMiniUpdateInterval(
interval: number,
rules?: Array<FTRemoteConfigOverrideRule>,
): Promise<FTRemoteConfigResult>;
Example¶
// Basic manual sync update (limited by the global minimum interval)
FTMobileReactNative.updateRemoteConfig();
const rule: FTRemoteConfigOverrideRule = {
id: 'test_rule',
match: {
customKeys: {
custom_key: 'custom_value',
vip_user_id: {
contains: 'test_user_1001',
},
},
},
override: {
sessionSamplingRate: 100,
traceSamplingRate: 100,
logSamplingRate: 100,
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, exact match is applied; when the value is { contains: value }, contains match is applied.
contains is mainly used to match specific users by a fixed key, such as vip_user_id. A match occurs when the corresponding server-side field is returned in any of the following formats:
- A single string, such as
"test_user_1001" - A JSON array, such as
["test_user_1001", "test_user_1002"] - A JSON string array, such as
"[\"test_user_1001\",\"test_user_1002\"]"
Sampling Override Fields¶
Supported since SDK 0.4.3.
FTRemoteConfigOverrideRule.override supports the following percentage fields. The value range is [0,100], and decimals are allowed. Omitted fields are not modified by the rule.
| Percentage Field | Description | Deprecated Legacy Probability Field ([0,1]) |
|---|---|---|
| sessionSamplingRate | RUM session sampling | rumSampleRate |
| sessionOnErrorSamplingRate | Error session sampling | rumSessionOnErrorSampleRate |
| traceSamplingRate | Trace sampling | traceSampleRate |
| logSamplingRate | Log sampling | logSampleRate |
| sessionReplaySamplingRate | Session Replay sampling | — |
| sessionReplayOnErrorSamplingRate | Session Replay sampling for error scenarios | — |
For example, sessionSamplingRate: 12.5 means 12.5%, 1 means 1%, and 100 means full collection. If both the new and legacy fields are set for the same item, the new field takes precedence, including 0. The example above uses fields supported since SDK 0.4.3; for earlier versions, continue using the corresponding probability fields. The legacy probability fields are deprecated since SDK 0.4.3 and retained for compatibility. For the sampling fields that the server can deliver, see Remote Configuration Fields; — in the table above indicates that the override rule does not provide a corresponding legacy field.
Dynamically Update the Reporting URL¶
Use FTMobileReactNative to dynamically switch the data reporting URL at SDK runtime. After the setting succeeds, subsequent data continues to be uploaded to the new URL.
Dynamic reporting URL updates are supported since SDK 0.4.1. Use either
setDatakitURLorsetDatawayURL, not both. When usingsetDatawayURL, you must also pass the newclientToken.
Use Cases¶
Switch the Reporting URL at Runtime¶
If a reporting URL was configured during initialization and you need to change the data receiving end while the application is running, call setDatakitURL() or setDatawayURL() to update the URL. When using DataWay, you must also pass the clientToken corresponding to the new URL.
Configure the Reporting URL Later¶
Supported since SDK 0.4.3.
FTMobileConfig allows you to leave datakitUrl, datawayUrl, and clientToken empty during initialization, and then supply them later via setDatakitURL() or setDatawayURL(); when using DataWay, clientToken must also be provided. In this case, the SDK performs data collection first but does not upload data.
After you later call FTMobileReactNative.setDatakitURL(...) or FTMobileReactNative.setDatawayURL(..., ...) to dynamically set the reporting URL, the SDK starts consuming the local cache and reporting data.
Note that while no upload URL is set, collected data is still subject to the local cache limits. The cache limits are mainly determined 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 dropped. Therefore, in this mode, it is recommended to supply the upload URL as soon as possible, or to set the cache limits appropriately for your business scenario.
Usage¶
/**
* Dynamically set the Datakit reporting URL. After the setting succeeds, the SDK continues to upload data to the new Datakit URL.
*/
setDatakitURL(datakitUrl: string): Promise<void>;
/**
* Dynamically set the Dataway reporting URL and clientToken. After the setting succeeds, the SDK continues to upload data to the new Dataway URL.
*/
setDatawayURL(datawayUrl: string, clientToken: string): Promise<void>;
Example¶
await FTMobileReactNative.setDatakitURL('http://10.0.0.1:9529');
await FTMobileReactNative.setDatawayURL(
'https://open.dataway.url',
'your-client-token',
);
| Method | Type | Required | Description |
|---|---|---|---|
| setDatakitURL | string | Yes | Dynamically sets the Datakit reporting URL. After the setting succeeds, the SDK continues to upload data to the new Datakit URL. |
| setDatawayURL | string, string | Yes | Dynamically sets the Dataway reporting URL and clientToken. After the setting succeeds, the SDK continues to upload data to the new Dataway URL. |