React Native SDK (client)
Privacy-first analytics for React Native.
Installation
npm install @oursprivacy/react-native
# or
yarn add @oursprivacy/react-nativeQuick Start
import { OursPrivacy } from '@oursprivacy/react-native';
const oursprivacy = new OursPrivacy('YOUR_TOKEN', false);
await oursprivacy.init(false, {
default_event_properties: { app_version: '1.0.0' },
default_user_custom_properties: { subscription_tier: 'free' },
});
oursprivacy.track('App Opened');
oursprivacy.flush();The SDK connects to the Ours Privacy API automatically.
Initialization
The OursPrivacy constructor takes a token and a flag for automatic event tracking:
const oursprivacy = new OursPrivacy(token, trackAutomaticEvents);Then call init(optOutDefault?, options?) to configure and start the SDK:
await oursprivacy.init(false, {
visitor_id: 'user_123', // optional: pre-set visitor ID
default_event_properties: { platform: 'mobile' },
default_user_custom_properties: { tier: 'pro' },
default_user_consent_properties: { analytics: true },
});Init Options
| Option | Type | Description |
|---|---|---|
visitor_id | string | Pre-set the visitor ID. Sets is_manually_set_id: true on the identity |
default_event_properties | object | Merged into every track() call |
default_user_custom_properties | object | Merged into userProperties.custom_properties on every event |
default_user_consent_properties | object | Merged into userProperties.consent on every event |
Track Events
oursprivacy.track('Button Pressed');
oursprivacy.track('Purchase', { value: 49.99, currency: 'USD' });Events are batched and sent every 60 seconds or when the app goes to the background. To send immediately:
oursprivacy.flush();Identify Users
After login, link events to a known user:
// Basic — just a user ID
await oursprivacy.identify('user@example.com');
// With full user properties
await oursprivacy.identify('user@example.com', {
email: 'user@example.com',
external_id: 'user_123',
first_name: 'Jane',
last_name: 'Doe',
custom_properties: { plan: 'enterprise' },
consent: { marketing: true },
});Default Properties
Set persistent properties once and have them automatically merged into every subsequent event or user object. You can set them at init time or update them dynamically at any point:
// Update after init
oursprivacy.updateDefaultEventProperties({ feature_flag: 'new_ui' });
oursprivacy.updateDefaultUserCustomProperties({ last_seen_screen: 'home' });
oursprivacy.updateDefaultUserConsentProperties({ marketing: false });Visitor ID
Each device gets a stable UUID that persists across sessions. You can read it with:
const visitorId = oursprivacy.getVisitorId();Privacy Controls
oursprivacy.optOutTracking(); // Stop tracking and clear queued events
oursprivacy.optInTracking(); // Resume tracking
const optedOut = await oursprivacy.hasOptedOutTracking(); // Returns booleanWhen optOutTracking() is called, any unflushed events are discarded. Call flush() first if you want to send them before opting out.
Reset
Clear stored identity and default properties (useful on logout):
oursprivacy.reset();Auto-captured Device Properties
Every event automatically includes the following properties:
| Property | Description |
|---|---|
device_type | Always "mobile" |
os_name | "iOS" or "Android" |
os_version | OS version string |
device_vendor | "Apple" or device manufacturer |
device_model | Human-readable model name |
screen_width | Screen width in pixels |
screen_height | Screen height in pixels |
version | SDK version |
No IDFA is collected — AppTrackingTransparency (ATT) permission is not required.
Full API Reference
Core Methods
| Method | Description |
|---|---|
new OursPrivacy(token, trackAutomaticEvents, useNative?, storage?) | Create an instance |
init(optOutDefault?, options?) | Initialize and configure the SDK |
track(eventName, properties?) | Track an event with optional properties |
identify(id, userProperties?) | Link events to a known user identity |
flush() | Send queued events immediately |
reset() | Clear stored identity and default properties |
Default Property Methods
| Method | Description |
|---|---|
updateDefaultEventProperties(properties) | Merge into every track() call |
updateDefaultUserCustomProperties(properties) | Merge into userProperties.custom_properties |
updateDefaultUserConsentProperties(properties) | Merge into userProperties.consent |
Identity and IDs
| Method | Description |
|---|---|
getVisitorId() | Returns the stable device UUID |
Privacy
| Method | Description |
|---|---|
optOutTracking() | Stop all tracking and discard queued events |
optInTracking() | Resume tracking |
hasOptedOutTracking() | Returns Promise<boolean> |
Configuration
| Method | Description |
|---|---|
setLoggingEnabled(enabled) | Enable/disable debug logging |
setFlushOnBackground(enabled) | Flush when app backgrounds (iOS only, default: true) |
setFlushBatchSize(size) | Max events per network request (max: 50) |
Compatibility
- React Native >= 0.60
- iOS 10+
- Android API 21+
- Expo
FAQ
Do I need AppTrackingTransparency permission?
No. Ours Privacy does not use IDFA, so no ATT permission is required on iOS.
Why aren't my events showing up?
Events are batched every 60 seconds. Call flush() to send immediately, or enable setLoggingEnabled(true) to see debug output.
Explore the API
Want to see what you can send? Try our playground for a point-and-click payload builder.
Getting Help
How is this guide?