About five minutes, on the free plan, without a credit card.
1
Install the SDK
The SDK depends on expo-application for build and version numbers (and the referrer on Android), and expo-constants for the user agent.
npm install @openpanel/react-native
npx expo install expo-application expo-constants
2
Create the client
Put the instance in one shared file and import it everywhere. apiUrl must be set to the Privytics ingestion host, otherwise the SDK sends to its default host. React Native needs a clientSecret because native apps cannot use CORS headers the way browsers do.
// lib/op.ts
import { OpenPanel } from '@openpanel/react-native';
export const op = new OpenPanel({
apiUrl: 'https://api.privytics.com',
clientId: 'YOUR_CLIENT_ID',
clientSecret: 'YOUR_CLIENT_SECRET',
});
3
Track screen views
With Expo Router, call screenView whenever the pathname changes. React Navigation users can call the same method from onStateChange using the current route name.
import { usePathname, useSegments } from 'expo-router';
import { useEffect } from 'react';
import { op } from '@/lib/op';
export default function RootLayout() {
const pathname = usePathname();
const segments = useSegments();
useEffect(() => {
op.screenView(pathname, {
segments: segments.join('/'),
});
}, [pathname, segments]);
return (/* Your layout JSX */);
}
4
Track events and identify users
Global properties are attached to every event. identify() links sessions into one profile using your own user id, so it is opt-in and needs your own lawful basis. Call clear() on logout to reset the identity.
import { Platform } from 'react-native';
import { op } from '@/lib/op';
op.setGlobalProperties({
app_version: '1.0.0',
platform: Platform.OS,
});
op.track('button_clicked', {
button_name: 'signup',
screen: 'home',
});
op.identify({
profileId: user.id,
firstName: user.firstName,
lastName: user.lastName,
email: user.email,
properties: {
plan: user.plan,
},
});
// on logout
op.clear();
5
Queue events while offline
Install the two optional peer dependencies, then pass them to the constructor as the storage and networkInfo options. Events are held on the device and sent once connectivity returns.
npm install @react-native-async-storage/async-storage @react-native-community/netinfo
6
Pass the offline adapters to the client
Update your shared client file to include the two adapters. Everything else stays the same, including apiUrl.
// lib/op.ts
import AsyncStorage from '@react-native-async-storage/async-storage';
import NetInfo from '@react-native-community/netinfo';
import { OpenPanel } from '@openpanel/react-native';
export const op = new OpenPanel({
apiUrl: 'https://api.privytics.com',
clientId: 'YOUR_CLIENT_ID',
clientSecret: 'YOUR_CLIENT_SECRET',
storage: AsyncStorage,
networkInfo: NetInfo,
});