# Installation

Detour provides a React Native SDK (`@swmansion/react-native-detour`) compatible with Expo and bare React Native projects.

:::tip[AI agent skills]
Detour ships two AI coding-agent skills: `detour-onboarding` for a setup from scratch, and `migrate-to-detour` for moving off Branch or AppsFlyer. Both cover this page. See [Detour Skills](https://detour.swmansion.com/docs/platform/fundamentals/skills).
:::

A Detour app in the Dashboard is required before the SDK can resolve links. See [Getting Started](https://detour.swmansion.com/docs/platform/fundamentals/getting-started).

## Install package

```bash
    npm install @swmansion/react-native-detour
    ```
  ```bash
    yarn add @swmansion/react-native-detour
    ```
  ```bash
    pnpm add @swmansion/react-native-detour
    ```
  ```bash
    bun add @swmansion/react-native-detour
    ```
  ## Peer dependencies (Expo)

For Expo projects (including prebuild), install peer dependencies with Expo CLI so versions are matched to your Expo SDK:

```bash
npx expo install expo-application expo-clipboard expo-constants expo-localization @react-native-async-storage/async-storage
```

## Bare React Native projects

If you are not using Expo CLI, install peer dependencies with your package manager and pin versions compatible with your React Native/Expo Modules setup.

```bash
    npm install expo-application expo-clipboard expo-constants expo-localization @react-native-async-storage/async-storage
    ```
  ```bash
    yarn add expo-application expo-clipboard expo-constants expo-localization @react-native-async-storage/async-storage
    ```
  ```bash
    pnpm add expo-application expo-clipboard expo-constants expo-localization @react-native-async-storage/async-storage
    ```
  ```bash
    bun add expo-application expo-clipboard expo-constants expo-localization @react-native-async-storage/async-storage
    ```
  :::note[Async Storage is optional]
Skip `@react-native-async-storage/async-storage` if you pass a custom storage adapter in `config.storage`. See [Custom Storage](https://detour.swmansion.com/docs/sdk/react-native/custom-storage).
:::

### Expo Modules setup (React Native CLI)

Four of the peer dependencies above are [Expo Modules](https://docs.expo.dev/bare/installing-expo-modules/):

- `expo-application`
- `expo-clipboard`
- `expo-constants`
- `expo-localization`

They ship native code that has to be autolinked into your `android/` and `ios/` projects. An Expo project does this for you. A bare React Native CLI project needs Expo Modules added once:

```bash
npx install-expo-modules@latest
```

This sets up Expo Modules autolinking (and on iOS raises the deployment target to the Expo Modules minimum).

`install-expo-modules` also switches the native JS bundling step to Expo CLI (`export:embed`). That requires `metro.config.js` to extend `expo/metro-config`, which is a superset of `@react-native/metro-config` and safe in bare projects. The tool usually migrates the file for you, but verify it, especially if you had customized it:

```js title="metro.config.js"
const { getDefaultConfig } = require("expo/metro-config");
const { mergeConfig } = require("@react-native/metro-config");

module.exports = mergeConfig(getDefaultConfig(__dirname), {});
```

Then align the Expo package versions to your setup:

```bash
npx expo install --fix
```

:::tip[Build errors after adding Expo Modules]
If the app throws at startup or a release build fails after adding Expo Modules, see [bare React Native CLI build issues](https://detour.swmansion.com/docs/sdk/react-native/testing#bare-react-native-cli-build-issues).
:::

## Device info provider

Deferred-link matching builds a probabilistic fingerprint of the device. The SDK reads three values for it:

- device model
- manufacturer
- OS version

Those values come from a device info library. Install **one** of the two supported ones. Both are optional peer dependencies, and the SDK uses whichever it finds:

```bash
    npx expo install expo-device
    ```
  ```bash
    npm install react-native-device-info
    ```
  :::note[Which one to pick]
Choose `react-native-device-info` if your project already depends on it. Otherwise `expo-device` is the simplest option for Expo apps.

The device info source is not configurable. Unlike storage, it has no adapter. The SDK detects the installed library at export const detourConfig: Config = {
  apiKey: process.env.EXPO_PUBLIC_DETOUR_API_KEY!,
  appID: process.env.EXPO_PUBLIC_DETOUR_APP_ID!,
  shouldUseClipboard: true,
};
```

Keep `apiKey` and `appID` in environment variables or another secure configuration layer.

## Next steps

1. Implement the provider and link handling in [Usage](https://detour.swmansion.com/docs/sdk/react-native/sdk-usage).
2. Pick a runnable app pattern in [Examples](https://detour.swmansion.com/docs/sdk/react-native/examples).
3. Verify the native link configuration in [Testing](https://detour.swmansion.com/docs/sdk/react-native/testing).
4. Fill in the store declarations from [Privacy](https://detour.swmansion.com/docs/sdk/react-native/privacy) before you submit a build.
5. If upgrading existing code, follow [Migration to v2](https://detour.swmansion.com/docs/sdk/react-native/migration-2-0-0) and start from [From 0.x](https://detour.swmansion.com/docs/sdk/react-native/migration-2-0-0#from-0x) or [From 1.0.1](https://detour.swmansion.com/docs/sdk/react-native/migration-2-0-0#from-101).