Skip to main content
The React Native SDK supports React Native 0.72 or later and React 18 or later.

Install

npm install @datalyr/react-native
For an iOS project, install pods after adding the package:
cd ios && pod install

Initialize

import { Datalyr } from '@datalyr/react-native'

await Datalyr.initialize({
  apiKey: 'dk_your_api_key',
  enableAutoEvents: true,
  enableAttribution: true
})
For Expo, import the Expo entry instead:
import { Datalyr } from '@datalyr/react-native/expo'

Track an event

await Datalyr.track('signup_completed', {
  plan: 'pro'
})

Identify a user

await Datalyr.identify('user_123', {
  email: '[email protected]'
})

Track a purchase

await Datalyr.trackPurchase(99.99, 'USD', 'product_123')

Core methods

MethodUse it to
initialize(config)Initialize the SDK.
track(name, properties?)Track an event.
screen(name, properties?)Track a screen view.
identify(userId, properties?)Identify a user.
alias(newUserId, previousId?)Link two IDs for the same user.
reset()Clear identity on logout.
flush()Send queued events immediately.
trackPurchase(...)Track purchase revenue.
The SDK can automatically track app lifecycle events and attribution. Call reset() whenever a user signs out or switches accounts.

Configuration

await Datalyr.initialize({
  apiKey: 'dk_your_api_key',
  debug: false,
  maxRetries: 3,
  retryDelay: 1000,
  timeout: 15000,
  batchSize: 10,
  flushInterval: 30000,
  maxQueueSize: 100,
  enableAutoEvents: true,
  enableAttribution: true,
  enableWebToAppAttribution: true
})
OptionDefaultWhat it controls
apiKeyRequiredWorkspace API key.
workspaceIdOptional workspace identifier.
debugfalseDevelopment logging.
maxRetries3Delivery retries.
retryDelay1000Delay between retries in milliseconds.
timeout15000Request timeout in milliseconds.
batchSize10Events sent in each batch.
flushInterval30000Automatic flush interval in milliseconds.
maxQueueSize100Maximum queued events.
enableAutoEventstrueApp lifecycle and session tracking.
enableAttributiontrueCampaign and deep-link attribution.
enableWebToAppAttributiontrueWeb-to-app matching when supported.
skadTemplateiOS conversion template: ecommerce, gaming, or subscription.
Deprecated aliases such as apiUrl, maxEventQueueSize, autoEvents, and retryConfig are still accepted but should not be used in new implementations.

Identity

await Datalyr.identify('user_123', {
  email: '[email protected]',
  plan: 'pro'
})

const anonymousId = Datalyr.getAnonymousId()
Use alias only when the old and new IDs belong to the same person. reset() rotates local identity and clears user-scoped attribution.

Screens

Track a screen manually:
await Datalyr.screen('Pricing', { source: 'tab_bar' })
For React Navigation, use datalyrScreenTracking or createScreenTrackingListeners. For Expo Router, use the Expo entry and useDatalyrScreenTracking.

Revenue events

await Datalyr.trackPurchase(99.99, 'USD', 'pro_yearly')
await Datalyr.trackSubscription(19.99, 'USD', 'pro_monthly')
The SDK also includes helpers for add to cart, content views, checkout, registration, search, leads, and payment information.

Attribution and journeys

const attribution = Datalyr.getAttributionData()
const journey = Datalyr.getJourney()
const summary = Datalyr.getJourneySummary()
Use setAttributionData() only when your app already has trusted campaign information that the SDK could not capture automatically. The SDK captures supported deep-link and install-referrer values when attribution is enabled. You can read a deferred result with:
const deferred = Datalyr.getDeferredAttributionData()

iOS tracking authorization

await Datalyr.updateTrackingAuthorization(true)
This controls advertiser tracking behavior on iOS. It does not replace a complete analytics-consent implementation.

RevenueCat and Superwall

const revenueCat = Datalyr.getRevenueCatAttributes()
const superwall = Datalyr.getSuperwallAttributes()
Pass these attributes to the matching subscription SDK when needed.

Queue and lifecycle

Events created before initialization are temporarily buffered. Offline events are queued and retried when connectivity returns.
await Datalyr.flush()
Datalyr.destroy()
Use flush() when immediate delivery matters. destroy() stops listeners and background work; only call it when tearing down the SDK.