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.
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.
| File | Version | SHA-256 |
|---|---|---|
gotmode-metrics-react-native-0.1.0.tgz | 0.1.0 | 3110984f8a0b2c4f4378791f5658c02e1641f188b627b3be27f47c74423ee53d |
gotmode-metrics-core-0.1.0.tgz | 0.1.0 | fac754c0bb498c57505735897073c09b2860044af54376c1a4611c095b9203c3 |
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.
Start
Call init once with your public key and tracking hostname, both from Setup, and wrap the app in ModeProvider.
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.
Events and people
Capture what matters in your app, and name the person once they sign in.
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 logoutA 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.
What is captured automatically
Every event below arrives with no code beyond init and ModeProvider.
| Event | When |
|---|---|
$app_installed, $app_updated | The first launch, and the first launch after the version or build changed |
$app_opened | Every launch and return to the foreground, with the link that opened it |
$app_backgrounded | The app leaves the foreground, with the time it was in front |
$screen | A route is focused, with the previous screen and how long it was shown |
$deep_link_opened | A link opens the app or reaches it while it runs |
$click, $rage_click | Taps on pressable controls inside ModeProvider |
$exception | An 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.
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.
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').
Deep links and attribution
A link that opens your app counts like a landing on your site, so campaigns and Mode links get credit for installs and opens.
The launch link and every later link are read from React Native's Linking. Before anything is kept, parameters that carry a secret (tokens, passwords, codes, keys, signatures, sessions and magic links) are removed and any email becomes [email]. Campaign parameters, ad click ids and the Mode click id become the first and last touch of the person.
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.
// 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());Surveys
The surveys you build in Mode Metrics, shown over the screens they target in your app.
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.
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.
Session replay
Watch what people saw in your app, next to what they did, on iOS.
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.
Consent and opt out
Start with consent pending, and nothing is written to the device or sent until the person answers.
mode.init('YOUR_INGEST_KEY', { api_host: 'https://m.example.com', consent: 'pending' });
mode.set_consent('granted');
mode.set_consent({ ad_storage: 'denied' });
mode.opt_out();Pending holds up to 200 events in memory. Denied drops events and deletes what was stored. Without ad storage consent, ad click ids and the Mode click id are left out. An opt out is remembered on the device and stops every send until mode.opt_in().
Delivery
Events wait on the device and are sent in batches, so nothing is lost offline and nothing is counted twice.
| Setting | Value |
|---|---|
| Batches | A second after an event, at once at 50 events, and when the app goes to the background |
| Queue | Up to 1,000 events stored on the device |
| Retries | From 1 second to 5 minutes, with the same event ids |
| Shutdown | mode.shutdown() sends what is queued and removes every listener |