Integrating AppsFlyer analytics into a mobile application
AppsFlyer — primarily an MMP (Mobile Measurement Partner), not just analytics. Its key task — attribution: determine which ad network the user installing the app came from. Without an MMP, you can't correctly compare ROI of Facebook Ads and Google UAC: both platforms will claim the same user.
How AppsFlyer attribution works
When clicking an ad, AppsFlyer saves a fingerprint or click_id. After installation and first app launch, the SDK sends an install event to AppsFlyer server. The server matches install with click through deterministic method (click_id in deeplink) or probabilistic (IP + User-Agent). Result: accurate information about campaign, ad group and ad that brought the user.
SDK connection
iOS via Swift Package Manager — AppsFlyerLib-iOS:
import AppsFlyerLib
// AppDelegate
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
AppsFlyerLib.shared().appsFlyerDevKey = "YOUR_DEV_KEY"
AppsFlyerLib.shared().appleAppID = "YOUR_APP_STORE_ID"
AppsFlyerLib.shared().delegate = self
AppsFlyerLib.shared().isDebug = false // debug builds only!
return true
}
// SceneDelegate or applicationDidBecomeActive
func applicationDidBecomeActive(_ application: UIApplication) {
AppsFlyerLib.shared().start()
}
Android:
implementation("com.appsflyer:af-android-sdk:6.+")
// Application.onCreate()
AppsFlyerLib.getInstance().init("YOUR_DEV_KEY", conversionDataListener, this)
AppsFlyerLib.getInstance().start(this)
start() on Android must be called in Application.onCreate(), not in Activity — otherwise deeplink attribution on cold start from deeplink will be inaccurate.
In-app events for campaign optimization
AppsFlyer sends in-app events to ad networks for algorithmic optimization (Conversions API, SKAdNetwork on iOS):
AppsFlyerLib.shared().logEvent(
AFEventPurchase,
withValues: [
AFEventParamRevenue: 990.0,
AFEventParamCurrency: "RUB",
AFEventParamContentId: "sku_123",
AFEventParamOrderId: "order_456"
]
)
Standard constants AFEventPurchase, AFEventAddToCart, AFEventCompleteRegistration — these are strings matching Facebook and Google format. Use them instead of arbitrary names so ad networks correctly interpret events.
SKAdNetwork and iOS 14+
Starting iOS 14, Apple limited deterministic attribution through ATT. AppsFlyer implements SKAdNetwork attribution: conversion value (6 bits) encodes user information and transmits to Apple aggregately. AppsFlyer automatically manages updateConversionValue through dashboard configuration — you don't need to implement this manually.
// Conversion Value requires calling start() with ATT status
AppsFlyerLib.shared().waitForATTUserAuthorization(timeoutInterval: 60)
// ... after ATT request:
AppsFlyerLib.shared().start()
Deeplink and OneLink
OneLink — AppsFlyer technology for universal links working both on iOS (Universal Links) and Android (App Links) and when app not installed, directing to installation page:
// AppDelegate
func application(_ application: UIApplication,
continue userActivity: NSUserActivity,
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
AppsFlyerLib.shared().continue(userActivity, restorationHandler: nil)
return true
}
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
AppsFlyerLib.shared().handleOpen(url, options: options)
return true
}
Typical integration mistakes
isDebug = true in production — direct attribution data leak (debug traffic goes to separate stream and isn't counted in real campaigns). Must check through Build Configuration.
Missing waitForATTUserAuthorization on iOS 14+: without pause, AppsFlyer sends install before getting ATT permission, and attribution will be probabilistic even if user later agreed.
What's included in the work
- SDK connection for iOS/Android
- DEV Key and App ID setup
- In-app events for key conversions
- SKAdNetwork configuration for iOS 14+
- OneLink / Universal Links / App Links setup
- Integration with ad networks through postbacks (if required)
Timeline
Basic attribution with in-app events: 1–2 days. Full integration with OneLink and SKAdNetwork: up to 3 days. Cost calculated individually.







