SDK Initialization¶
This document covers the initialization and runtime capabilities of the React Native SDK.
Import SDK¶
Now in your code, you can use:
import {
FTMobileReactNative,
FTReactNativeLog,
FTReactNativeTrace,
FTReactNativeRUM,
FTMobileConfig,
FTLogConfig,
FTTraceConfig,
FTRUMConfig,
ErrorMonitorType,
DeviceMetricsMonitorType,
DetectFrequency,
TraceType,
FTLogStatus,
EnvType,
} from '@cloudcare/react-native-mobile';
Basic Configuration¶
// Local environment deployment, Datakit deployment
let config: FTMobileConfig = {
datakitUrl: datakitUrl,
};
// Using public DataWay
let config: FTMobileConfig = {
datawayUrl: datawayUrl,
clientToken: clientToken,
};
await FTMobileReactNative.sdkConfig(config);
| Field | Type | Required | Description |
|---|---|---|---|
| datakitUrl | string | Yes | Local environment deployment (Datakit) reporting URL address, example: http://10.0.0.1:9529, default port is 9529. The device installing the SDK must be able to access this address. Note: Choose one between datakitUrl and datawayUrl configuration. |
| datawayUrl | string | Yes | Public Dataway reporting URL address, obtained from the [RUM] application, example: https://open.dataway.url. The device installing the SDK must be able to access this address. Note: Choose one between datakitUrl and datawayUrl configuration. |
| clientToken | string | Yes | Authentication token, must be used together with datawayUrl. |
| debug | boolean | No | Sets whether to allow log printing, default is false. |
| env | string | No | Environment configuration, default is prod. Any string, recommended to use a single word, such as test, etc. |
| envType | enum EnvType | No | Environment configuration, default is EnvType.prod. Note: Only one of env or envType needs to be configured. |
| service | string | No | Sets the name of the business or service it belongs to, affecting the service field data in Log and RUM. Default: df_rum_ios, df_rum_android. |
| autoSync | boolean | No | Whether to automatically sync data to the server after collection, default is true. When false, use FTMobileReactNative.flushSyncData() to manage data synchronization manually. |
| syncPageSize | number | No | Sets the number of entries per sync request. Range [5,). Note: Larger request entry count means data synchronization consumes more computing resources. |
| syncSleepTime | number | No | Sets the sync interval time. Range [0,5000], default is not set. |
| enableDataIntegerCompatible | boolean | No | Recommended to enable when needing to coexist with web data. This configuration handles web data type storage compatibility issues. Enabled by default in versions after 0.3.12. |
| globalContext | object | No | Adds custom tags. For addition rules, please refer to here. |
| compressIntakeRequests | boolean | No | Compresses upload synchronization data with deflate, disabled by default. |
| enableLimitWithDbSize | boolean | No | Enables using DB to limit data size, default is 100MB, unit Byte. Larger database increases disk pressure, disabled by default. Note: After enabling, the Log configuration logCacheLimitCount and RUM configuration rumCacheLimitCount will become invalid. Supported in SDK version 0.3.10 and above. |
| dbCacheLimit | number | No | DB cache size limit. Range [30MB,), default is 100MB, unit byte. Supported in SDK version 0.3.10 and above. |
| dbDiscardStrategy | string | No | Sets data discard rules in the database. Discard strategies: FTDBCacheDiscard.discard discards new data (default), FTDBCacheDiscard.discardOldest discards old data. Supported in SDK version 0.3.10 and above. |
| dataModifier | object | No | Modifies individual fields. Supported in SDK version 0.3.14 and above. For usage examples, see Data Collection Desensitization. |
| lineDataModifier | object | No | Modifies single data entries. Supported in SDK version 0.3.14 and above. For usage examples, see Data Collection Desensitization. |
| remoteConfiguration | boolean | No | Whether to enable the remote configuration function for data collection, disabled by default. When enabled, SDK initialization or application hot start triggers data updates. Supported in SDK version 0.3.16 and above. Configurable parameters. |
| remoteConfigMiniUpdateInterval | number | No | Sets the minimum update interval for remote dynamic configuration, unit seconds, default is 12 hours. Supported in SDK version 0.3.16 and above. |
| remoteConfigOverrideRules | Array |
No | Sets remote configuration override rules, allowing custom adjustments before applying remote configuration. Supported in SDK version 0.3.16 and above. For usage examples, see here. |
User Information Binding and Unbinding¶
Usage¶
/**
* Binds a user.
* @param userId User ID.
* @param userName User name.
* @param userEmail User email.
* @param extra Additional user information.
*/
bindRUMUserData(userId: string, userName?: string, userEmail?: string, extra?: object): Promise<void>;
/**
* Unbinds a user.
*/
unbindRUMUserData(): Promise<void>;
Example¶
import { FTMobileReactNative } from '@cloudcare/react-native-mobile';
FTMobileReactNative.bindRUMUserData('react-native-user', 'user_name');
FTMobileReactNative.unbindRUMUserData();
Runtime Capabilities¶
Shutting Down the SDK¶
Use FTMobileReactNative to shut down the SDK.
Clearing SDK Cached Data¶
Use FTMobileReactNative to clear cached data that has not been reported.
/**
* Clears all data that has not yet been uploaded to the server.
*/
clearAllData(): Promise<void>;
Manually Syncing Data¶
When FTMobileConfig.autoSync is configured as true, no additional action is needed; the SDK syncs automatically.
When FTMobileConfig.autoSync is configured as false, manual data synchronization must be triggered.
/**
* Manually syncs data. Required when `FTMobileConfig.autoSync = false` is configured.
*/
flushSyncData(): Promise<void>;
Initialization Sequence Instructions¶
Please complete SDK initialization before registering the App in the top-level index.js file to ensure the SDK is fully ready before calling other SDK methods.
After completing the basic configuration, proceed with RUM, Log, and Trace configurations.
import App from './App';
async function sdkInit() {
await FTMobileReactNative.sdkConfig(config);
await FTReactNativeRUM.setConfig(rumConfig);
// ...
}
sdkInit();
AppRegistry.registerComponent('main', () => App);
Dynamic Configuration¶
Dynamic configuration related capabilities have been separated into Dynamic Configuration.