Skip to content

React Native and Expo apps

View as Markdown

Track screens, custom events, identify and revenue in a React Native or Expo app, offline included, and follow people from your website into the app.

On this page

The @reveata/react-native package sends your app's activity to the same Reveata website as your site. Screens are recorded as pages of the app, so the pages report, goals, funnels, journeys and visitor profiles show the app next to the website, and the Platform filter separates them.

Install

bash
npx expo install @reveata/react-native @react-native-async-storage/async-storage
# or, without Expo: npm install @reveata/react-native @react-native-async-storage/async-storage

AsyncStorage is optional but recommended: it keeps the visitor id and the events waiting to be sent across app restarts. Without it everything is kept in memory until the app closes. With Expo, the app id, version and build number are read from expo-application and the device model from expo-device when they are installed; otherwise pass appId, appVersion and appBuild to init.

Start tracking

Call init once, as early as possible, with your website's tracking id (Settings → General) and your Reveata address:

ts
import AsyncStorage from '@react-native-async-storage/async-storage';
import * as Reveata from '@reveata/react-native';

Reveata.init({
  websiteId: 'ws_your_tracking_id',
  host: 'https://reveata.com',
  storage: AsyncStorage,
  enabled: !__DEV__,
});

Calls made before init are kept and sent once it runs. No function ever throws into your app.

Screen views

With Expo Router, add the hook to the root layout:

tsx
// app/_layout.tsx
import { Stack, usePathname } from 'expo-router';
import { useScreenTracking } from '@reveata/react-native';

export default function RootLayout() {
  useScreenTracking(usePathname());
  return <Stack />;
}

With React Navigation, pass the container ref. Route names are recorded, never route parameters:

tsx
import { NavigationContainer, useNavigationContainerRef } from '@react-navigation/native';
import { useScreenTracking } from '@reveata/react-native';

export default function App() {
  const ref = useNavigationContainerRef();
  useScreenTracking(ref);
  return <NavigationContainer ref={ref}>{/* … */}</NavigationContainer>;
}

useScreenTracking(source, { rename }) can rename or skip screens: return null to skip a modal, or group dynamic routes (/product/42 → /product/[id]). You can also record a screen yourself with Reveata.screen('Checkout') or Reveata.screen('/product/42', { from: 'search' }). The same screen twice in a row counts once.

Custom events, identify and revenue

ts
Reveata.track('add_to_cart', { sku: 'A1', plan: 'pro' });

Reveata.identify({ userId: user.id, email: user.email, name: user.name });

Reveata.revenue({ amount: 29.99, currency: 'USD', transactionId: order.id });
  • Custom events are goals in Reveata, with the same naming rules as on the website: lowercase letters, digits, _, - and : (Add To Cart becomes add_to_cart), and up to 20 string properties.
  • identify works as on the website (Identify visitors). Use the same userId as your website: funnels then count that person once across the website and the app.
  • revenue links the user to the payment your payment provider reports, by transactionId (or email), exactly like the website's thank-you page payments. The amount is recorded on its own only when the website allows unverified payments (Settings → Payments). For App Store and Google Play purchases, send them from your server with the payments API and the visitor id from Reveata.getVisitorId().

Offline, batching and app sessions

  • Events are queued and sent in batches of up to 50: every 10 seconds while the app is open, as soon as 20 are waiting, and when the app goes to the background. Reveata.flush() sends them now.
  • Without a connection, events stay queued (up to 1,000, oldest dropped first) and are retried with a growing delay (5 seconds up to 5 minutes). Each event keeps the time it happened; Reveata corrects a wrong phone clock. Events older than 7 days are not recorded.
  • A visit (session) ends after 30 minutes without activity, as on the website. Coming back from the background after that starts a new visit on the screen on display. The time each screen was visible is reported as time on page.

Options of init: flushInterval (ms, default 10000), flushAt (default 20), maxQueueSize (default 1000), trackDeepLinks (default true), trackEngagement (default true), requireConsent, enabled, debug.

What is sent

Each event carries the screen, the visitor and visit ids the SDK keeps on the device, the app id, version and build, the operating system and its version, the device type (phone or tablet) and model, the screen size, the language and the time zone. The IP address is used for the location and never stored, as on the website. No advertising id is read.

To wait for consent, start with requireConsent: true and call setConsent with the person's choice. Until then nothing is recorded or stored.

ts
Reveata.init({ websiteId: 'ws_your_tracking_id', host: 'https://reveata.com', requireConsent: true });
// After the consent prompt:
await Reveata.setConsent(true); // or false

The choice is kept across launches. Reveata.optOut() (or setConsent(false)) stops tracking, deletes the queued events and forgets the visitor id on the device; Reveata.optIn() starts again. Reveata.reset() starts a new visitor, for example when someone logs out.

Funnels from the website to the app

A funnel can start on your website and finish in the app (a visit to the pricing page, then a purchase in the app). Reveata links the two in one of two ways:

  1. identify: when the person is signed in on both, call identify with the same userId on the website and in the app. Funnels count visitors identified with the same user id as one person.

  2. A link with the visitor token: for an "Open in the app" link or button, add the website visitor's token to the link the app opens (a universal link or your own scheme). The app then continues as the same visitor, signed in or not.

    js
    // On the website (script tag): reveata.appLink(url); with npm: appLink from @reveata/tracker
    openAppButton.href = reveata.appLink('myshop://product/42');

    The SDK reads the token (_dt) from the link that opened the app, when it is less than 10 minutes old, and ignores everything else in the link except campaign parameters (UTM, ref, ad click ids), which are credited to the app visit. The app visit is a new visit of that visitor, after their website visits. Turn this off with trackDeepLinks: false, or pass links yourself with Reveata.handleDeepLink(url).

In the funnel builder, an app screen is a page step: its path is the screen (/checkout), and its host name is the app id (com.example.shop), so a step can be limited to the app.

Reports: website, app or both

  • Dashboard and reports: Add filter → System → Platform → Website or App. Visits recorded before app tracking existed count as Website. The filter works in saved segments, exports and the API ({"dimension":"platform","operator":"is","values":["app"]}).
  • Goals and funnels: the All / Website / App switch above the goals and funnels.
  • The Hostname of app visits is the app id, and website exclusions apply to it: exclude com.example.staging under Settings → Exclusions → Host names to ignore a test build.

For other runtimes

@reveata/react-native/core is the same client without React Native: give it your own Environment (storage, fetch, app details). Events are posted to https://reveata.com/api/collect/batch as { "sentAt": <ms>, "events": [...] }, at most 50 events, each a collect event with "platform": "app", an app object and an app://<app id>/<screen> address.

Was this helpful?