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, applied from the RUM console |
| iOSAppId | string | Yes | app_id, applied from the RUM console |
| sampleRate | number | No | Sampling rate, 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. 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 in SDK 0.3.14+ |
| enableAutoTrackUserAction | boolean | No | Whether to automatically collect React Native component click events. When enabled, actionName can be set with accessibilityLabel |
| enableAutoTrackError | boolean | No | Whether to automatically collect React Native Errors, 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 auto-tracking. Recommended to turn off for pure React Native applications, default false |
| enableNativeUserResource | boolean | No | Whether to enable Native Resource auto-tracking. Since React Native network requests are implemented using system APIs on iOS and Android, when enabled, 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 off |
| deviceMonitorType | enum DeviceMetricsMonitorType | No | Add monitoring data within the View cycle, default is off |
| detectFrequency | enum DetectFrequency | No | View performance monitoring sampling frequency, default is DetectFrequency.normal |
| enableResourceHostIP | boolean | No | Whether to collect the IP address of the requested domain name. Scope: only affects default collection when enableNativeUserResource = true. iOS: >= iOS 13 support; Android: IP caching mechanism exists for the same OkhttpClient |
| globalContext | object | No | Add custom tags for distinguishing user monitoring data sources. If tracking functionality is needed, the parameter key should be track_id, value can be any value. For notes on addition rules, please refer to 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 | Set the threshold for collecting Native Freeze stutter, range [100,), unit milliseconds. iOS default 250ms, Android default 1000ms |
| rumDiscardStrategy | string | No | Discard strategy: FTRUMCacheDiscard.discard discard new data (default), FTRUMCacheDiscard.discardOldest discard old 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 in SDK 0.3.16+ |
| allowWebViewHost | Array |
No | Set allowed WebView host addresses for data tracking, null for full collection, default is null. Supported in SDK 0.3.16+ |
| iosCrashMonitoringType | enum IOSCrashMonitoringType | No | Configure the type range for SDK crash monitoring, default is IOSCrashMonitoringType.highCompatibility. Supported in 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. For React Native View, since React Native provides extensive libraries for screen navigation, only manual collection is supported by default. If automatic collection of React Native View is needed, please continue reading "Automatic Collection of React Native View" 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>;
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 use createNativeStackNavigator(); to create a native navigation stack, it is recommended to use the screenListeners method to enable collection. This 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>;
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 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¶
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>;
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.