Skip to content

React Native

One init covers both platforms. Autolinking registers the native module, so there are no manual linking steps:

npm install @kloudmate/rum-react-native
cd ios && pod install   # iOS only

Call init() once, at the top of your app entry file:

import { init } from '@kloudmate/rum-react-native';

init({
  endpoint: 'https://otel.kloudmate.com:4318',
  rumAccessToken: 'YOUR_PUBLIC_API_KEY',
  applicationName: 'my-app',
  deploymentEnvironment: 'production',
  version: '1.0.0',
  sampleRate: 1.0,
  sessionReplayEnabled: true,
  replaySampleRate: 0.25,
});

Get your key and the rest of the values from Add application. See Add an application.

Screens, taps, app start, crashes, and uncaught JS errors are captured from this call on. Set captureJsErrors to false if you install your own JS error handler. Name a screen with setCurrentScreen(), send a custom event with addEvent(), and report a handled error with reportError().

The SDK ships native code, so it doesn’t run in Expo Go. Use a development build.

Add the config plugin to your app config:

{
  "expo": {
    "plugins": ["@kloudmate/rum-react-native"]
  }
}

Then create the development build:

npx expo prebuild
npx expo run:android   # or: npx expo run:ios

The plugin registers the native module on Android, and iOS needs no extra setup. It works with the New Architecture, and everything else on this page applies unchanged.

On Android, React Native sends both fetch and XMLHttpRequest through OkHttp, so one change in MainApplication.kt covers both:

OkHttpClientProvider.setOkHttpClientFactory {
    OkHttpClient.Builder()
        .addInterceptor(KloudMateRum.okHttpInterceptor()!!)
        .build()
}

Set the user after sign-in with setUser(), and call endSession() on sign-out. A mobile session runs for up to four hours and survives the process being killed, so without that call a sign-out followed by a different sign-in keeps one session ID across both people.