# React Native Deferred Deep Links

Deferred deep links let you route users to specific content even when they don't have your app installed. The user clicks a link, installs from the App Store or Play Store, and on first launch the SDK matches them back to the original link.

## How It Works

1. User taps a WarpLink URL in a browser
2. WarpLink records the click. The server derives the IP and stores it with the normalized language and timezone. Clicks that share a match key are kept as a list, newest first, up to 10, so a second click never overwrites the first
3. User is redirected to the App Store (iOS) or Play Store (Android)
4. User installs and opens the app
5. SDK detects first launch. A completion marker is written only after the check completes. It is scoped to one install on both platforms, and no backup restores it, so a reinstall attributes fresh. On iOS, if the backup-excluded file cannot be written, the SDK falls back to a UserDefaults flag that a restore does carry; that rare case is the one exception
6. SDK collects device signals (preferred language, timezone name and offset, and platform IDs) and sends them to the attribution API. The server derives the IP and computes the match key
7. Server matches against stored click data
8. Deep link returned with `isDeferred: true`

On iPhone (iOS), the App Store passes the app no link, so the check can only estimate. [Tether](https://warplink.app/docs/tether) closes that gap: the app reads a short code from the clipboard and gets the exact link. Pick when the SDK reads it in [SDK read modes](https://warplink.app/docs/tether/sdk-modes).

## Automatic Check

The deferred check fires automatically from `configure()`. The result arrives in your `onLink` callback, where `isDeferred` is `true`. `navigateTo(...)` in the samples on this page stands for your own navigation code:

```tsx
import { WarpLink } from '@warplink/react-native';

WarpLink.configure({
  apiKey: 'wl_live_yoursdkkeyhere000000000000000000',
  onLink: ({ deepLink, error }) => {
    if (error || !deepLink) return;
    if (deepLink.isDeferred) {
      const confidence = deepLink.matchConfidence ?? 0;
      if (confidence > 0.5) navigateTo(deepLink.deepLinkUrl ?? deepLink.destination);
    } else {
      navigateTo(deepLink.destination); // a tap, not a deferred install
    }
  },
});
```

If that check cannot reach the server, for example on a launch with no network, the failure also arrives in `onLink`. The first-launch gate stays open, so a later launch checks again by itself. From SDK 1.4.0, it waits before it tries again, and the first launch never waits. The waits are listed under [Caching Behavior](#caching-behavior). Treat an `E_NETWORK_ERROR` there as a report, not as something to act on.

## Manual Check (Advanced)

To run the check yourself, set `automaticDeferredDeepLinks: false` and call `checkDeferredDeepLink()`:

```tsx
import { useEffect, useState } from 'react';
import { WarpLink, type WarpLinkDeepLink } from '@warplink/react-native';

function App() {
  const [isReady, setIsReady] = useState(false);

  useEffect(() => {
    WarpLink.checkDeferredDeepLink()
      .then((link) => {
        if (link?.isDeferred) {
          navigateTo(link.deepLinkUrl ?? link.destination);
        }
      })
      .catch((error) => {
        console.warn('Deferred deep link check failed:', error.message);
      })
      .finally(() => {
        setIsReady(true);
      });
  }, []);

  if (!isReady) return <SplashScreen />;
  return <>{/* Your app */}</>;
}
```

## Confidence-Based Routing

```tsx
const link = await WarpLink.checkDeferredDeepLink();
if (!link?.isDeferred) return;

const confidence = link.matchConfidence ?? 0;

if (confidence > 0.5) {
  // High confidence: navigate straight to the link's destination
  navigation.navigate('WebView', { url: link.deepLinkUrl ?? link.destination });
} else if (confidence > 0.3) {
  // Medium confidence: show suggestion
  navigation.navigate('Suggestion', {
    message: 'Were you looking for this?',
    url: link.destination,
  });
}
// Below 0.3: ignore, show default onboarding
```

## Confidence Scores

Probabilistic scores depend on the match key variant. `enriched_tz` hashes the IANA timezone name and is what an SDK that collects a zone name sends. `enriched` hashes the minute offset instead and stays as the fallback for older SDKs. `basic` drops the timezone entirely.

| Scenario | Confidence | Match Type |
|----------|------------|------------|
| IDFV repeat check, same install asking again (iOS, not a reinstall) | The stored install's own score | The stored install's own type |
| Invitation token (`install_token`) | 1.0 | `deterministic` |
| Play Install Referrer (Android) | 1.0 | `deterministic` |
| `enriched_tz` match key, < 1 hour | 0.85 | `probabilistic` |
| `enriched_tz` match key, < 3 hours | 0.65 | `probabilistic` |
| `enriched_tz` match key, < 6 hours | 0.50 | `probabilistic` |
| `enriched_tz` match key, < 24 hours | 0.30 | `probabilistic` |

The offset variant scores 0.80 / 0.60 / 0.45 / 0.25 across the same bands, and `basic` scores 0.70 / 0.50 / 0.35 / 0.20. Two further signals adjust the score: more than one distinct link in the match key bucket applies x0.6, and a shared click IP applies x0.6 for carrier-grade NAT or a private address, x0.9 for a household IPv4 address, and x1.0 for IPv6. Past 24 hours there is no match at all.

An invitation token match or a Play Install Referrer match sets `matchGuaranteed` to `true` on the returned link. Use the flag, like `matchConfidence`, to pick a destination, and keep sign-in on your own authentication.

## Match Window

The match window is set **per link on the server**, not in the SDK. Configure it in the dashboard when you create or edit a link. The default is 6 hours and the maximum is 24 hours.

The window is deliberately short so the match key bucket stays tight and matches stay precise. Links created before the current limits may still carry a longer stored value, but the server caps every window at 24 hours when it reads them.

This governs probabilistic matching only. The Play Install Referrer branch is not affected by the window, and neither is an IDFV repeat check, which returns an install the device already has.

## Platform Differences

| | iOS | Android |
|---|-----|---------|
| **Deterministic match** | Invitation token only (the IDFV only recognizes the same install asking again) | Invitation token and Play Install Referrer |
| **Completion marker** | Backup-excluded file in the app container | File in `noBackupFilesDir` |
| **Device-seen marker** | Keychain | `SharedPreferences` (restored by Auto Backup) |
| **ATT required?** | No (IDFV is exempt) | N/A |

The completion marker is per install and no backup restores it, so a reinstall re-attributes on both platforms. The device-seen marker outlives an uninstall on both platforms and only sets `is_reinstall` on the request. The one exception is the iOS fallback described above.

## Caching Behavior

- Attribution check happens **once per install** (first launch only)
- Result cached by the native SDK
- Subsequent calls to `checkDeferredDeepLink()` resolve with the cached result, the matched deep link if there was one and `null` if there was not, without another network request
- An attempt that produced no usable answer (offline, an error, or a match the SDK cannot route to a destination) is **not** recorded as complete, so a later launch tries again. SDK 1.3.0 and earlier try again on the next launch
- From SDK 1.4.0, a failed check waits before it tries again, and old installs are limited:
  - The wait is 15 minutes after the first failure, 1 hour after the second, 6 hours after the third, and 24 hours after every failure after that. The SDK stops 3 days after the first failure
  - While a wait runs, `checkDeferredDeepLink` resolves with `null`, the same answer as no match, and sends no request. `isAttributionComplete()` stays `false`, and [`getDeferredCheckStatus()`](#if-your-test-did-not-match) tells you which case you have: a skipped check does not look finished. The check starts only while your app is in the foreground. A call made while the app is in the background waits until the app comes to the foreground, and then runs
  - An install older than 30 days is not checked. An install older than 48 hours is checked without language and timezone signals, so a match can come only from an exact method such as the Play Install Referrer (Android) or the IDFV repeat check (iOS)
  - A `wl_test_` key has no waits and no age limits, so you can test a first launch as often as you like
- A reinstall is a new install, so it gets a new check. See [App Reinstall](#app-reinstall)

## Edge Cases

### Offline First Launch

`checkDeferredDeepLink()` rejects with `E_NETWORK_ERROR`. The attempt is **not** consumed. The SDK tries the check again on a later launch. From SDK 1.4.0, it waits before it tries again, as listed under [Caching Behavior](#caching-behavior).

Check for connectivity before calling `checkDeferredDeepLink()` if your first-launch experience depends on it.

### App Reinstall

A reinstall is a new install and is attributed again on both platforms. The JavaScript layer does nothing special here: it bridges to the native SDK, which keeps two markers with two different jobs.

- **Completion marker.** Says the check already ran for *this* install, and it is gone once the app is. iOS keeps it in a backup-excluded file in the app container, Android in `noBackupFilesDir`. Neither comes back from a restore, so a reinstall starts clean. The one exception is the iOS fallback described above.
- **Device-seen marker.** Says the device was attributed at some point, and it outlives an uninstall. iOS keeps it in the Keychain, Android in `SharedPreferences`, which Auto Backup restores. It gates nothing. Its only job is to set `is_reinstall: true` on the attribution request

Both installs count. The dashboard shows installs and reinstalls together as one installs number.

### Routing-only mode

If the app is in [routing-only mode](https://warplink.app/docs/trust/attribution-accuracy#routing-only-mode), the server skips the probabilistic match. On Android an install that carries a Play Install Referrer still matches. No SDK change is needed.

### Multiple Links Before Install

Clicks that share a match key are kept as a list, newest first, up to 10. The **most recent** click your app can claim is the one matched, and the others stay available for the other devices that share the address. When more than one click is claimable, the confidence score is multiplied by 0.6 to report that ambiguity.

### Referral Invitation

A referral link adds a step the automatic check does not do on its own. On iPhone the person pastes the invitation into a field you provide, and `redeemInvitation(text)` matches it. On Android the Play Install Referrer carries it and the automatic check matches it. An invitation that a network failure delayed is kept by the native SDK and finished on a later launch. That result is delivered through `getAttributionResult()` and `claimReferral`, not through `onLink`. See [Referral Invitations](https://warplink.app/docs/sdks/react-native/attribution#referral-invitations). The [referrals guide](https://warplink.app/docs/guides/referrals) covers the whole path.

## Testing

Deleting or uninstalling the app is enough to retest. The completion marker goes with it, so the next install runs the check again:

1. Delete (iOS) or uninstall (Android) the app from the test device
2. Open the test link in Safari or Chrome. You're redirected to the App Store, Play Store, or fallback URL
3. Install the app via Xcode/TestFlight or Android Studio/`adb install`
4. Launch the app. The matched deep link arrives in `onLink` with `isDeferred` set to `true`

The request from step 4 carries `is_reinstall: true`, because the device-seen marker from the earlier install is still on the device. To test the first-install path instead, use a device or simulator/emulator that has never run the app, or erase it first: on iOS Simulator, **Device** > **Erase All Content and Settings** (or `xcrun simctl erase`); on Android, clear app data along with an uninstall, since `SharedPreferences` on Android is restored by Auto Backup.

### If your test did not match

Use a `wl_test_` key and a link from your Test app while you build: a Test key has no waits and no age limits. Tap the link again before every install: one tap matches one install.

If a test still shows no link, read the status of the check:

```tsx
const status = await WarpLink.getDeferredCheckStatus();
console.log(status.state, status.retryAt);
```

Read it after the check ends, for example from a debug button, or watch for the `Deferred check: <state>` log line. Right after `configure`, it reads the check as still running.

`getDeferredCheckStatus()` resolves with `{ state, retryAt? }`. `retryAt` is set only for `waiting`, in epoch milliseconds. It sends no request, and it comes from what the native SDK stored, so a relaunch keeps it.

| State | What it means |
|-------|---------------|
| `notChecked` | No check has finished for this install. A failed check whose wait has passed also reads `notChecked`. |
| `checking` | A check is running, or waiting for the app to come to the foreground. |
| `matched` | The check found a link. |
| `noMatch` | The check finished and the server found no link. |
| `waiting` | An earlier check failed. The SDK sends nothing before `retryAt`. |
| `skippedOldInstall` | The install is older than 30 days. No request is sent. |
| `stopped` | The SDK gave up 3 days after the first failure. No request is sent. |

A `wl_test_` key never reports `waiting`, `skippedOldInstall` or `stopped`. These causes give no link:

- **The link and the key are from different environments.** A `wl_test_` key matches only taps on links of your Test app, at `<handle>-test.aplnk.to`. A `wl_live_` key matches only Production links. Create the test link in Test, and tap that link.
- **A wait is running.** The first launch never waits. A check counts as failed from the moment its request is sent, so stopping the app in Xcode or Android Studio while the request is out starts a 15-minute wait. Use a `wl_test_` key, or wait until `retryAt`.
- **The install is too old.** With a `wl_live_` key, an install older than 48 hours is checked without language and timezone, so it usually reads `noMatch`. An install older than 30 days is not checked and reads `skippedOldInstall`. On iOS, Xcode keeps the app container when it runs the app again, so the install age keeps counting. Delete or uninstall the app to start the age and the waits over.
- **The click was used.** A click matches one install. Tap the link again before the next install.
- **The click is too old.** The match window is 6 hours by default. See [Match Window](#match-window).

With `debugLogging` on, each check prints `Deferred check request: attempt <n>, raw signals <yes|no>`, and each check ends with `Deferred check: <state>`. In Xcode the lines start with `[WarpLink]`. In Logcat, filter by the `WarpLink` tag. A waiting check prints `Deferred check: waiting, retry at <ISO 8601 time>`.
