Skip to content

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 character, it is 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 and 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 synchronize 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 for synchronization requests. Range [5,). Note: A larger number of request entries means data synchronization occupies more computing resources
syncSleepTime number No Sets the synchronization interval time. Range [0,5000], default is not set
enableDataIntegerCompatible boolean No Recommended to enable when coexistence with web data is required. This configuration is used to handle 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 Deflate compression for uploaded synchronization data, disabled by default
enableLimitWithDbSize boolean No Enables using DB to limit data size, default is 100MB, unit Byte, larger database means greater disk pressure, disabled by default. Note: After enabling, the Log configuration logCacheLimitCount and RUM configuration rumCacheLimitCount will become invalid. SDK version 0.3.10 and above supports this parameter
dbCacheLimit number No DB cache limit size. Range [30MB,), default is 100MB, unit byte, SDK version 0.3.10 and above supports this parameter
dbDiscardStrategy string No Sets the data discard rule in the database. Discard strategies: FTDBCacheDiscard.discard discards new data (default), FTDBCacheDiscard.discardOldest discards old data. SDK version 0.3.10 and above supports this parameter
dataModifier object No Modifies a single field. Supported in SDK version 0.3.14 and above, for usage examples, see Data Collection Desensitization
lineDataModifier object No Modifies a single piece of data. 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 will trigger data updates. Supported in SDK version 0.3.16 and above
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

User Information Binding and Unbinding

Usage

/**
 * Bind user.
 * @param userId User ID.
 * @param userName User name.
 * @param userEmail User email.
 * @param extra User's extra information.
 */
bindRUMUserData(userId: string, userName?: string, userEmail?: string, extra?: object): Promise<void>;

/**
 * Unbind user.
 */
unbindRUMUserData(): Promise<void>;

Example

import { FTMobileReactNative } from '@cloudcare/react-native-mobile';

FTMobileReactNative.bindRUMUserData('react-native-user', 'user_name');

FTMobileReactNative.unbindRUMUserData();

Runtime Capabilities

Shut Down SDK

Use FTMobileReactNative to shut down the SDK.

/**
 * Shut down running objects within the SDK.
 */
shutDown(): Promise<void>;
FTMobileReactNative.shutDown();

Clear SDK Cached Data

Use FTMobileReactNative to clear cached data that has not been reported.

/**
 * Clear all data that has not yet been uploaded to the server.
 */
clearAllData(): Promise<void>;
FTMobileReactNative.clearAllData();

Actively Synchronize Data

When FTMobileConfig.autoSync is configured as true, no additional operation is needed, the SDK will synchronize automatically.

When FTMobileConfig.autoSync is configured as false, data synchronization needs to be triggered actively.

/**
 * Actively synchronize data, needs to be triggered actively when `FTMobileConfig.autoSync = false` is configured.
 */
flushSyncData(): Promise<void>;
FTMobileReactNative.flushSyncData();

Initialization Order 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, Trace configuration.

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.