> AI agents: this is one page of nextanalytica's docs. The full index for agents: https://nextanalytica.app/llms.txt

# React Native and Expo

> Add nextanalytica to a React Native or Expo app: screens, your own events, app versions, JavaScript errors and failed requests, read by your agent.

Updated: 2026-11-19

`@nextanalytica/react-native` counts what your React Native or Expo app does: screens, your own events, app versions, JavaScript errors and failed requests to your API. It is plain JavaScript on the same tracker as [the tag](/docs/tracking), so it works in Expo Go. Your agent reads the numbers like any other project's.

## How do you add it?

Your agent does the steps, with the project's MCP tools:

1. **Register each platform.** Your agent calls `add_app` once for the iOS bundle identifier and once for the Android application id (`ios.bundleIdentifier` and `android.package` in `app.json`). A project holds up to **10** apps. A batch from an app the project doesn't know is dropped, like a batch from another site.
2. **Add the SDK.** Your agent calls `get_tag`, which returns the install line, the provider and the navigation hook for your app.
3. **Run a development build.** `check_setup` lists the apps and the development builds it has seen. `dev_report` shows what they hit.
4. **Ship a release build.** The first release build of a registered app marks it verified, and the project live. The batch that verifies the app isn't stored: counting starts with the batches after it. The Tracking screen lists each app as verified or waiting.

To do it by hand, your project key (`na_…`) is the **Project token** row on the **Tracking** screen in nextanalytica.

## How do you install it?

In an Expo app, with the optional modules that give the SDK the app's version, build and device model, and a place to keep its queue:

```sh title="Terminal"
npx expo install @nextanalytica/react-native expo-application expo-device @react-native-async-storage/async-storage
```

In a React Native app without Expo:

```sh title="Terminal"
npm install @nextanalytica/react-native @react-native-async-storage/async-storage
```

Without `expo-application`, pass `appId`, `version` and `build` yourself. Without AsyncStorage everything stays in memory for the launch. On the web (react-native-web) the SDK does nothing: use [the tag](/docs/tracking/installation).

## How do you start it?

Wrap the app's root in the provider. It starts the SDK once, before your screens render.

```tsx title="App.tsx"
import { NextanalyticsProvider } from "@nextanalytica/react-native";

export default function App() {
  return (
    <NextanalyticsProvider projectKey="na_…" apiHosts={["api.shop.example"]}>
      {/* your app */}
    </NextanalyticsProvider>
  );
}
```

Outside React, `init("na_…", options)` does the same and returns the tracker.

## How do you count screens?

With Expo Router, call the hook once in the root layout. Every path the app shows is a screen view.

```tsx title="app/_layout.tsx"
import { Stack } from "expo-router";
import { NextanalyticsProvider, useNextanalyticsExpoRouter } from "@nextanalytica/react-native";

export default function RootLayout() {
  useNextanalyticsExpoRouter();
  return (
    <NextanalyticsProvider projectKey="na_…" apiHosts={["api.shop.example"]}>
      <Stack />
    </NextanalyticsProvider>
  );
}
```

With React Navigation, pass the container's ref. Every screen is a screen view at `/<route name>`.

```tsx title="App.tsx"
import { NavigationContainer, useNavigationContainerRef } from "@react-navigation/native";
import { NextanalyticsProvider, useNextanalyticsNavigation } from "@nextanalytica/react-native";

export default function App() {
  const ref = useNavigationContainerRef();
  useNextanalyticsNavigation(ref);
  return (
    <NextanalyticsProvider projectKey="na_…" apiHosts={["api.shop.example"]}>
      <NavigationContainer ref={ref}>{/* screens */}</NavigationContainer>
    </NextanalyticsProvider>
  );
}
```

For anything else, call `screen("Checkout", "/checkout")`: the route is the screen's path and the name is its title. A screen is stored as a page view, so every page metric reads screens too, with the app's id as the host.

## How do you send your own events?

```ts title="checkout.ts"
import { identify, reset, track } from "@nextanalytica/react-native";

track("signup_completed", { plan: "team" });
identify("user_8412", { plan: "team" }); // only after a yes
reset(); // on sign-out
```

Name events in `snake_case`, as on the web. See [Custom events](/docs/tracking/custom-events) and [Identify people](/docs/tracking/identify-people).

## How does consent work in an app?

Call `consent` at every launch, from the answer your own consent screen keeps:

```ts title="consent.ts"
import { consent } from "@nextanalytica/react-native";

consent("granted"); // or "denied"
```

The SDK doesn't remember the answer itself, as a website's tag doesn't between pages. Before a yes, nothing is kept on the phone: the session lives in memory for the launch and there is no device id. After `consent("granted")` the SDK keeps a random device id and any batch the network didn't take. `consent("denied")` removes everything the SDK kept. The SDK never asks for App Tracking Transparency, because nothing is shared across apps.

> **Note:** Visitors before consent are approximate in apps. They are counted from a daily hash of the network address and the phone's model and system version, so people on one network with the same phone model can merge into one visitor. Sessions are exact. See [Cookieless counting and consent](/docs/tracking/cookieless-and-consent).

## What are the options?

| Option | What it does |
| --- | --- |
| `apiHosts` | Your API's hosts (`api.shop.example`, subdomains included). Failed requests to them are reported. None by default, so nothing is reported until you name your API. |
| `release` | Your own release label. By default the app's `version+build`. |
| `appId`, `version`, `build` | The app's id, version and build, when `expo-application` isn't installed. |
| `captureRejections` | Report unhandled promise rejections (Hermes). `true` by default. |
| `endpoint` | Where batches go. `https://t.nextanalytica.app/e` by default. |

## Which requests are reported as failed?

Requests to your `apiHosts` that answer 5xx or get no answer, with the method and the path (no query, scrubbed), at most **5** a screen. Requests to other hosts are never reported.

## Which errors are reported?

- **JavaScript errors**, with their stack, from React Native's global handler. Your previous handler still runs. Stacks are scrubbed and cut to **4096** characters. The same error in the next build is the same group, because the group ignores line and column numbers.
- **Unhandled promise rejections** on Hermes.
- **Fatal errors**, sent at once rather than with the next batch. In a release build delivery is best-effort: the app can end before the request does.

Hermes keeps one rejection tracker. With Sentry present the SDK leaves it to Sentry. With another crash reporter that takes it, pass `captureRejections: false`.

When a batch gets no answer or a 5xx, the SDK tries it again later. A batch answered with a 4xx is dropped. Nothing the SDK does throws into your app.

## What is the release of an app?

The release is the app's version and build, `1.4.0+57`. With `expo-updates` running an over-the-air update, `.ota-` and the first **8** characters of the update's id follow: `1.4.0+57.ota-3f2a1b9c`. Set `release` to use your own label, **1** to **80** letters, digits and `. _ : + / @ -`, not starting with `marker:`.

`check_release` compares the newest release with at least **5** visits against the newest one with as many visits first seen before it, as it does for a website. See [Check your work](/docs/model-context-protocol/check-your-work).

## What about development builds?

A development build is one running with `__DEV__`, or, with `expo-device` installed, a simulator or emulator. Its events are never stored. They show in your agent's `dev_report`, under `<platform>.<app id>` in lower case (`ios.com.example.shop`), and in `check_setup`. A release build's numbers are what your agent reads with `query` and `check_release`.

## What does it send?

- The app's id, platform, version and build.
- The operating system and its version, the device model, and whether it is a development build.
- Screens, your events, JavaScript errors and failed requests as above.

It never reads what a person types, and it sends no advertising id. The visit dimensions `platform`, `release`, `os_version` and `device_model` split visits, so your agent can ask for sessions by phone model or system version.

## What is coming?

Native crashes, native iOS and Android SDKs and Flutter are coming. Until then the SDK sees JavaScript errors only: a crash in native code ends the app without a report.

## Next steps

- [Check your work: dev_report and check_release](/docs/model-context-protocol/check-your-work)
- [Custom events](/docs/tracking/custom-events)
- [Data and privacy](/docs/privacy)

Canonical address: https://nextanalytica.app/docs/tracking/react-native
