API reference
All methods hang off the Attriv object exported from @attriv/capacitor.
getAttribution(),resolve(),logEvent()andshowPasteControl()requireinit()to have been called first and throw otherwise.setIdentity(),clearIdentity()andgetDeviceId()can be called beforeinit()— the identity state is stored locally and reconciled with the server on the next configure.onDeepLink()can be subscribed at any time.
init()
await Attriv.init(options: AttrivConfigureOptions): Promise<void>
Configures the SDK and wires automatic install/open tracking. See AttrivConfigureOptions.
getAttribution()
await Attriv.getAttribution(): Promise<AttrivAttribution>
Install-time attribution for this device — matchType is "organic" when unmatched. See AttrivAttribution.
onDeepLink()
Attriv.onDeepLink(cb: (event: AttrivDeepLinkEvent) => void): { remove(): void }
Subscribe to resolved deep links (universal links / app links / URI schemes). Returns a handle with remove() to unsubscribe. See AttrivDeepLinkEvent.
resolve()
await Attriv.resolve(options: { url?: string; clickId?: string }): Promise<AttrivDeepLinkEvent>
Resolve a URL or click id into link data — also notifies onDeepLink listeners. Use when autoResolveLinks is off and your app forwards URLs itself. See AttrivDeepLinkEvent.
logEvent()
await Attriv.logEvent(name: string, data?: Record<string, unknown>): Promise<void>
Track a custom event for this device. Custom events count as activity for MAU. Requires init() first; throws when name is empty or longer than 120 characters. Delivery is fire-and-forget — the promise resolves once the event is handed to the native layer, not when the server acknowledges it.
setIdentity()
await Attriv.setIdentity(identity: string): Promise<void>
Attach a user identity (your own user id) to the device for user-level attribution and cross-device MAU deduplication. Throws when identity is empty. Use at most 256 characters; longer identities are rejected by the API. Can be called before init() — the identity is stored locally and reconciled on the next configure. Call it as early as possible; current-month anonymous MAU activity for the same device is merged when identity arrives, while earlier months are not rewritten. Identity changes are sent through the explicit identify endpoint; a delayed open carrying an older identity cannot replace the newer one.
clearIdentity()
await Attriv.clearIdentity(): Promise<void>
Clear the device's identity on logout without deleting history. Future opens and events count as anonymous device activity until setIdentity() is called again; previously recorded attribution, events, and MAU history are unchanged. If the clear request cannot reach the server, the SDK remembers it and retries on the next configure. Can be called before init().
getDeviceId()
await Attriv.getDeviceId(): Promise<string>
The Attriv device id for this install. Works before init(). On iOS it is mirrored into the keychain so it survives reinstalls; reinstalls re-attribute against the same id rather than counting as a new organic install.
showPasteControl()
await Attriv.showPasteControl(options?: AttrivPasteControlOptions): Promise<AttrivPasteControlResult>
iOS 16+ only. Renders a native card — your heading, your caption, and Apple's UIPasteControl system button — for the consent-first deferred deep linking flow. UIPasteControl is a system-rendered control that delivers the clipboard contents only on an explicit user tap: the tap is the consent, so no iOS paste prompt ever fires, and the system draws the button (localized "Paste" label plus the source app's icon). Requires no entitlements or Info.plist changes. The card is a native overlay on top of the webview, not a DOM element — align it to page UI by measuring a placeholder element (see Positioning and customizing the card); it does not scroll with the page. Show it while getAttribution() reports matchType: "organic" and hide it once attributed; a skipped button stays retryable across launches. Clipboard content that doesn't carry an Attriv payload is validated and discarded on-device — nothing unrelated is transmitted.
The promise resolves once the card is rendered ({ shown: true }) or reports why nothing showed — tap outcomes are delivered via onPasteClaim, not this promise, since the user may skip the card entirely. See AttrivPasteControlOptions and AttrivPasteControlResult.
onPasteClaim()
const handle = Attriv.onPasteClaim((event: AttrivPasteClaimEvent) => { /* … */ });
// later: handle.remove()
Fires when the user taps the system paste button rendered by showPasteControl() — on a claim the event carries the updated attribution. Skipped cards fire nothing, so this (not the showPasteControl promise) is where claim results land. See AttrivPasteClaimEvent.
hidePasteControl()
await Attriv.hidePasteControl(): Promise<void>
Removes the paste control overlay, if rendered.
Types
AttrivConfigureOptions
Options for init():
interface AttrivConfigureOptions {
appKey: string;
apiUrl: string;
pasteboard?: AttrivPasteboardMode | boolean;
autoResolveLinks?: boolean;
}
| Option | Type | Default | Description |
|---|---|---|---|
appKey | string | — | Public app key from the Attriv dashboard (ak_…) |
apiUrl | string | — | Base URL of the Attriv API — must use https (http is only allowed for localhost) |
pasteboard | AttrivPasteboardMode | boolean? | "control" | iOS: how the pasteboard is used for deferred deep linking — see AttrivPasteboardMode. Booleans are accepted for compatibility: true → "read", false → "off" |
appClipAppGroup | string? | — | iOS: App Group identifier the App Clip writes the click id into (e.g. group.com.acme.app). On first launch the SDK reads the attriv.click_id key from the shared container and claims it — the deterministic App Clip install attribution path. See the App Clips guide |
autoResolveLinks | boolean? | true | Automatically resolve deep links delivered via Capacitor appUrlOpen |
AttrivPasteboardMode
How the iOS SDK uses the pasteboard for deferred deep linking:
type AttrivPasteboardMode = "off" | "read" | "control" | "both";
| Mode | System paste prompts | Behavior |
|---|---|---|
"control" (default) | None, ever | No automatic read; the app offers the paste control via showPasteControl(). Degrades to "read" on iOS < 16 (no prompt exists there) |
"read" | One at install | Silent probe gates an automatic prompted read at first launch — only fires when the clipboard holds a URL-shaped Attriv payload |
"both" | One at install | "read" at install, plus the paste control for users who deny the prompt |
"off" | None | No pasteboard mechanics — the app never reads the clipboard and showPasteControl() reports disabled |
Probabilistic fingerprint matching is not controlled by this option: it always runs as the last resort before organic. See iOS attribution for the full signal overview and setup recipes.
AttrivPasteControlOptions
Options for showPasteControl():
interface AttrivPasteControlOptions {
x?: number;
y?: number;
width?: number;
title?: string;
caption?: string;
displayMode?: "iconAndLabel" | "iconOnly" | "labelOnly";
}
| Field | Description |
|---|---|
x / y | Position of the card in CSS pixels — centered horizontally and ~70% down the screen when omitted |
width | Card width in CSS pixels (defaults to 320) |
title | Heading above the system button, e.g. "Open the link that brought you here" — frame it as an offer, never a permission |
caption | Caption under the heading, e.g. "Your link is waiting on the clipboard — only the link is read." |
displayMode | System button style; the label itself is fixed by iOS ("Paste", localized) and cannot be reworded |
AttrivPasteControlResult
Result of showPasteControl():
interface AttrivPasteControlResult {
shown: boolean;
reason?: string;
}
| Field | Description |
|---|---|
shown | Whether the native card was rendered |
reason | Why nothing was shown: not_configured, disabled (the pasteboard mode doesn't offer the control — off or read), unsupported (pre-iOS 16 / non-iOS), no_url (nothing URL-shaped on the clipboard — nothing rendered) |
AttrivPasteClaimEvent
Delivered to onPasteClaim listeners when the user taps the system paste button:
interface AttrivPasteClaimEvent {
claimed: boolean;
reason?: string;
attribution?: AttrivAttribution;
}
| Field | Description |
|---|---|
claimed | Whether the pasted payload claimed a click and re-attributed the install |
reason | Why nothing was claimed: no_payload (unrelated clipboard content — discarded on-device), unclaimed (the server declined the payload — invalid shape, outside the attribution window, or the install was already attributed; retrying won't change it), network (claim POST failed — the payload stays queued; show the control again to retry) |
attribution | Present on a successful claim — the updated attribution |
AttrivLinkData
The link payload attached to attributions and deep link events:
interface AttrivLinkData {
slug: string;
channel?: string;
campaign?: string;
tags?: string[];
data?: Record<string, string>;
}
| Field | Type | Description |
|---|---|---|
slug | string | The link's slug |
channel | string? | Attribution channel set on the link |
campaign | string? | Campaign set on the link |
tags | string[]? | Tags set on the link |
data | Record<string, string>? | Link payload — $deeplink_path routes in-app, $ios_url / $android_url / $web_url are platform fallback URLs |
AttrivAttribution
Install-time attribution for a device, returned by getAttribution():
interface AttrivAttribution {
matchType: "deeplink" | "referrer" | "pasteboard" | "fingerprint" | "organic" | "appclip";
attributed: boolean;
link?: AttrivLinkData;
clickId?: string;
clickedAt?: number;
deviceId: string;
matchScore?: number;
matchedFactors?: string[];
competingLinks?: number;
}
| Field | Description |
|---|---|
matchType | How this install/open was matched — deeplink (click id from a resolved deep link), referrer (Play Install Referrer, Android), pasteboard (iOS clipboard), appclip (click id handed over from the App Clip), fingerprint (probabilistic fallback), or organic (no click matched) |
attributed | Whether a click was attributed to this install/open |
link | The matched link's data — absent when matchType is organic |
clickId | The matched click's id — absent when matchType is organic |
clickedAt | When the click happened — Unix timestamp (milliseconds) |
deviceId | The Attriv device id — keychain-persisted on iOS, so it survives reinstalls |
matchScore | Confidence score of the fingerprint match — only on fingerprint matches |
matchedFactors | Fingerprint factors used in the match |
competingLinks | Number of other links that also matched the fingerprint |
AttrivDeepLinkEvent
Emitted to onDeepLink listeners and returned by resolve():
interface AttrivDeepLinkEvent {
link: AttrivLinkData;
clickId: string;
clickedAt: number;
url?: string;
}
| Field | Description |
|---|---|
link | The resolved link's data |
clickId | The click this resolution is tied to |
clickedAt | When the click happened — Unix timestamp (milliseconds) |
url | The original URL that opened the app — absent when resolving by clickId |