> ## Documentation Index
> Fetch the complete documentation index at: https://docs.datalyr.com/llms.txt
> Use this file to discover all available pages before exploring further.

# React Native SDK

> Track React Native and Expo apps with @datalyr/react-native.

The React Native SDK supports React Native 0.72 or later and React 18 or later.

## Install

```bash theme={null}
npm install @datalyr/react-native
```

For an iOS project, install pods after adding the package:

```bash theme={null}
cd ios && pod install
```

## Initialize

```ts theme={null}
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:

```ts theme={null}
import { Datalyr } from '@datalyr/react-native/expo'
```

## Track an event

```ts theme={null}
await Datalyr.track('signup_completed', {
  plan: 'pro'
})
```

## Identify a user

```ts theme={null}
await Datalyr.identify('user_123', {
  email: 'person@example.com'
})
```

## Track a purchase

```ts theme={null}
await Datalyr.trackPurchase(99.99, 'USD', 'product_123')
```

## Core methods

| Method                          | Use 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

```ts theme={null}
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
})
```

| Option                      | Default  | What it controls                                             |
| --------------------------- | -------- | ------------------------------------------------------------ |
| `apiKey`                    | Required | Workspace API key.                                           |
| `workspaceId`               | —        | Optional workspace identifier.                               |
| `debug`                     | `false`  | Development logging.                                         |
| `maxRetries`                | `3`      | Delivery retries.                                            |
| `retryDelay`                | `1000`   | Delay between retries in milliseconds.                       |
| `timeout`                   | `15000`  | Request timeout in milliseconds.                             |
| `batchSize`                 | `10`     | Events sent in each batch.                                   |
| `flushInterval`             | `30000`  | Automatic flush interval in milliseconds.                    |
| `maxQueueSize`              | `100`    | Maximum queued events.                                       |
| `enableAutoEvents`          | `true`   | App lifecycle and session tracking.                          |
| `enableAttribution`         | `true`   | Campaign and deep-link attribution.                          |
| `enableWebToAppAttribution` | `true`   | Web-to-app matching when supported.                          |
| `skadTemplate`              | —        | iOS 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

```ts theme={null}
await Datalyr.identify('user_123', {
  email: 'person@example.com',
  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:

```ts theme={null}
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

```ts theme={null}
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

```ts theme={null}
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.

## Deep links

The SDK captures supported deep-link and install-referrer values when attribution is enabled. You can read a deferred result with:

```ts theme={null}
const deferred = Datalyr.getDeferredAttributionData()
```

## iOS tracking authorization

```ts theme={null}
await Datalyr.updateTrackingAuthorization(true)
```

This controls advertiser tracking behavior on iOS. It does not replace a complete analytics-consent implementation.

## RevenueCat and Superwall

```ts theme={null}
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.

```ts theme={null}
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.
