Documentation

React Native SDK.

Screens, taps, opens, links, pushes and errors from your React Native or Expo app, linked to the same people as your site.

React Native

Install

One package for React Native and Expo. Its events, screens and taps are plain JavaScript, so they run in Expo Go, a development build and a bare app alike. Session replay and surveys are not in the published package yet.

shell
echo "@gotmode:registry=https://gotmode.com/sdk/npm/" >> .npmrc
npm install @gotmode/metrics-react-native @react-native-async-storage/async-storage

The .npmrc line sends every @gotmode package to Mode, so commit it with the project. pnpm, Yarn 1 and Bun read it too.

Mode serves its SDKs itself, not from a public package registry. A published version never changes, and every file and its SHA-256 is listed in SHA256SUMS.

FileVersionSHA-256
gotmode-metrics-react-native-0.1.0.tgz0.1.03110984f8a0b2c4f4378791f5658c02e1641f188b627b3be27f47c74423ee53d
gotmode-metrics-core-0.1.0.tgz0.1.0fac754c0bb498c57505735897073c09b2860044af54376c1a4611c095b9203c3

AsyncStorage keeps ids and unsent events across launches. When the app has expo-application or react-native-device-info, the app name, version and build come from it. Otherwise pass them to init.

React Native

Start

Call init once with your public key and tracking hostname, both from Setup, and wrap the app in ModeProvider.

tsx
import mode, { ModeProvider } from '@gotmode/metrics-react-native';
import { NavigationContainer, createNavigationContainerRef } from '@react-navigation/native';

mode.init('YOUR_INGEST_KEY', { api_host: 'https://m.example.com' });
const navigation = createNavigationContainerRef();

export default function App() {
  return (
    <ModeProvider mode={mode} navigation={navigation}>
      <NavigationContainer ref={navigation}>{/* your screens */}</NavigationContainer>
    </ModeProvider>
  );
}

There is no built-in host. Without api_host, init throws in a debug build and does nothing in a release build. Calls made before stored state is read are kept and run once it is.

React Native

Events and people

Capture what matters in your app, and name the person once they sign in.

javascript
mode.capture('added_to_cart', { sku: 'tee-black-m', price: 24 });
mode.identify('user_42', { plan: 'pro' });
mode.group('company', 'acme', { seats: 25 });
mode.register({ app_theme: 'dark' });
mode.reset(); // on logout

A different user than the one stored starts a new person. Person properties set before identify wait for it. An empty id, one over 200 bytes, or a placeholder such as null or guest is never sent. alias, set_person_properties, unset_person_properties, register_once, register_for_session, unregister, flags (flag, flag_enabled, flag_payload) and capture_exception work as on the web.

React Native

What is captured automatically

Every event below arrives with no code beyond init and ModeProvider.

EventWhen
$app_installed, $app_updatedThe first launch, and the first launch after the version or build changed
$app_openedEvery launch and return to the foreground, with the link that opened it
$app_backgroundedThe app leaves the foreground, with the time it was in front
$screenA route is focused, with the previous screen and how long it was shown
$deep_link_openedA link opens the app or reaches it while it runs
$click, $rage_clickTaps on pressable controls inside ModeProvider
$exceptionAn uncaught error, before React Native ends the app, and an unhandled promise rejection

Every event carries the locale, time zone, screen and window size, platform, app version and current screen. The first event of each session carries the device (OS, model, device type, dark mode, font scale, React Native version). Each autocapture can be turned off with capture_screens, capture_touches, capture_lifecycle, capture_deep_links and capture_errors, or from the project.

React Native

Screens

React Navigation and Expo Router both name screens by route, never by route params.

With React Navigation, pass the container ref to ModeProvider as above, and the deepest focused route is the screen. With Expo Router, call the hook in the root layout with Expo Router's own hooks, and each screen is named by its file pattern, so /product/[id] is one screen whatever the id.

tsx
import { usePathname, useSegments } from 'expo-router';
import { useEffect } from 'react';
import mode, { useModeExpoRouter } from '@gotmode/metrics-react-native';

useModeExpoRouter(mode, { usePathname, useSegments, useEffect });

For anything else, call mode.screen('Checkout').

React Native

Push notifications

With expo-notifications or React Native Firebase installed, arrivals, taps and the push token are captured with no code.

init finds the push package the app already has and listens alongside it, so the app's own handlers get every notification as before. The tap that opened the app is read without taking it from the app, and it marks that $app_opened with push. The device token is seen whenever the app fetches it. Notifications the app schedules on the device are not push and are left out.

Each event keeps the message id and the campaign, the category and thread on iOS, the channel on Android and whether the push was silent. Never the title or the body. A link in a notification's data is read as a landing. The same message seen twice counts once, a token is reported once until it changes, and the token itself is sent only with send_push_token: true. capture_push: false turns it off.

javascript
// Only for an app that keeps its own module or instance
import * as Notifications from 'expo-notifications';
import { getMessaging } from '@react-native-firebase/messaging';
import mode, { trackExpoNotifications, trackFirebaseMessaging } from '@gotmode/metrics-react-native';

trackExpoNotifications(mode, Notifications);
trackFirebaseMessaging(mode, getMessaging());
React Native

Surveys

The surveys you build in Mode Metrics, shown over the screens they target in your app.

Coming in the next release. The published package doesn't include surveys yet. ModeSurveys and the survey calls will be listed here once they are published.

In the app, a survey will ask one question at a time with its own labels, follow its URL rule against the current screen, keep to its flag and how often it repeats, ask only while consent is granted, and send $survey_shown, $survey_dismissed, and $survey_response.

React Native

Taps and privacy

A tapped control is described by its component chain, test id, accessibility label and visible text, never by what a person typed.

Emails and long numbers in a label become *. A TextInput with secureTextEntry is never described. mask_text: true leaves all text out, mode-label names a control, and mode-no-capture on a component keeps its taps out.

React Native

Session replay

Watch what people saw in your app, next to what they did, on iOS.

Coming in the next release. The published package has no native part, no masking components, and no session_replay option yet, so no app can record sessions today. The setup steps, the components, and the Expo config plugin will be listed here once they are published.

Replay will run the native Mode recorder for iOS, sending a wireframe of each screen about once a second, never a screenshot. Android recording waits on a recorder in the Android SDK. Everything will be masked until you unmask it, and secure fields and the keyboard are never recorded.

React Native

Delivery

Events wait on the device and are sent in batches, so nothing is lost offline and nothing is counted twice.

SettingValue
BatchesA second after an event, at once at 50 events, and when the app goes to the background
QueueUp to 1,000 events stored on the device
RetriesFrom 1 second to 5 minutes, with the same event ids
Shutdownmode.shutdown() sends what is queued and removes every listener

Let AI run your marketing.

Mode Agent does the daily work. You approve the spend.

Get early access