Skip to content

SDK Initialization

This article 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 9529. The device installing the SDK must be able to access this address. Note: Choose one between datakitUrl and datawayUrl
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
clientToken string Yes Authentication token, must be used together with datawayUrl
debug boolean No Sets whether to allow log printing, default false
env string No Environment configuration, default prod, any character, recommended to use a single word, such as test, etc.
envType enum EnvType No Environment configuration, default EnvType.prod. Note: Only one of env and envType needs to be configured
service string No Sets the name of the associated business or service, affecting the service field data in Log and RUM. Default: df_rum_ios, df_rum_android
autoSync boolean No Whether to automatically sync collected data to the server, default 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 not set
enableDataIntegerCompatible boolean No Recommended to enable when coexistence with web data is needed. This configuration handles web data type storage compatibility issues. Enabled by default in versions after 0.3.12
globalContext object No Adds custom tags. Addition rules please refer to here
compressIntakeRequests boolean No Deflate compression for upload sync data, disabled by default
enableLimitWithDbSize boolean No Enable using DB to limit data size, default 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. SDK version 0.3.10 and above supports this parameter
dbCacheLimit number No DB cache limit size. Range [30MB,), default 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 discard new data (default), FTDBCacheDiscard.discardOldest discard old data. SDK version 0.3.10 and above supports this parameter
dataModifier object No Modifies individual fields. Supported in SDK version 0.3.14 and above. Usage examples please see Data Collection Desensitization
lineDataModifier object No Modifies single data entries. Supported in SDK version 0.3.14 and above. Usage examples please see Data Collection Desensitization
enableDataFilter boolean No Whether to enable SDK-side data filtering, including local filtering rules and remote filtering rules. Default true. Supported in SDK version 0.4.2 and above. Usage examples please see Blacklist Filtering
dataFilters Record> No App-locally managed data filtering rules. Supported categories: logging, rum. Supported in SDK version 0.4.2 and above. Rule syntax please see Rule Syntax
remoteConfiguration boolean No Whether to enable the remote configuration function for data collection, disabled by default. When enabled, SDK initialization or app 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 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 configurations. Supported in SDK version 0.3.16 and above. Usage examples please see here

Blacklist Filtering

Data Filter is used to filter RUM and Log data according to rules before the SDK writes to local cache. Data matching the filtering rules will not enter local cache and will not be reported.

  • Local Rules: Configured via FTMobileConfig.dataFilters, issued by the App during SDK initialization.
  • Remote Rules: After enabling FTMobileConfig.enableDataFilter, the SDK will fetch blacklist rules added on the Studio side.

  • Local rules and remote rules take effect simultaneously. Data will be discarded if it matches any rule.

  • Blacklist filtering executes after lineDataModifier and before local cache write. If both lineDataModifier and blacklist filtering are configured, filtering rules will be judged based on the modified data.

Data Filter operates on the SDK data write pipeline. Having too many rules or overly complex regular expressions may affect data write performance. It is recommended to configure only necessary rules.

let config: FTMobileConfig = {
  datawayUrl: datawayUrl,
  clientToken: clientToken,
  enableDataFilter: true,
  dataFilters: {
    logging: [
      "{ `source` in [ 'df_rum_ios_log' , 'df_rum_android_log' ] and `message` match [ 'timeout' ] }",
    ],
    rum: [
      "{ `resource_status` match [ '5..' ] }",
    ],
  },
};

await FTMobileReactNative.sdkConfig(config);

Rule Syntax

The Data Filter rule syntax is largely consistent with the blacklist filtering rules. For complete syntax description, please refer to Blacklist Filtering Rules.

The key of dataFilters represents the data category. Currently the SDK supports:

Category Description
logging Log data
rum RUM data

Each rule is expressed using { condition }. Matching any rule filters data under that category. Rules can use tag and field fields of the data.

Field value formats and operator semantics can refer to the Field Value Format Description and Operator Description in the blacklist filtering rules.

In SDK rule strings, all field values must use array format, and reverse operators are fixed as notin, notmatch.

{ `status` in [ 'debug' ] and `env` notin [ 'prod' ] and `message` notmatch [ '.*error.*' ] }

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 Cache Data

Use FTMobileReactNative to clear unreported cache data.

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

Manually Sync Data

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

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

/**
 * Manually sync data. Needs to be triggered manually when `FTMobileConfig.autoSync = false`.
 */
flushSyncData(): Promise<void>;
FTMobileReactNative.flushSyncData();

Initialization Order Explanation

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 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.

Feedback

Is this page helpful? ×