React Native and Expo
Your app reports to MRRocket like your website: screens, your events, errors, feature flags and experiments. Use the same public key as the product's website.
Install#
npx expo install @mrrocket/sdk @react-native-async-storage/async-storage expo-device expo-application expo-localizationOnly @mrrocket/sdk is required. AsyncStorage keeps unsent events across launches; the expo-* modules add app version, OS, device and locale. It has no native code of its own, so Expo Go works. A bare React Native app installs @mrrocket/sdk and AsyncStorage, then runs pod install in ios/.
Add the provider#
import { Stack } from "expo-router";
import { MRRocketProvider, useExpoRouterTracking } from "@mrrocket/sdk/react-native";
function Screens() {
useExpoRouterTracking();
return <Stack />;
}
export default function RootLayout() {
return (
<MRRocketProvider apiKey="mrr_pub_…">
<Screens />
</MRRocketProvider>
);
}With React Navigation instead of Expo Router:
const ref = useNavigationContainerRef();
const onStateChange = useNavigationTracking();
<NavigationContainer ref={ref} onReady={() => onStateChange(ref.getRootState())} onStateChange={onStateChange}>Events, flags and experiments#
import { useFlag, useMRRocket, useVariant } from "@mrrocket/sdk/react-native";
const { track, identify, reset, screen, captureError } = useMRRocket();
track("signup", { plan: "team" });
identify(user.id, { email: user.email, plan: "pro" });
const newCheckout = useFlag("new-checkout");
const paywall = useVariant("paywall"); // "control" until knownFlags and experiments are cached on the device, so a cold start shows the same variant as the last run.
Push notifications#
With expo-notifications installed, usePush().register() after sign-in signs the device up for your journeys' push steps. See Push notifications.
What it sends on its own#
$app_openand$app_background; a new session after 30 minutes in the background$screenfor every screen$installon the first open, with the UTM andrefparameters of the deep link that opened the app- Uncaught JavaScript errors, for Build › Bugs, with the app version as release
- On every event: platform, app version, build, OS version, device model and locale
Events go in batches every 10 seconds and when the app goes to the background. Offline, up to 1,000 events wait on the device and are sent later.
Consent#
consent | Stored on the device | Sent |
|---|---|---|
"anonymous" (default) | Unsent events, no id | Events without an id until identify() |
"persistent" | A random install id, removed with the app | Events with the install id |
"off" | Nothing; what the SDK stored is deleted | Nothing |
<MRRocketProvider apiKey="mrr_pub_…" consent={storedChoice}>The SDK does not remember the choice. Pass it on every start from your consent screen's stored answer, or call setConsent().
The SDK reads no advertising id and shares nothing with ad networks, so it needs no App Tracking Transparency prompt.
Surveys, feedback and the messenger#
The provider shows your live in-app survey a few seconds after start (surveys={false} switches it off). useFeedback().open() shows the top requests with votes and a form to suggest one. The messenger with your help articles: see Messenger and help center.
Click maps#
Taps show in Click maps like clicks on a web page, per screen (add the screen's path, like /settings, as a page there). Three quick taps on one spot count as a rage tap. To see the taps the provider wraps your app in one View with flex: 1; heatmaps={false} switches it off.
Session recordings#
Recordings show how people use your app, in Recordings, next to your website's. They need three things: the product's recordings switched on in MRRocket, npx expo install react-native-view-shot, and the person's own yes (ask first):
<MRRocketProvider apiKey="mrr_pub_…" replay={userAgreed}>
const { setReplay } = useMRRocket();
setReplay(false); // stops, and forgets what was not sent yetWhat is recorded: a small picture of the screen about once a second while it changes, with screens, taps and errors on the timeline.
What is never recorded:
- Typing. No picture is taken while the keyboard is open.
- What you wrap in
<MRRocketMask>. Those areas are painted black on MRRocket's server before a picture is stored; if a masked view cannot be measured, that picture is not taken at all.
<MRRocketMask><Text>{iban}</Text></MRRocketMask>