# Flutter Install Attribution

WarpLink uses a cascade of attribution matching to connect app installs to the links that drove them.

## Match Cascade

| Tier | Method | iOS | Android |
|------|--------|-----|---------|
| 1 | Invitation token | Referral invitation, redeemed with `redeemInvitation` | Invitation token in the Play Install Referrer |
| 2 | Deterministic | Same-install recognition by IDFV | Play Install Referrer |
| 3 | Probabilistic | Enriched probabilistic match | Enriched probabilistic match |

### Deterministic Matching

**iOS:** The App Store passes nothing through an install, so a first install on iOS uses the scored match path and returns `matchGuaranteed: false`, unless the person arrives through a [referral invitation](https://warplink.app/docs/guides/referrals) and your app passes the pasted text to `redeemInvitation`. An invitation token match is exact and returns `matchGuaranteed: true`. The IDFV is used only when the same install asks again: it returns the install the device already has, with that install's own match type and confidence, so it never turns a probabilistic match into a guaranteed one. A reinstall is deliberately not answered by the IDFV. It falls through to the probabilistic tier, which records it as a new install. IDFV is exempt from App Tracking Transparency.

**Android (Play Install Referrer):** The Play Store passes the click referrer through the install process. Confidence: 1.0. Probabilistic matching covers installs that have no Play Install Referrer.

### Probabilistic Matching

Used when deterministic signals are unavailable. The SDK collects the device's preferred language and timezone, and the server derives the request's IP address and computes the match key from all three.

#### Match Key Variants

| Variant | Timezone component | Sent by |
|---------|--------------------|---------|
| `enriched_tz` | IANA zone name, for example `America/Toronto` | SDKs that collect a zone name |
| `enriched` | Minute offset | Older SDKs, and devices that cannot resolve a zone |
| `basic` | None | Fallback when neither matches |

The zone name carries far more entropy than the offset (roughly 340 zones against 38 offsets) and does not shift at a daylight-saving boundary. It therefore earns a higher confidence ceiling.

#### Confidence by Elapsed Time

| Time Since Click | `enriched_tz` | `enriched` | `basic` |
|------------------|---------------|------------|---------|
| < 1 hour | 0.85 | 0.80 | 0.70 |
| < 3 hours | 0.65 | 0.60 | 0.50 |
| < 6 hours | 0.50 | 0.45 | 0.35 |
| < 24 hours | 0.30 | 0.25 | 0.20 |

Past 24 hours there is no match at all. The 24 hour band only applies to links whose match window is set past the 6 hour default.

Two further signals adjust the score:

- **Bucket ambiguity.** More than one claimable click shared the match key: x0.6
- **IP sharing.** Carrier-grade NAT or a private address: x0.6. A household IPv4 address: x0.9. IPv6: x1.0

## Reinstalls

A reinstall counts as an install. If the user deletes and reinstalls your app, the native SDK runs attribution again on both platforms and the result lands in your install numbers like any other install.

The attribution request carries `is_reinstall: true` in that case. It comes from a device-level marker that outlives the uninstall: the Keychain on iOS, `SharedPreferences` on Android. The marker that stops a duplicate check inside one install is a separate, install-scoped one that no backup restores. The flag labels the install and never blocks the request. See [App Reinstall](https://warplink.app/docs/sdks/flutter/deferred#app-reinstall).

## Referral Invitations

SDK 1.2.0 adds the referral handoff. A friend taps a referral link and installs the app. On Android the Play Install Referrer carries the invitation and the automatic check matches it with no screen of yours. On iPhone the install carries no data, so your first screen offers a paste field and hands the text to `redeemInvitation`.

```dart
import 'package:warplink_flutter/warplink_flutter.dart';

Future<void> onPaste(String text) async {
  try {
    final link = await WarpLink.redeemInvitation(text);
    if (link != null) showInvitationApplied(); // null: nothing was confirmed
  } on WarpLinkServerException catch (error) {
    showMessage(error.message); // says how to open the link again
  }
}
```

Text that is not a WarpLink invitation sends nothing and returns `null`. The SDK never reads the clipboard, and skipping the paste leaves the app fully usable. When the network fails, the native SDK keeps the invitation on the device and tries again on a later launch. That later result is delivered through `getAttributionResult()` and `claimReferral`, not through `onLink`.

After the friend signs up, credit the referral with your own id for them:

```dart
final claim = await WarpLink.claimReferral(user.warplinkId);
if (claim.status == ReferralClaimStatus.claimed) {
  // Recorded. Your webhook grants the reward.
}
```

`claimReferral` is safe to repeat, and `ReferralClaimStatus.none` is an ordinary answer, not an error. The full path, from link to webhook, is in the [referrals guide](https://warplink.app/docs/guides/referrals).

For a step-by-step setup, follow the [Flutter referral quickstart](https://warplink.app/docs/guides/referrals/flutter).

## Match Evidence

Every result carries the evidence behind the match, so you can decide how much weight it deserves:

| Property | Meaning |
|----------|---------|
| `attributionId` | A stable id for this attribution. Send it to your backend to claim from there |
| `matchMethod` | `installToken`, `androidReferrer`, `deviceId`, `linkOpen` or `probabilistic` |
| `evidenceClass` | `exact`, `estimated` (an estimated match from device signals) or `legacyLink` (the link id alone) |
| `replayState` | `original` for the first answer, `replayed` for a repeat of it |
| `capturedParams` | The allowed parameters captured when the link was tapped |
| `tappedAt` | When the link was tapped |

A value this SDK does not know reads as `null`, and `null` is never treated as exact.

## Interpreting Results

```dart
import 'package:warplink_flutter/warplink_flutter.dart';

final attribution = await WarpLink.getAttributionResult();
if (attribution != null) {
  debugPrint('Link ID: ${attribution.linkId}');
  debugPrint('Match type: ${attribution.matchType.name}');
  debugPrint('Confidence: ${attribution.matchConfidence}');
  debugPrint('Guaranteed: ${attribution.matchGuaranteed}');
  debugPrint('Is deferred: ${attribution.isDeferred}');
}
```

`matchGuaranteed` is also present on `WarpLinkDeepLink`, so the same check works in an `onLink` callback. `getAttributionResult()` reads the stored result and returns `null` when the install had no match.

## Recommended Thresholds

```dart
final attribution = await WarpLink.getAttributionResult();
if (attribution == null) {
  showOnboarding(); // Organic install
  return;
}

if (attribution.matchConfidence >= 0.5) {
  navigateToLink(attribution.linkId);
} else if (attribution.matchConfidence >= 0.3) {
  showSuggestion(attribution.linkId);
} else {
  showOnboarding();
}
```

| Confidence | Recommended Action |
|------------|-------------------|
| 1.0 (deterministic) | Route directly to content |
| > 0.5 (probabilistic) | Route to content: high confidence |
| 0.3–0.5 | Show content with confirmation |
| < 0.3 | Show generic onboarding |

### Using `matchGuaranteed`

`matchGuaranteed` is `true` only for an exact match: a tapped link the SDK resolved directly, a referral invitation token, or a Play Install Referrer match on Android. An iOS install reads `false` unless a referral invitation token matched it. Use it, like `matchConfidence`, to pick the destination the attribution result routes to. Use a probabilistic match to pick a destination with a safe fallback. Keep sign-in on your own authentication.

```dart
if (attribution.matchGuaranteed) {
  personalizeOnboarding(attribution.linkId); // a reliable hint, not an identity
} else {
  navigateToLink(attribution.linkId); // public content only
}
```

## Privacy

### Not Collected

- IDFA (iOS Advertising Identifier)
- GAID (Google Advertising ID)
- Android ID
- Location data
- Contacts or personal data
- Cross-app identifiers

### Signals Collected

| Signal | Purpose | Platform |
|--------|---------|----------|
| Preferred language | Match key (server normalizes to the primary subtag) | Both |
| Timezone name | Match key, sent as `timezone` by SDKs that collect a zone name | Both |
| Timezone offset | Match key, the fallback for older SDKs | Both |
| IDFV | Recognizing the same install asking again | iOS only |
| Play Install Referrer | Deterministic match | Android only |

The IP address is the third match key component and is derived server-side. The SDK does not collect a User-Agent or screen dimensions.

### App Tracking Transparency

- No IDFA access: no ATT prompt needed
- IDFV is exempt from ATT
- Does not interfere with your app's ATT strategy

All signals are sent over HTTPS and used solely for attribution matching.

The probabilistic match restores the link a user tapped on the first open after install, for your own app's deferred deep links and install attribution. It does not track users across other companies' apps or websites, and it uses no advertising ID. The server keys the pending deep link by a one-way hash of device signals (HMAC-SHA256 of the IP address, primary language, and time zone). Each tap can be matched only within the app's match window, and pending entries expire automatically. A matched install keeps that hash for your plan's data retention period. The raw IP address is not stored. The time zone is used by the enriched variant only; the basic variant uses the IP address and primary language.

## Related

- [Getting more installs matched](https://warplink.app/docs/concepts/attribution#why-an-install-did-not-match)
