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, apply in the application access monitoring console |
| iOSAppId | string | Yes | app_id, apply in the application access monitoring console |
| sampleRate | number | No | Sampling rate, value range [0,1], 0 means no collection, 1 means full collection, default is 1. Scope: all View, Action, LongTask, Error data under the same session_id |
| sessionOnErrorSampleRate | number | No | Set error collection rate. When a session is not sampled by sampleRate, 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 is 0. Scope: all View, Action, LongTask, Error data under the same session_id. Supported from SDK 0.3.14 |
| enableAutoTrackUserAction | boolean | No | Whether to automatically collect React Native component click events. After enabling, actionName can be set with accessibilityLabel |
| enableAutoTrackError | boolean | No | Whether to automatically collect React Native Error, default false |
| enableNativeUserAction | boolean | No | Whether to track Native Action, native Button click events, application startup events, default false |
| enableNativeUserView | boolean | No | Whether to enable Native View automatic tracking. It is recommended to turn off for pure React Native applications, default false |
| enableNativeUserResource | boolean | No | Whether to enable Native Resource automatic tracking. Since React Native network requests are implemented using system APIs on iOS and Android, after enabling, all resource data can be collected together. Default false |
| errorMonitorType | enum ErrorMonitorType | No | Set auxiliary monitoring information, add additional monitoring data to RUM Error data, default is not enabled |
| deviceMonitorType | enum DeviceMetricsMonitorType | No | Add monitoring data in the View cycle, default is not enabled |
| detectFrequency | enum DetectFrequency | No | View performance monitoring sampling period, default is DetectFrequency.normal |
| enableResourceHostIP | boolean | No | Whether to collect the IP address of the requested target domain. Scope: only affects default collection when enableNativeUserResource = true. iOS: Supported for >= iOS 13; Android: IP caching mechanism exists for the same OkhttpClient |
| globalContext | object | No | Add custom tags for user monitoring data source differentiation. If tracking functionality is needed, the parameter key should be track_id, value can be any numerical value. For notes on adding rules, please refer to here |
| enableTrackNativeCrash | boolean | No | Whether to enable Android Java Crash and OC/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 | Set the Native Freeze stutter threshold for collection, value range [100,), unit milliseconds. iOS default 250ms, Android default 1000ms |
| rumDiscardStrategy | string | No | Discard strategy: FTRUMCacheDiscard.discard discard new data (default), FTRUMCacheDiscard.discardOldest discard oldest data |
| rumCacheLimitCount | number | No | Local cache maximum RUM entry count limit [10_000,), default 100_000 |
| enableTraceWebView | boolean | No | Set to enable WebView data collection, default true. Supported from SDK 0.3.16 |
| allowWebViewHost | Array |
No | Set allowed WebView host addresses for data tracking, null means collect all, default is null. Supported from SDK 0.3.16 |
| iosCrashMonitoringType | enum IOSCrashMonitoringType | No | Configure the type range for SDK crash monitoring, default is IOSCrashMonitoringType.highCompatibility. Supported from SDK 0.3.16 |
RUM User Data Tracking¶
FTRUMConfig can enable automatic collection through configurations like enableAutoTrackUserAction, enableAutoTrackError, enableNativeUserAction, enableNativeUserView, enableNativeUserResource; if manual collection is needed, the following APIs can also be used.
View¶
Automatic collection of Native View can be enabled by configuring enableNativeUserView during SDK initialization RUM Configuration. React Native View only supports manual collection by default because React Native provides extensive libraries for screen navigation; if automatic collection of React Native View is needed, please continue reading the "Automatic Collection of React Native View" section below.
Usage¶
/**
* View load duration.
*/
onCreateView(viewName: string, loadTime: number): Promise<void>;
/**
* View start.
*/
startView(viewName: string, property?: object): Promise<void>;
/**
* View end.
*/
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' });
Automatic Collection of React Native View¶
If you are using react-native-navigation, react-navigation, or Expo Router navigation components in React Native, you can refer to the following methods for automatic collection of React Native View.
react-native-navigation¶
Add the FTRumReactNavigationTracking.tsx file from the example 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 to your project;
- Method 1:
If you are using createNativeStackNavigator(); to create a native navigation stack, it is recommended to enable collection by adding screenListeners, which allows statistics on page load duration. Specific usage is as follows:
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 createNativeStackNavigator(); is not used, you need to add the automatic collection method in 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 specific usage examples, please refer to example.
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¶
Usage¶
/**
* Start RUM Action.
*/
startAction(actionName: string, actionType: string, property?: object): Promise<void>;
/**
* Add 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¶
/**
* Exception capture and log collection.
*/
addError(stack: string, message: string, property?: object): Promise<void>;
/**
* Exception capture and log collection for specified error types.
*/
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¶
/**
* Start resource request.
*/
startResource(key: string, property?: object): Promise<void>;
/**
* End resource request.
*/
stopResource(key: string, property?: object): Promise<void>;
/**
* Send 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 Action custom rule descriptions, please read Data Collection Custom Rules.