Skip to content

React Native SDK

Official React Native SDK for Mitr Analytics. Works with bare React Native and Expo development builds (it uses AsyncStorage, which isn't available in Expo Go's managed sandbox without the dev-client).

Install

Not yet published to npm — add it as a local/git dependency alongside its one required peer:

npm install @mitr/react-native @react-native-async-storage/async-storage

Get your Site ID and Secret Key

From the dashboard: Integration Hub → Add New App → Android / iOS. You'll get a Site ID and a Secret Key — copy the secret key now, it's shown in full only once. React Native apps have no browser Origin to check, so the secret key is sent with every request instead.

Initialize

import { MitrAnalytics } from '@mitr/react-native';

export const mitr = new MitrAnalytics({
  siteId: 'YOUR_SITE_ID',
  secretKey: 'YOUR_SECRET_KEY',
});

Automatic screen tracking

Wire into React Navigation's onStateChange for automatic screen-view tracking:

<NavigationContainer onStateChange={(state) => mitr.trackNavigationStateChange(state)}>
  /* ... */
</NavigationContainer>

Not using React Navigation? Call mitr.pageView('ScreenName') manually wherever screens change instead.

Manual tracking

await mitr.track('purchase_completed', { metadata: { value: 49.99, currency: 'USD' } });

Identifying users (login/logout)

// After a successful login:
mitr.identify(user.id);

// On logout:
mitr.reset();

User ids are SHA-256 hashed on-device before they're ever sent — the backend only ever sees user_hash.

Deep-link attribution

First-touch utm_* query params from whatever deep link opened (or was received by) the app are captured once, automatically, and attached to every event from then on — no setup required beyond your app's own deep-link configuration already being in place.

Resilience

Events are batched (flushed every 5s or every 10 events, whichever comes first) and persisted to AsyncStorage between flushes, and the SDK automatically flushes when the app backgrounds. A backgrounded or killed app doesn't lose queued events.

Have questions about integration or security? Drop us a line directly.