# React Native and Expo

Install the React Native package, add the component once and check your first screens under Test events.

The React Native package counts iOS and Android apps built with React Native or Expo. It is plain JavaScript with no native module, so it runs in Expo Go and needs no prebuild, config plugin or pod install. It needs React Native 0.79 or newer. [Mobile apps](/docs/mobile) explains how apps count.

## Add the app to a site

An app counts under a site, the same way a website does.

- **The app goes with a website.** Open that site's settings and add the app's ID under Apps. That is the bundle ID on iOS or the package name on Android, such as `com.acme.app`.
- **An app with no website.** In Add a site, pick An app only and enter the app's ID.

[Apps and sites](/docs/mobile#apps-and-sites) covers separate iOS and Android IDs and app variants.

## Install the package

```sh
npx expo install @ultanimus/react-native
```

In a bare React Native app, run `npm install @ultanimus/react-native` instead.

## Add the component

Render `Analytics` once, with the site ID from your site's settings. Pick the import that matches how your app moves between screens.

### Expo Router

Put it in your root layout, `app/_layout.tsx`, or `src/app/_layout.tsx` in newer templates. It reads the app's ID and version from your Expo config.

`app/_layout.tsx`

```tsx
import { Analytics } from '@ultanimus/react-native/expo-router'
import { Stack } from 'expo-router'

export default function Layout() {
  return (
    <>
      <Stack />
      <Analytics site="YOUR_SITE_ID" />
    </>
  )
}
```

### React Navigation

Put it inside `NavigationContainer` and pass the app's ID and version.

`App.tsx`

```tsx
import { Analytics } from '@ultanimus/react-native/navigation'
import { NavigationContainer } from '@react-navigation/native'

export function App() {
  return (
    <NavigationContainer>
      <Screens />
      <Analytics site="YOUR_SITE_ID" app="com.acme.app" version="2.4.0" />
    </NavigationContainer>
  )
}
```

### Any other navigation

Render the plain component once, with the app's ID and version, then name each screen where it renders.

```tsx
import { Analytics, useScreen } from '@ultanimus/react-native'

export function App() {
  return (
    <>
      <Screens />
      <Analytics site="YOUR_SITE_ID" app="com.acme.app" version="2.4.0" />
    </>
  )
}

function Checkout() {
  useScreen('Checkout')
  return <CheckoutForm />
}
```

[Screens and events](/docs/mobile/screens-and-events) covers renaming screens and what counts as a view.

## Send an event

```tsx
import { track } from '@ultanimus/react-native'

track('add_to_cart', { sku: 'lamp', quantity: 2 })
```

## Check that it works

Open the app in Expo Go or a development build and move between a few screens. Each screen and event shows under Test events in the site's settings within a few seconds. Development builds never count, so the dashboard stays empty until a release build sends its first event. [Development builds](/docs/mobile/development) explains test builds and staging.

## Next steps

- [Screens and events](/docs/mobile/screens-and-events): rename screens, send events, and name the signed-in person.
- [Visitors and offline](/docs/mobile/visitors-and-offline): storage, consent and sending without a connection.
- [App Store and Play privacy](/docs/mobile/store-privacy): what to answer on each store's form.
