Skip to content

RUM Configuration

RUM Initialization Configuration

let rumConfig: FTRUMConfig = {
  androidAppId: Config.ANDROID_APP_ID,
  iOSAppId: Config.IOS_APP_ID,
  enableAutoTrackUserAction: true,
  enableAutoTrackError: true,
  enableNativeUserAction: true,
  enableNativeUserView: false,
  enableNativeUserResource: true,
  enableIOSWebSocketResource: true,
  sessionSamplingRate: 100,
  errorMonitorType: ErrorMonitorType.all,
  deviceMonitorType: DeviceMetricsMonitorType.all,
  detectFrequency: DetectFrequency.rare,
  enableLongTask: true,
  longTaskThresholdMs: 200,
};

await FTReactNativeRUM.setConfig(rumConfig);
Field Type Required Description
androidAppId string Yes app_id, applied for in the RUM console
iOSAppId string Yes app_id, applied for in the RUM console
sessionSamplingRate number No RUM session sampling percentage, range [0,100], decimal values supported, default 100; 0 means no collection, 100 means full collection. Takes precedence over sampleRate. Supported since SDK 0.4.3.
sessionOnErrorSamplingRate number No Error session sampling percentage when not selected by regular session sampling, range [0,100], decimal values supported, default 0; takes precedence over sessionOnErrorSampleRate. Supported since SDK 0.4.3.
visitorIdConfig FTVisitorIdConfig No Supported since SDK 0.4.3. Anonymous visitor identification configuration, disabled by default. See Visitor ID
sampleRate number No Deprecated since SDK 0.4.3, retained for compatibility. Use sessionSamplingRate instead; value range [0,1], 0 means no collection, 1 means full collection, default 1. Applies to all View, Action, LongTask, and Error data under the same session_id
sessionOnErrorSampleRate number No Deprecated since SDK 0.4.3, retained for compatibility. Use sessionOnErrorSamplingRate instead; when a session is not selected by regular session sampling, if an error occurs during the session, data from the 1 minute before the error can be collected, value range [0,1], 0 means no collection, 1 means full collection, default 0. Applies to all View, Action, LongTask, and Error data under the same session_id. Supported in SDK 0.3.14 and later
enableAutoTrackUserAction boolean No Whether to automatically collect React Native component click events. When enabled, actionName can be set with accessibilityLabel. Since SDK 0.4.3, you can use the Babel plugin to automatically generate Action names
enableAutoTrackError boolean No Whether to automatically collect React Native Errors, default false
enableNativeUserAction boolean No Whether to track Native Action, native Button click events, and app launch events, default false
enableNativeUserView boolean No Whether to automatically track Native View. For pure React Native apps, it is recommended to disable this. Default false
enableNativeUserResource boolean No Whether to enable automatic native HTTP(S) Resource tracking. Android WebSocket handshakes are also controlled by this field. Default false; for iOS WebSocket handshakes, enable enableIOSWebSocketResource separately
enableIOSWebSocketResource boolean No Supported since SDK 0.4.3. Collects iOS React Native WebSocket handshake Resources, default false, independent of enableNativeUserResource. See WebSocket handshake collection
errorMonitorType enum ErrorMonitorType No Sets auxiliary monitoring information and adds additional monitoring data to RUM Error data. Disabled by default
deviceMonitorType enum DeviceMetricsMonitorType No Adds monitoring data during the View lifecycle. Disabled by default
detectFrequency enum DetectFrequency No View performance monitoring sampling interval, default DetectFrequency.normal
enableResourceHostIP boolean No Whether to collect the IP of the requested target domain name. Scope: only affects default collection when enableNativeUserResource = true. iOS: supported on >= iOS 13; Android: IP caching mechanism exists for the same OkhttpClient
globalContext object No Adds custom tags for distinguishing RUM data sources. If you need to use the tracing feature, set the parameter key to track_id and value to any numeric value. For notes on adding rules, see here
enableTrackNativeCrash boolean No Whether to enable Android Java Crash and OC/C/C++ crash monitoring, default false
enableTrackNativeAppANR boolean No Whether to enable Native ANR monitoring, default false
enableTrackNativeFreeze boolean No Whether to collect Native Freeze, default false
nativeFreezeDurationMs number No Sets the Native Freeze lag threshold, value range [100,), unit milliseconds. Default 250 ms on iOS and 1000 ms on Android
enableLongTask boolean No Whether to enable React Native JS LongTask monitoring, default false. This configuration only collects JS thread lag and is independent of Native Freeze monitoring. Supported since SDK 0.4.3
longTaskThresholdMs number No Sets the React Native JS LongTask monitoring threshold, value range [100, 5000], unit milliseconds, default 100 ms. Only takes effect when enableLongTask = true; values below 100 are treated as 100, and values above 5000 are treated as 5000. Supported since SDK 0.4.3
rumDiscardStrategy string No Discard strategy: FTRUMCacheDiscard.discard discards new data (default), FTRUMCacheDiscard.discardOldest discards old data
rumCacheLimitCount number No Maximum number of locally cached RUM entries [10_000,), default 100_000
enableTraceWebView boolean No Whether to enable WebView data collection, default true. Supported in SDK 0.3.16 and later
allowWebViewHost Array / null No Sets the WebView host addresses allowed for data tracking. null allows all hosts, [] disallows all hosts. Supported since SDK 0.3.16; since SDK 0.4.3, FTMobileConfig.allowWebViewHost is recommended. This field is retained for compatibility and takes effect only when the basic configuration is not set. See WebView host configuration
iosCrashMonitoringType enum IOSCrashMonitoringType No Configures the type range of SDK crash monitoring, default IOSCrashMonitoringType.highCompatibility. Supported in SDK 0.3.16 and later
About React Native JS LongTask

When enabled, the SDK monitors the interval between adjacent frames on the React Native JS thread and reports a LongTask when the full frame interval is strictly greater than longTaskThresholdMs. The current version does not collect JS call stacks.

Sampling Configuration

Decimal percentage sampling is supported since SDK 0.4.3.

Use the new fields. sessionSamplingRate: 12.5 means collecting 12.5% of sessions; sessionSamplingRate: 1 means 1%, and 100 means full collection.

When both the new and old fields are configured for the same item, the new field takes precedence, including when it is explicitly set to 0. The old fields retain the [0,1] meaning; do not copy old values directly to the new fields. Error session sampling applies to sessions not selected by regular session sampling, and when an error occurs, data from the 1 minute before the error can be collected.

The old fields are deprecated since SDK 0.4.3 and retained for compatibility. After upgrading, set the new fields to the percentage you actually need. For example, migrate a full-collection configuration as follows:

 const rumConfig: FTRUMConfig = {
   androidAppId: 'YOUR_ANDROID_APP_ID',
   iOSAppId: 'YOUR_IOS_APP_ID',
-  sampleRate: 1,
+  sessionSamplingRate: 100,
 };

Log, Trace, Session Replay, and remote configuration override rules also support the corresponding percentage fields.

RUM User Data Tracking

FTRUMConfig can implement automatic collection through configurations such as enableAutoTrackUserAction, enableAutoTrackError, enableNativeUserAction, enableNativeUserView, and enableNativeUserResource; if manual collection is required, you can also use the following APIs.

View

When initializing the SDK with RUM configuration, you can configure enableNativeUserView to enable automatic collection of Native View. Because React Native provides a wide range of libraries for creating screen navigation, React Native View only supports manual collection by default; if you need to automatically collect React Native View, continue reading "Automatically Collect React Native View" below.

Usage

/**
 * View loading duration, in nanoseconds.
 */
onCreateView(viewName: string, loadTime: number): Promise<void>;

/**
 * View starts.
 */
startView(viewName: string, property?: object): Promise<void>;

/**
 * View ends.
 */
stopView(property?: object): Promise<void>;

Example

import { FTReactNativeRUM } from '@cloudcare/react-native-mobile';
FTReactNativeRUM.onCreateView('viewName', duration);

FTReactNativeRUM.startView('viewName', { 'custom.foo': 'something' });

FTReactNativeRUM.stopView({ 'custom.foo': 'something' });

Update the Loading Time of the Current View

Supported since SDK 0.4.3.

Call after startView() and before stopView():

await FTReactNativeRUM.updateViewLoadingTime(25_500_000); // 25.5 ms

duration is the time calculated from the business loading start and end boundaries, in nanoseconds, and must be a non-negative safe integer. It is recommended to use a monotonic clock to calculate elapsed time; millisecond values must be multiplied by 1_000_000 and rounded. The call replaces the current View's loading time; passing 0 clears it. This method only updates the currently active View and does not support specifying other Views.

Automatically Collect React Native View

An optional navigation plugin is available since SDK 0.4.3.

Choose a plugin based on the navigation library you actually use and keep it at the same version as the main SDK; the plugin contains only JavaScript and type declarations and does not add native linking configuration. Complete SDK and RUM initialization first; for pure React Native pages, it is recommended to set enableNativeUserView: false.

If you previously copied the navigation collection file from the example, import the class with the same name from the plugin instead, and remove the old collection logic to avoid duplicate reporting. Use only one automatic navigation collection method at a time. The plugin cooperates with native code to end the View when the app enters the background, and restarts the current page when the app returns to the foreground, without reusing the previous loading time.

react-native-navigation
yarn add @cloudcare/mobile-react-native-navigation@0.4.3

When migrating from the old example file, replace the import path of the collection class:

- import { FTRumReactNativeNavigationTracking } from './FTRumReactNativeNavigationTracking';
+ import { FTRumReactNativeNavigationTracking } from '@cloudcare/mobile-react-native-navigation';

Enable collection before displaying the navigation root page:

import { FTRumReactNativeNavigationTracking } from '@cloudcare/mobile-react-native-navigation';
// Call after SDK and RUM initialization is complete and before Navigation.setRoot().
FTRumReactNativeNavigationTracking.startTracking();

Call FTRumReactNativeNavigationTracking.stopTracking() before unmounting the navigation integration or closing the SDK.

The plugin collects page appear and disappear events. The loading time is the interval from componentWillAppear to componentDidAppear, in nanoseconds, and does not mean that all asynchronous content on the page has finished loading. When the navigation library does not provide a will-appear callback, the start point is missing, or the duration is not positive, only the View is collected, and no loading time is fabricated.

react-navigation
yarn add @cloudcare/mobile-react-navigation@0.4.3

When migrating from the old example file, replace the import path of the collection class; keep the navigation library import unchanged:

- import { FTRumReactNavigationTracking } from './FTRumReactNavigationTracking';
+ import { FTRumReactNavigationTracking } from '@cloudcare/mobile-react-navigation';
import { createNativeStackNavigator } from '@react-navigation/native-stack';

Routing mode applies to regular routes, nested navigation, and Tabs: it records the current leaf route when the container is ready, and then tracks route changes; this mode does not collect loading time.

import { NavigationContainer, createNavigationContainerRef } from '@react-navigation/native';
import { FTRumReactNavigationTracking } from '@cloudcare/mobile-react-navigation';
const navigationRef = createNavigationContainerRef();

<NavigationContainer
  ref={navigationRef}
  onReady={() => FTRumReactNavigationTracking.startTrackingViews(navigationRef)}
>
  {/* The project's navigation component */}
</NavigationContainer>;

Call FTRumReactNavigationTracking.stopTrackingViews(navigationRef) before the container is unmounted or the SDK is closed.

Transition mode applies to @react-navigation/native-stack and is an alternative to routing mode. Configure it on the Stack responsible for page transitions:

import { FTRumReactNavigationTracking } from '@cloudcare/mobile-react-navigation';
<Stack.Navigator screenListeners={FTRumReactNavigationTracking.StackListener}>
  {/* The project's Stack.Screen */}
</Stack.Navigator>;

The Stack above uses the instance created by createNativeStackNavigator() in the project. Call FTRumReactNavigationTracking.stopTrackingViews() before the Stack is unmounted or the SDK is closed. When remounting, obtain StackListener again; do not continue using a listener object that has been cleaned up.

The loading time is the observed monotonic time interval from focus to the corresponding open transition transitionEnd, in nanoseconds, and does not mean that the network or all content has finished loading. It is collected only for the first display of a new page instance; returning to an existing page, switching Tabs, and foreground restoration do not restart timing. When the start point is missing or the duration is not positive, no loading data is attached. Do not register repeatedly at every level of nested navigation.

Expo Router

If you are using Expo Router, add the following method in the app/_layout.js file for data collection.

import { useEffect } from 'react';
import { useSegments, usePathname, Slot } from 'expo-router';
import { FTReactNativeRUM } from '@cloudcare/react-native-mobile';
export default function Layout() {
  const pathname = usePathname();
  const segments = useSegments();
  const viewKey = segments.join('/');

  useEffect(() => {
    FTReactNativeRUM.startView(viewKey);
  }, [viewKey, pathname]);

  return <Slot />;
}

Action

Differences between startAction and addAction
  • startAction automatically calculates Action duration internally. During calculation, it associates with nearby Resource, LongTask, and Error data as much as possible, and has a 100 ms frequent-trigger protection. It is recommended for user operation data.
  • If frequent calls are required, use addAction. Actions reported through addAction do not conflict with startAction and are not associated with current Resource, LongTask, or Error data.

Usage

/**
 * Start a RUM Action.
 */
startAction(actionName: string, actionType: string, property?: object): Promise<void>;

/**
 * Add an Action event.
 */
addAction(actionName: string, actionType: string, property?: object): Promise<void>;

Example

import { FTReactNativeRUM } from '@cloudcare/react-native-mobile';
FTReactNativeRUM.startAction('actionName', 'actionType', { 'custom.foo': 'something' });

FTReactNativeRUM.addAction('actionName', 'actionType', { 'custom.foo': 'something' });

Error

Usage

/**
 * Exception capture and log collection.
 */
addError(stack: string, message: string, property?: object): Promise<void>;

/**
 * Exception capture and log collection for a specified error type.
 */
addErrorWithType(type: string, stack: string, message: string, property?: object): Promise<void>;

Example

import { FTReactNativeRUM } from '@cloudcare/react-native-mobile';
FTReactNativeRUM.addError('error stack', 'error message', { 'custom.foo': 'something' });

FTReactNativeRUM.addErrorWithType('custom_error', 'error stack', 'error message', {
  'custom.foo': 'something',
});

Resource

Automatic WebSocket Handshake Collection

iOS React Native WebSocket handshake collection is supported since SDK 0.4.3.

Set enableIOSWebSocketResource: true when initializing RUM, and create the connection after initialization is complete; this switch is independent of enableNativeUserResource. Android uses the native SDK for automatic collection, which requires enabling enableNativeUserResource and completing the Android ft-plugin configuration.

The collection scope is the connection handshake; it does not include message sending and receiving after the connection is established, nor does it use the entire connection lifetime as the Resource duration. On iOS, the duration is calculated from the collection boundary when the WebSocket constructor is called to the final state of the first handshake success or failure, and the collection start and end times are passed to native code to avoid subsequent bridge processing delays affecting the result. This collection path does not provide phased durations such as DNS, TCP, TLS, and time to first byte; when real HTTP response information is missing, status codes or response headers are not fabricated. Metro, Inspector, HMR, and debugger WebSocket requests are filtered out.

To automatically inject Trace request headers for iOS WebSocket, you also need to enable FTTraceConfig.enableNativeAutoTrace. If only Trace is enabled and enableIOSWebSocketResource is not enabled, automatic injection is not performed through this path.

Manual Collection Usage

/**
 * Start a resource request.
 */
startResource(key: string, property?: object): Promise<void>;

/**
 * End a resource request.
 */
stopResource(key: string, property?: object): Promise<void>;

/**
 * Send resource data metrics.
 */
addResource(key: string, resource: FTRUMResource, metrics?: FTRUMResourceMetrics): Promise<void>;

Example

import { FTReactNativeRUM } from '@cloudcare/react-native-mobile';
async function getHttp(url: string) {
  const key = Utils.getUUID();
  FTReactNativeRUM.startResource(key);
  const fetchOptions = {
    method: 'GET',
    headers: {
      Accept: 'application/json',
      'Content-Type': 'application/json',
    },
  };
  let res: Response;
  try {
    res = await fetch(url, fetchOptions);
  } finally {
    const resource: FTRUMResource = {
      url: url,
      httpMethod: fetchOptions.method,
      requestHeader: fetchOptions.headers,
    };
    if (res) {
      resource.responseHeader = res.headers;
      resource.resourceStatus = res.status;
      resource.responseBody = await res.text();
    }
    FTReactNativeRUM.stopResource(key);
    FTReactNativeRUM.addResource(key, resource);
  }
}

For more information about custom Action rules, see Custom data collection rules.

Feedback

Is this page helpful?