Skip to main content
Despia embeds the native AppsFlyer SDK in your iOS and Android builds and manages its entire lifecycle for you: initialization at launch, session tracking on every foreground, attribution resolution, deep link handling, and local caching. Your web layer never touches the SDK directly. It reads injected variables and sends commands through the appsflyer:// scheme.
Enable AppsFlyer for your app and add your AppsFlyer Dev Key (plus your Apple App ID on iOS) to your project configuration, then rebuild. No data flows until the SDK is enabled and the app is rebuilt.

Installation

npm install despia-native
pnpm add despia-native
yarn add despia-native
import despia from 'despia-native';

How it works

Despia activates the native AppsFlyer SDK at app launch and starts a new session every time the app returns to the foreground. Attribution data is resolved natively, cached on the device, and injected into your web layer on every page load, with no setup, no requests, and no waiting:
despia.appsFlyerAttribution  // full attribution object, null until first resolution
despia.appsFlyerReferrer     // e.g. "tiktok_ad", "facebook_organic", "organic"
despia.appsFlyerUID          // unique AppsFlyer device ID
Commands fired from your web layer using despia("appsflyer://...") are intercepted natively and forwarded to AppsFlyer in real time. AppsFlyer then postbacks to your connected partners (Meta, TikTok, Google) based on your dashboard configuration. Emails and phone numbers are hashed with SHA256 on the device before transmission, so raw PII never leaves the app. When a user arrives through a OneLink, an ad click or a creator’s affiliate link, the native layer resolves it and delivers the click’s metadata (the product, creator, invite code, or offer you attached to the link) to your web app through the window.onAppsFlyerDeepLink callback. This works even for a brand-new user who installs from the store first: AppsFlyer stores the click server-side and delivers it on that first launch (deferred deep linking). Your app reads the payload and decides what to do with it, redirect, fetch, or render the right content in place. Put anything a fresh install must receive into deep_link_sub1 through deep_link_sub10, the fields AppsFlyer guarantees on deferred resolution.
On iOS, the AppsFlyer SDK waits up to 60 seconds for the App Tracking Transparency prompt to be answered before finalizing install attribution. This is handled automatically.

Feature map

Attribution

Read where every user came from, TikTok, Meta, Google, affiliate, or organic, through injected variables.

Deep Linking

Receive OneLink payloads (direct and deferred) through a callback and open the right content in your app.

Events

Log standard and custom in-app events back to AppsFlyer, Meta, and TikTok.

Campaigns

Connect Meta and TikTok as integrated partners and measure which campaigns drive the most valuable users.

Ad Revenue

Report impression-level ad revenue per network for LTV and ROAS reporting.

User Identity

Set your customer user ID, pass hashed email and phone, and read the AppsFlyer UID.

Consent

Forward GDPR and DMA consent choices from your cookie banner to the native SDK.

Testing

Verify installs, events, and user IDs end to end before going live.

Quick start

1

Enable AppsFlyer for your app

Add your AppsFlyer Dev Key (and Apple App ID on iOS) to your project configuration and rebuild. The SDK, session tracking, and attribution injection activate automatically.
2

Read the referrer

if (despia.appsFlyerReferrer === "tiktok_ad") {
    showTikTokWelcome()
}
3

Identify the user at login

despia("appsflyer://set_user_id?customer_user_id=" + encodeURIComponent(userId))
4

Log your first event

despia("appsflyer://log_event?event_name=af_login&event_values=" + encodeURIComponent("{}"))
5

Handle deep links

Define the callback early, before your bundle loads, and open the right content from the payload.
window.onAppsFlyerDeepLink = (payload) => {
    if (payload.deep_link_value) openContent(payload.deep_link_value, payload.deep_link_sub1)
}

Resources

NPM Package

despia-native