React Native RUM
The Oodle React Native SDK records how people use your iOS and Android app: the screens they open, the taps they make, the requests the app sends, the errors and crashes they see, and a replay of each session. The data goes to the same RUM Explorer, Issues and Session Replay pages as browser RUM.
Requirements
- React Native 0.79 or later with the New Architecture, or an Expo app that uses a development or release build.
- A RUM API key. Create it in Settings > API Keys with the RUM role. A RUM key can only write RUM data, so it is safe in an app.
Installation
npm install @oodle-ai/mobile-sdk-reactnative
The SDK contains native code. Build the app again after you install it:
- Expo: run
npx expo prebuild, thennpx expo run:androidornpx expo run:ios. - Bare React Native: on iOS, run
cd ios && pod install, then build the app. Android needs no step: Gradle links the SDK when it builds the app.
Quick start
Wrap the app in OodleProvider. It starts the SDK during the
first render and records taps. useOodleNavigationTracking
starts a view for each react-navigation screen.
import {
NavigationContainer,
useNavigationContainerRef,
} from '@react-navigation/native';
import {
OodleProvider,
useOodleNavigationTracking,
} from '@oodle-ai/mobile-sdk-reactnative';
const config = {
instanceId: '<YOUR_INSTANCE_ID>',
apiKey: '<YOUR_RUM_API_KEY>',
endpoint: 'https://<YOUR_COLLECTOR_DOMAIN>',
service: 'my-app',
env: 'production',
allowedTracingUrls: ['api.example.com'],
};
export default function App() {
const navigationRef = useNavigationContainerRef();
useOodleNavigationTracking(navigationRef);
return (
<OodleProvider config={config}>
<NavigationContainer ref={navigationRef}>
{/* screens */}
</NavigationContainer>
</OodleProvider>
);
}
To start the SDK at a different time (for example, after the
user gives consent), call OodleRum.init(config) and use
<OodleProvider> without config.
Configuration
| Option | Type | Default | Description |
|---|---|---|---|
instanceId | string | required | Oodle instance ID |
apiKey | string | required | RUM API key |
endpoint | string | required | Collector URL |
service | string | required | Application name |
env | string | '' | Environment |
version | string | native app version | App version |
build | string | native build number | App build |
trackingConsent | string | 'granted' | 'granted', 'pending' or 'not-granted' |
sessionSampleRate | number | 100 | Percentage of sessions to record |
trackInteractions | boolean | true | Record taps |
useAccessibilityLabel | boolean | true | Name taps by accessibilityLabel |
actionNameAttribute | string | 'oodle-action-name' | Prop that names a tap |
trackResources | boolean | true | Record XHR and fetch requests |
trackErrors | boolean | true | Record JS errors and unhandled promise rejections |
trackConsole | boolean | true | Record console.error and console.warn |
allowedTracingUrls | array | [] | Requests that get trace headers |
traceSampleRate | number | 100 | Percentage of traced requests marked as sampled |
nativeCrashReporting | boolean | true | Record native crashes |
trackAnrs | boolean | true | Record ANRs (Android) and app hangs (iOS) |
anrThresholdMs | number | 5000 Android, 2000 iOS | Main thread block that counts |
longTaskThresholdMs | number or false | 200 | JS thread block that counts as a long task |
vitals | boolean | true | Frame rate, frozen frames, memory and CPU per view |
tags | object | none | Tags on every event |
sessionReplay | object or false | on | Replay settings (see below) |
beforeSend | function | none | Change or drop an event before it is queued |
verbosity | string | 'warn' | SDK log level: 'debug', 'warn', 'error' or 'none' |
What is collected
| Event | Contents |
|---|---|
| View | Screen name, time on screen, load time, app start time (cold start), refresh rate, slow and frozen frames, memory, CPU |
| Action | Taps, named by oodle-action-name, then accessibilityLabel, then the text inside the button. Three taps on one target in one second are a rage tap. |
| Resource | XHR and fetch requests: URL without query string, method, status, duration, size, trace ID |
| Error | JS errors, unhandled promise rejections, native crashes (sent on the next start), ANRs, app hangs, failed requests |
| Long task | JS thread blocks longer than longTaskThresholdMs |
| Visibility | The app going to the background and coming back |
Each event also has the device brand and model, the OS and its version, the app version and build, the connection type, and the user and tags.
Screen views
useOodleNavigationTracking(navigationRef) covers apps that use
react-navigation. For other navigation, call the view methods
yourself:
OodleRum.startView('order-FW-1042', 'Order');
OodleRum.reportViewLoaded(); // the screen has its data
Call OodleRum.reportAppFullyDisplayed() once, when the first
screen has its data, to record the time to full display.
Taps
Give a button a clear name with accessibilityLabel or with the
oodle-action-name prop:
<Pressable oodle-action-name="Open order" onPress={open}>
<Text>{order.id}</Text>
</Pressable>
Distributed tracing
The SDK adds trace headers to requests whose URL matches
allowedTracingUrls, and puts the trace ID on the resource
event. A string matches a host and its subdomains. Choose the
header formats with propagators:
allowedTracingUrls: [
{ match: 'api.example.com', propagators: ['tracecontext', 'datadog'] },
],
Formats: tracecontext (W3C traceparent), b3, b3multi and
datadog.
Readable stack traces
Release builds have minified JavaScript and, with R8, renamed Java classes. Upload the source map and the R8 mapping after each release build, with the version and build number that the app sends. Oodle then shows errors and crashes with source files and lines.
export OODLE_API_URL=https://<YOUR_INSTANCE>.api.oodle.ai
export OODLE_INSTANCE=<YOUR_INSTANCE_ID>
export OODLE_API_KEY=<YOUR_API_KEY>
# Android
npx oodle-rum-upload --service my-app --version 1.4.0 --build 112 \
--sourcemap android/app/build/generated/sourcemaps/react/release/index.android.bundle.map \
--bundle index.android.bundle
npx oodle-rum-upload --service my-app --version 1.4.0 --build 112 \
--r8-mapping android/app/build/outputs/mapping/release/mapping.txt
# iOS: first add this line to the "Bundle React Native code and images"
# build phase: export SOURCEMAP_FILE="$DERIVED_FILE_DIR/main.jsbundle.map"
npx oodle-rum-upload --service my-app --version 1.4.0 --build 112 \
--sourcemap "$DERIVED_FILE_DIR/main.jsbundle.map" --bundle main.jsbundle
Use an API key with the Editor or Admin role. The RUM key that is in the app cannot upload files.
Session replay
The SDK records each screen as a wireframe: the position, color and text of each native view. Images are recorded as gray boxes. Replays play in the Session Replay page.
sessionReplay: {
sampleRate: 100,
textAndInputPrivacy: 'mask-all-inputs',
touchPrivacy: 'show',
startRecordingImmediately: true,
},
| Setting | Values |
|---|---|
textAndInputPrivacy | 'mask-sensitive-inputs': mask passwords, emails and phone numbers. 'mask-all-inputs' (default): mask every input. 'mask-all': mask all text and inputs. |
touchPrivacy | 'show' (default) or 'hide' |
Passwords and other sensitive inputs are masked at every level.
To set the privacy of one part of a screen, wrap it in
OodlePrivacy:
<OodlePrivacy level="hidden">
<PaymentCard />
</OodlePrivacy>
hidden replaces the content with an empty box, mask masks
its text, and allow shows its text.
Start and stop recording with OodleSessionReplay.start() and
OodleSessionReplay.stop().
Users, tags and feature flags
OodleRum.setUser({ id: 'user-123', name: 'Jane Doe', plan: 'pro' });
OodleRum.setTags({ team: 'field-ops' });
OodleRum.addFeatureFlag('new_checkout', true);
User fields other than id, name and email are sent as
usr.<key> tags.
Custom events and operations
OodleRum.addAction('Workflow submitted', { workflow: 'invoice' });
OodleRum.addError(error, { screen: 'Checkout' });
OodleRum.trackEvent('photo_uploaded', { bytes: 48213 });
OodleRum.startOperation('order.complete', requestId);
OodleRum.succeedOperation('order.complete', requestId);
// or OodleRum.failOperation('order.complete', requestId, 'timeout');
Consent
With trackingConsent: 'pending', the SDK keeps events on the
device. OodleRum.setTrackingConsent('granted') sends them;
'not-granted' deletes them and stops collection and replay.
Offline
Events that cannot be sent are kept on the device and sent when the app is online again, also after the app restarts.
Troubleshooting
- No data: check that the app was rebuilt after the install,
and that
OodleRum.init()returnedtrue. Setverbosity: 'debug'to see the SDK log. - Session ID:
OodleRum.getSessionId()returns the current session ID. Search for it in the RUM Explorer.
Support
If you need assistance or have any questions, please reach out to us through:
- Email at [email protected]