Register an account at https://console.dlink.cloud/. After creating an app on the platform, get the corresponding AccountId of the app.
source 'https://github.com/CocoaPods/Specs.git'
source 'https://github.com/DLinkSDK/deeplink-dev-specs.git'
pod 'AppAttribution'
import AppAttribution
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// you can set you project-applied custom deviceid
AttributionManager.setCustomDeviceId("your device id here")
// create your configuration
let configuration = AttributionConfiguration(appId: "your_account_id")
AttributionManager.setup(configuration: configuration, delegate: self) // setup your appid
// start attribution manager
AttributionManager.start()
return true
}
// if you're ready to report app attribution, call readyToReport to start the process
// strongly recommended to begin report after you get your att auth
AttributionManager.readyToReport()
pass the universal link info to AttributionManager in UIApplicationDelegate
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([any UIUserActivityRestoring]?) -> Void) -> Bool {
// If you use universal link to open your app
// pass the info to AttributionManager
AttributionManager.application(application: application, continue: userActivity, restorationHandler: restorationHandler)
return true
}
extension AppDelegate: AttributionManagerDelegate {
func appAttributionDidFinish(matched: Bool, info: [String : Any]) {
// app attribution finished
if matched {
print("attribution matched, get info \(info)")
// you can fetch your campaign info from here
if let campaignInfo = info[AttributionParamKey.campaignInfoKey] as? [String: Any] {
// check your campaign info params here
print("campaign info \(campaignInfo)")
}
} else {
print("attribution not matched")
}
}
func appAttributionDidFail(error: any Error) {
print("attribution failed \(error)")
}
func appAttributionDidReceiveUniversalLinkInfo(_ info: [String : Any]) {
// universal link info
print("get info from universal link \(info)")
}
}
You may also obtain the attribution result by attributionInfo API. Remeber it's only available after you have finished your attribution process, or else you can only get an nil result
let info = AttributionManager.attributionInfo
print("attribution info \(info)")
If your app supports AppsFlyerLib, follow the next steps
var configuration = AttributionConfiguration(appId: "your_app_id")
configuration.appsFlyerAdapter = self // set AppsFlyerAdapter
AttributionManager.setup(configuration: configuration, delegate: self) // set
extension AppDelegate: AppsFlyerAdapter {
func startAppsFlyerLib() {
// Start Your AppsFlyerLib Here
AppsFlyerLib.shared().appsFlyerDevKey = "your_apps_flyer_dev_key"
AppsFlyerLib.shared().appleAppID = "your_apps_app_id"
AppsFlyerLib.shared().start()
}
}
This step is very important!
extension AppDelegate: AppsFlyerLibDelegate {
func onConversionDataSuccess(_ conversionInfo: [AnyHashable : Any]) {
// callback to AttributionManager with appsflyer result
AttributionManager.onAppflyerConversionDataSuccess(conversionInfo)
}
func onConversionDataFail(_ error: any Error) {
print("appsflyerlib failed \(error)")
}
}