CDPGuidesSupport
SDKsClient

React Native SDK (client)

Install the Ours Privacy React Native SDK to capture privacy-first analytics in React Native, Expo, and web. Pure JavaScript, with no native modules, no IDFA, and no ATT prompt on iOS.

Privacy-first analytics for React Native. Pure JavaScript, so it works in React Native, Expo, and web.

Install

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

@react-native-async-storage/async-storage is a peer dependency used for persistent storage in bare React Native projects. Without it, the SDK falls back to in-memory storage.

Quick Start

import { OursPrivacy } from '@oursprivacy/react-native';

const op = new OursPrivacy();
await op.init('YOUR_API_TOKEN');

op.track('App Opened');

For the full API (identify, flush, reset, default properties, deep link attribution, opt in/out, EU routing, and configuration), see the README on GitHub.

Web-to-app Identity

When your app is opened by a link carrying ours_visitor_id, the SDK sets that visitor ID for you, and every event after it lands on the profile that already holds the person's web history and campaign context. The same call reads the UTM parameters and roughly 25 ad-platform click IDs off that link.

await op.trackDeepLink(url) does the parsing. Await it before your next track() so identity is applied first. You can also pass the URL to init as initialURL and let the SDK parse it at startup.

If your app already holds the visitor ID, from a WebView or a native bridge, set it directly with await op.setVisitorId('550e8400-e29b-41d4-a716-446655440000').

Forward the opening URL. The SDK hooks nothing in the operating system, so your app has to hand over the URL it was opened with, on a cold start and on a warm open:

import { Linking } from 'react-native';

// Cold start
const initialURL = await Linking.getInitialURL();
if (initialURL) {
  await op.trackDeepLink(initialURL);
}

// Warm open, app already running
Linking.addEventListener('url', async ({ url }) => {
  await op.trackDeepLink(url);
});

Parsed UTM parameters and click IDs last for the run of the app, and only the visitor ID persists across a restart. Attribution still holds, because the join happens on the visitor ID rather than on the campaign parameters.

Mobile app attribution covers how app attribution works end to end, and when you need a mobile measurement partner alongside it.

Compatibility

  • react >= 16.8.0
  • react-native >= 0.60.0
  • Expo (managed and bare)
  • Web (via react-native-web)

Because the SDK is pure JavaScript, iOS and Android version support follows whatever your React Native version supports. No IDFA is collected, so AppTrackingTransparency (ATT) permission is not required on iOS.

Explore the API

Want to see what you can send? Try our playground for a point-and-click payload builder.

Need Help?

Next Steps

How is this guide?

On this page