React Native SDK
Track screens, events, identity, and delivery from React Native without coupling analytics to a navigation library.
Install and initialize
The SDK works with Expo, React Navigation, Expo Router, and other navigation setups.
pnpm add tracwell-react-native @react-native-async-storage/async-storageimport { createAsyncStorage } from "@react-native-async-storage/async-storage";
import { AppState } from "react-native";
import { createTracwell } from "tracwell-react-native";
const analytics = await createTracwell({
appId: "com.example.app",
appState: AppState,
collectionMode: "product",
projectKey: "tw_live_...",
projectOrigin: "https://example.com",
storage: createAsyncStorage("tracwell"),
});createTracwell() is asynchronous because it reads saved identity from storage. Create the client once when the app starts and share that instance.
- projectKey
- Your project key from Settings → Website → Tracking setup.
- projectOrigin
- The URL of the website you added in Tracwell, exactly as registered, such as
https://example.com. Apps have no browser origin, so Tracwell checks this value instead. An app without a website can use any HTTPS URL you own, as long as it matches the website's URL in Tracwell. - appId
- Your iOS bundle identifier or Android application ID. Screens are reported as
app://com.example.app/Home, which keeps app traffic separate from website pages. - collectionMode
"private"(default) keeps nothing on the device."product"saves identity through thestorageadapter and enablesidentify()and revenue attribution.- appState
- Pass React Native's
AppStateso events are sent when the app goes to the background.
Track screens and events
analytics.screen("Home");
analytics.track("upgrade_started", { plan: "pro" });
// Product mode only. Use an opaque internal ID, never an email.
analytics.identify("customer_123");
// On logout, so the next person starts a fresh visitor and session.
await analytics.reset();Call screen() whenever the visible screen changes. The SDK does not depend on a navigation library, and repeated calls for the same screen are ignored.
<NavigationContainer
ref={navigationRef}
onReady={() => analytics.screen(navigationRef.getCurrentRoute()?.name ?? "Unknown")}
onStateChange={() => analytics.screen(navigationRef.getCurrentRoute()?.name ?? "Unknown")}
>
{/* your navigators */}
</NavigationContainer>import { usePathname } from "expo-router";
import { useEffect } from "react";
export function ScreenTracker() {
const pathname = usePathname();
useEffect(() => {
analytics.screen(pathname);
}, [pathname]);
return null;
}
// Render <ScreenTracker /> once in app/_layout.tsx.Delivery
Events are batched and sent when the app goes to the background. Mobile systems may suspend the app before a request finishes, so call await analytics.flush() after an important conversion.
For checkout attribution, pass analytics.getSession() to your server as described in Revenue attribution. It returns undefined in Private mode or before consent.