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

# Integrate deferred deep linking

> Learn how to recover a link's destination after an app install using the Masivo React Native SDK

<Note>
  Deferred deep linking requires `@masivo/rn` version `2.2.0` or later.
</Note>

### What is deferred deep linking?

When someone taps a Masivo link without your app installed, they're sent to the App Store or Play Store. Deferred deep linking recovers that original destination the first time the app opens after install, so the user lands on the right screen instead of the app's default entry point.

This feature is implemented entirely through `@masivo/rn` — there is no REST endpoint to call directly. The SDK handles device identification and the request to Masivo internally; you only need to wire a few pieces on app startup.

### 1. Provide platform adapters

The SDK does not bundle native modules for reading the Android Install Referrer or the iOS clipboard — you provide them via `setAdapters`:

```typescript theme={null}
client.deepLinks.setAdapters({
  getInstallReferrer: () => Application.getInstallReferrerAsync(),
  getClipboardText: () => Clipboard.getStringAsync()
});
```

| Adapter              | Platform | Purpose                                                                       | Example library                                                                        |
| -------------------- | -------- | ----------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- |
| `getInstallReferrer` | Android  | Reads the Play Install Referrer attached to the store redirect                | `expo-application` (`getInstallReferrerAsync`) or `react-native-play-install-referrer` |
| `getClipboardText`   | iOS      | Reads the clipboard on first launch; triggers the iOS 16+ system paste prompt | `expo-clipboard` (`getStringAsync`)                                                    |

Both adapters are optional. If you omit one, the SDK simply skips that matching method for that platform and falls back to IP-based fingerprint matching.

### 2. Configure persistent storage

`resolveDeferred` is designed to run once per install: it stores a flag so later app launches skip the request.

```typescript theme={null}
import AsyncStorage from "@react-native-async-storage/async-storage";
import { setAsyncStorage } from "@masivo/rn";

setAsyncStorage(AsyncStorage);
```

<Note>
  If you already call `setDeviceStorage(...)` for secure, Keychain-backed
  persistence of your device UUID, call it **after** `setAsyncStorage(...)`.
  `setAsyncStorage` wires in-app, device, and deep link storage together;
  calling `setDeviceStorage` afterward re-points device storage to your secure
  adapter, while deep links and in-app messaging keep using `AsyncStorage`.
</Note>

Skipping this step doesn't cause incorrect matches — Masivo still resolves each pending click at most once, server-side — but every app launch will call the resolve endpoint again instead of only the first one.

### 3. Resolve on app startup

Call this once you know the customer identifier, early in your app's lifecycle:

```typescript theme={null}
const deferred = await masivo.deepLinks.resolveDeferred({
  customerId,
  platform: Platform.OS === "ios" ? "ios" : "android"
});

if (deferred) {
  // e.g. Linking.openURL(deferred.url)
}
```

| Parameter    | Type                 | Required | Description                                                                  |
| ------------ | -------------------- | -------- | ---------------------------------------------------------------------------- |
| `customerId` | `string`             | Yes      | The Masivo customer identifier for the current user                          |
| `platform`   | `"ios" \| "android"` | Yes      | Current device platform                                                      |
| `osVersion`  | `string`             | No       | Improves fingerprint match accuracy when multiple pending clicks share an IP |
| `language`   | `string`             | No       | Same purpose as `osVersion`                                                  |

The call resolves to `null` when there is nothing to recover. Otherwise it resolves to:

| Field         | Type                                         | Description                                           |
| ------------- | -------------------------------------------- | ----------------------------------------------------- |
| `url`         | `string`                                     | The destination to open                               |
| `tracking_id` | `string`                                     | Correlates with the original link click for analytics |
| `match_type`  | `"referrer" \| "clipboard" \| "fingerprint"` | How the match was made                                |

Wrap the call in `try/catch` — a network or server error throws instead of resolving, and the attempt is not marked as done, so it retries automatically on the next app launch.

### How Android and iOS differ

* **Android** works automatically for any link that redirects to a Play Store listing — no configuration needed on the link itself.
* **iOS** requires the link to have **Deferred deep linking via clipboard** enabled in [Advanced Settings](/guides/create-links#recover-the-destination-after-an-app-install). Without it, there's nothing on the clipboard for the app to read, and only IP-based fingerprint matching applies.

### Related documentation

* [Links](/guides/create-links)
* [Integrate push notifications](/api-reference/guides/integrate-push-notification)
