Expo
Use the React Native SDK in Expo apps, with Expo Router screen tracking.
Expo apps use `@stancelens/react-native`. It works in Expo Go, development builds and production builds, with no config plugin and no native code of its own.
The package isn't on npm yet. Build it from packages/react-native in the Stancelens repository (bun install && bun run build) and install that folder, or an npm pack tarball of it, in your app.
Install
npx expo install @stancelens/react-native @react-native-async-storage/async-storage \
expo-application expo-constants expo-device expo-localizationOnly @stancelens/react-native is required. The others are optional; all of them run in Expo Go.
| Package | Adds |
|---|---|
@react-native-async-storage/async-storage | Keeps the install ID and the offline queue across restarts |
expo-application, expo-constants | app_version with the build number |
expo-device | device_model, device_type, os_version; iPadOS on iPad |
expo-localization | language and timezone |
Expo Router
import { Stack } from "expo-router";
import { StancelensProvider } from "@stancelens/react-native";
import { useExpoRouterTracking } from "@stancelens/react-native/expo-router";
function Tracking() {
useExpoRouterTracking();
return null;
}
export default function RootLayout() {
return (
<StancelensProvider site="SITE_ID" host="https://stancelens.com">
<Tracking />
<Stack />
</StancelensProvider>
);
}The screen name is the route pattern without groups: app/(tabs)/user/[id].tsx at /user/42 is sent as /user/[id], so IDs in URLs aren't collected. Options:
useExpoRouterTracking({
mode: "pathname", // send /user/42 instead of /user/[id]
props: ({ pathname, segments }) => ({ section: segments[0] }),
});The hook is a separate entry point, @stancelens/react-native/expo-router, so apps without expo-router never bundle it.
Everything else
Events, identify, revenue, flags, options, storage and error capture work exactly as in React Native. For encryption at rest you can pass secureStoreStorage(SecureStore) from expo-secure-store, but it's meant for small values; AsyncStorage suits a large offline queue better.