Skip to main content

Installation

npm install despia-native
import despia from 'despia-native';
Attribution data is injected automatically into your web layer on every page load. No requests, no waiting. The data is captured at install time by the native AppsFlyer SDK, cached on-device, and available immediately on every subsequent launch even after app restarts.
Attribution data survives app restarts. It is cached natively and available on every page load without any additional setup or API calls.

Attribution Variables

Three variables are injected by native on every page load. They are read-only.
despia.appsFlyerAttribution  // full attribution object
despia.appsFlyerReferrer     // normalized source string
despia.appsFlyerUID          // unique AppsFlyer user ID
Use despia.appsFlyerReferrer for quick source checks. Use despia.appsFlyerAttribution when you need full campaign details like ad set, campaign ID, or UTM parameters.

appsFlyerReferrer

A normalized string identifying the traffic source. Built automatically from raw attribution data. No parsing required.
ValueMeaning
tiktok_adPaid TikTok campaign
tiktok_organicOrganic TikTok traffic
facebook_adPaid Meta / Facebook / Instagram campaign
facebook_organicOrganic Meta traffic
google_adPaid Google / AdMob campaign
google_organicOrganic Google traffic
snapchat_adPaid Snapchat campaign
twitter_adPaid Twitter / X campaign
affiliate_[code]Affiliate traffic, suffixed with the affiliate code
organicNo identifiable media source
raw utm_sourceAny other tracked source
if (despia.appsFlyerReferrer === "tiktok_ad") {
    // show TikTok-specific onboarding
}

if (despia.appsFlyerReferrer === "organic") {
    // show default onboarding
}
If a deep_link_value is present in the attribution data, it is used as the referrer directly before falling back to the media source logic. If an affiliate_code is present, the referrer becomes affiliate_[code].

appsFlyerAttribution

The full attribution object containing all campaign, ad set, deep link, affiliate, and cost data from AppsFlyer.
media_source
string
Raw media source from AppsFlyer, e.g. "tiktokads_int", "facebook", "googleadwords_int"
campaign
string
Campaign name set in the ad platform
campaign_id
string
Campaign ID
ad_set
string
Ad set name
ad_set_id
string
Ad set ID
ad
string
Individual ad name
ad_id
string
Individual ad ID
channel
string
Channel within the media source
click_id
string
Click ID from the ad network
site_id
string
Publisher site ID
utm_source
string
UTM source parameter from the campaign link
utm_medium
string
UTM medium parameter
utm_campaign
string
UTM campaign parameter
utm_content
string
UTM content parameter
utm_term
string
UTM term parameter
affiliate_code
string
Affiliate code if the install came from an affiliate link
Deep link destination value set in the OneLink URL, e.g. "product", "collection", "offer"
Deep link sub-parameter 1
Deep link sub-parameter 2
is_organic
boolean
Whether the install was organic (not from a paid campaign)
install_type
string
One of "install", "re-engagement", or "re-attribution"
is_first_launch
boolean
Whether this is the user’s first ever app launch
apps_flyer_uid
string
Unique AppsFlyer user ID
cost_model
string
Cost model of the campaign, e.g. "cpi", "cpa"
cost_value
string
Cost value of the install
cost_currency
string
Currency of the cost value
click_time
string
Timestamp of the ad click
install_time
string
Timestamp of the app install
{
    "media_source": "tiktokads_int",
    "campaign": "summer_2025",
    "campaign_id": "1234567890",
    "ad_set": "summer_collection_adset",
    "ad_set_id": "9876543210",
    "channel": "tiktok",
    "utm_source": "tiktok",
    "utm_medium": "paid",
    "utm_campaign": "summer_2025",
    "deep_link_value": "product",
    "page_id": "123",
    "is_organic": false,
    "install_type": "install",
    "is_first_launch": true,
    "apps_flyer_uid": "1a2b3c4d5e6f7g8h",
    "click_time": "2025-03-15 14:22:00",
    "install_time": "2025-03-15 14:23:45"
}

appsFlyerUID

A unique ID assigned by AppsFlyer to every install. Use this to stitch user journeys across web and app or to match events in server-side reporting.
console.log(despia.appsFlyerUID) // "1a2b3c4d5e6f..."
You can also request it on demand in two ways. Fire-and-forget refreshes the variable silently. The await pattern lets you use the value immediately in the same flow.
despia("appsflyer://get_uid")
// despia.appsFlyerUID is refreshed in the background

Request Attribution On Demand

Attribution is injected on load automatically. If attribution arrives after the page has already rendered, or if you need the latest data mid-session, request it explicitly.
despia("appsflyer://get_attribution")
// despia.appsFlyerAttribution is refreshed in the background

Example: Personalize Onboarding by Source

import despia from 'despia-native';

const source = despia.appsFlyerReferrer
const attr = despia.appsFlyerAttribution

if (source === "tiktok_ad") {
    console.log("TikTok campaign:", attr.campaign)
    // show TikTok-specific welcome screen

} else if (source === "facebook_ad") {
    console.log("Meta campaign:", attr.campaign)
    // show Meta-specific welcome screen

} else if (attr.affiliate_code) {
    console.log("Affiliate:", attr.affiliate_code)
    // show affiliate partner welcome screen

} else {
    // show default onboarding
}

Resources

NPM Package

Install the Despia SDK

AppsFlyer Attribution Model

How AppsFlyer attributes installs

Support

Contact our support team