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,
  errorMonitorType: ErrorMonitorType.all,
  deviceMonitorType: DeviceMetricsMonitorType.all,
  detectFrequency: DetectFrequency.rare,
};

await FTReactNativeRUM.setConfig(rumConfig);
Field Type Required Description
androidAppId string Yes app_id, obtained from the RUM console
iOSAppId string Yes app_id, obtained from the RUM console
sampleRate number No Sample rate, range [0,1]. 0 means no collection, 1 means full collection. Default is 1. Applies to all View, Action, LongTask, and Error data under the same session_id
sessionOnErrorSampleRate number No Error collection rate. When a session is not sampled by sampleRate, if an error occurs during the session, data from the 1-minute window before the error can be collected. Range [0,1]. 0 means no collection, 1 means full collection. Default is 0. Applies to all View, Action, LongTask, and Error data under the same session_id. Supported in SDK 0.3.14 and above
enableAutoTrackUserAction boolean No Whether to automatically collect React Native component click events. When enabled, you can set actionName via accessibilityLabel
enableAutoTrackError boolean No Whether to automatically collect React Native errors. Default false
enableNativeUserAction boolean No Whether to enable Native Action tracking, including native Button click events and app launch events. Default false
enableNativeUserView boolean No Whether to enable automatic Native View tracking. It is recommended to disable this for pure React Native apps. Default false
enableNativeUserResource boolean No Whether to enable automatic Native Resource tracking. Since network requests in React Native use system APIs on iOS and Android, enabling this collects all resource data as well. Default false
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 to the View lifecycle. Disabled by default
detectFrequency enum DetectFrequency No Sampling interval for view performance monitoring. Defaults to DetectFrequency.normal
enableResourceHostIP boolean No Whether to collect the IP address of the request target domain. Scope: only affects default collection when enableNativeUserResource = true. iOS: supported on iOS 13 and above; Android: the same OkhttpClient has an IP caching mechanism
globalContext object No Adds custom tags to distinguish RUM data sources. To use the tracing feature, set the key parameter to track_id and value to any number. See here for notes on adding rules
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 jank threshold for collecting Native Freeze, range [100,), in milliseconds. iOS default is 250ms, Android default is 1000ms
rumDiscardStrategy string No Discard strategy: FTRUMCacheDiscard.discard discards new data (default), FTRUMCacheDiscard.discardOldest discards old data
rumCacheLimitCount number No Maximum number of RUM entries in the local cache, range [10_000,), default 100_000
enableTraceWebView boolean No Sets whether to collect WebView data. Default true. Supported in SDK 0.3.16 and above
allowWebViewHost Array No Sets the WebView host addresses allowed for data tracking. When null, all data is collected. Default is null. Supported in SDK 0.3.16 and above
iosCrashMonitoringType enum IOSCrashMonitoringType No Configures the SDK crash monitoring type scope. Defaults to IOSCrashMonitoringType.highCompatibility. Supported in SDK 0.3.16 and above

RUM User Data Tracking

FTRUMConfig supports automatic collection through configuration options such as enableAutoTrackUserAction, enableAutoTrackError, enableNativeUserAction, enableNativeUserView, and enableNativeUserResource. If manual collection is needed, you can also use the following APIs.

View

When initializing the SDK in RUM Configuration, you can set enableNativeUserView to enable automatic Native View collection. Since 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 Collecting React Native View" below.

Usage

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

/**
 * Starts a view.
 */
startView(viewName: string, property?: object): Promise<void>;

/**
 * Stops a view.
 */
stopView(property?: object): Promise<void>;

Usage Example

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

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

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

Automatically Collecting React Native View

If you use react-native-navigation, react-navigation, or Expo Router navigation components in React Native, you can automatically collect React Native View data in the following ways.

react-native-navigation

Add the FTRumReactNavigationTracking.tsx file from the example directory to your project;

Call the FTRumReactNativeNavigationTracking.startTracking() method to start collection.

import { FTRumReactNativeNavigationTracking } from './FTRumReactNativeNavigationTracking';

function startReactNativeNavigation() {
  FTRumReactNativeNavigationTracking.startTracking();
  registerScreens();
  Navigation.events().registerAppLaunchedListener(async () => {
    await Navigation.setRoot({
      root: {
        stack: {
          children: [{ component: { name: 'Home' } }],
        },
      },
    });
  });
}
react-navigation

Add the FTRumReactNavigationTracking.tsx file from the example directory to your project;

  • Method 1:

If you use createNativeStackNavigator(); to create a native navigation stack, we recommend enabling collection by adding screenListeners, which allows the page load duration to be measured. Example:

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

const Stack = createNativeStackNavigator();

<Stack.Navigator
  screenListeners={FTRumReactNavigationTracking.StackListener}
  initialRouteName="Home"
>
  <Stack.Screen name="Home" component={Home} options={{ headerShown: false }} />
  <Stack.Screen name="Mine" component={Mine} options={{ title: 'Mine' }} />
</Stack.Navigator>;
  • Method 2:

If you do not use createNativeStackNavigator();, add the automatic collection method to the NavigationContainer component, as follows:

Note: This method cannot collect page load duration.

import { FTRumReactNavigationTracking } from './FTRumReactNavigationTracking';
import type { NavigationContainerRef } from '@react-navigation/native';

const navigationRef: React.RefObject<
  NavigationContainerRef<ReactNavigation.RootParamList>
> = React.createRef();

<NavigationContainer
  ref={navigationRef}
  onReady={() => {
    FTRumReactNavigationTracking.startTrackingViews(navigationRef.current);
  }}
>
  <Stack.Navigator initialRouteName="Home">
    <Stack.Screen name="Home" component={Home} options={{ headerShown: false }} />
    <Stack.Screen name="Mine" component={Mine} options={{ title: 'Mine' }} />
  </Stack.Navigator>
</NavigationContainer>;

For a complete usage example, see example.

Expo Router

If you are using Expo Router, add the following method to 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

Difference between startAction and addAction
  • startAction automatically calculates the Action duration. During the calculation, it associates the Action with nearby Resource, LongTask, and Error data where possible, and includes a 100 ms frequent-trigger protection. It is recommended for user action type data.
  • If you need to call it frequently, use addAction. Actions reported through addAction do not conflict with startAction and are not associated with the current Resource, LongTask, or Error data.

Usage

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

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

Usage Example

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

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

Error

Usage

/**
 * Captures exceptions and collects logs.
 */
addError(stack: string, message: string, property?: object): Promise<void>;

/**
 * Captures exceptions and collects logs with a specified error type.
 */
addErrorWithType(type: string, stack: string, message: string, property?: object): Promise<void>;

Usage 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

Usage

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

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

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

Usage 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 Data Collection Custom Rules.

Feedback

Is this page helpful?