Back to Home

React Native and Expo

Track screens, sessions, app versions and devices, plus your own events, in the same dashboard as your website. The SDK works in Expo Go and needs no config plugin.

1. Add your app

In the dashboard, choose Add website or app, then Mobile app. Enter the app's name and bundle ID. You get a tracking ID and the exact code for your app.

2. Install

Expo

npx expo install @thravic/react-native @react-native-async-storage/async-storage

React Native CLI

npm install @thravic/react-native @react-native-async-storage/async-storage
npx pod-install

3. Start tracking

Call init once, as early as you can, with the values from your dashboard:

import { Thravic } from '@thravic/react-native';

Thravic.init('TF-1A2B3C4D', {
  bundleId: 'com.acme.shop',
  appVersion: '1.4.0',
});
OptionDefaultWhat it does
bundleId'app'Your bundle ID. Screens are recorded as app://com.acme.shop/Home.
appVersionnoneShown under Versions. In Expo, use Application.nativeApplicationVersion from expo-application.
apiUrlThravicWhere events are sent. The code in your dashboard fills it in.
sessionTimeoutMinutes30Time in the background after which the next open starts a new session.
flushIntervalSeconds10How often queued events are sent.
debugfalseLog every event to the console.

4. Track screens

React Navigation

import { NavigationContainer, createNavigationContainerRef } from '@react-navigation/native';
import { Thravic } from '@thravic/react-native';

const navigationRef = createNavigationContainerRef();

export default function App() {
  return (
    <NavigationContainer ref={navigationRef} onReady={() => Thravic.trackNavigation(navigationRef)}>
      {/* ... */}
    </NavigationContainer>
  );
}

Expo Router

// app/_layout.tsx
import { Stack, useNavigationContainerRef } from 'expo-router';
import { useEffect } from 'react';
import { Thravic } from '@thravic/react-native';

Thravic.init('TF-1A2B3C4D', { bundleId: 'com.acme.shop' });

export default function Layout() {
  const ref = useNavigationContainerRef();
  useEffect(() => Thravic.trackNavigation(ref), [ref]);
  return <Stack />;
}

By hand

Thravic.screen('Checkout');

Events and users

Thravic.track('purchase', { amount: 49, currency: 'USD' });
Thravic.identify('user-42');

Use your events as funnel steps, or send them to your own systems with webhooks.

Privacy

Thravic.optOut(); // stops tracking and drops unsent events; remembered across launches
Thravic.optIn();
Thravic.isOptedOut();

The SDK stores a random visitor ID on the device. It doesn't read the advertising ID, contacts, location or any other data that needs a permission. Thravic gets the country from the request IP and then discards the IP.

What you see in the dashboard

How it works

Create a free account to get your tracking ID.