Search code examples
iosswiftappsflyer

AppsFlyer with iOS 14


I'm working on an existing project and haven't used AppsFlyer before.

in older version of AppsFlyer we have initialized it using these lines in AppDelegate

    AppsFlyerTracker.shared().appsFlyerDevKey = appsflyerKey
    AppsFlyerTracker.shared().appleAppID = appId

    AppsFlyerTracker.shared().trackAppLaunch()

And Track events using

     AppsFlyerTracker.shared().trackEvent("Started", withValues: prop)

But in the latest version of AppsFlyer the initial class name has changed from

AppsFlyerTracker -> AppsFlyerLib
// now event is logged by
AppsFlyerLib.shared().logEvent("Started", withValues: prop)

So I have two questions

  1. As according to guide lines in iOS 14, we need to add permission for user to accept it before any tracking. Is it applies to these AppsFlyers logEvent event too ?

  2. if we need to add permission then adding these lines will fill the purpose ?

    AppsFlyerLib.shared().waitForATTUserAuthorization(timeoutInterval: 60) ATTrackingManager.requestTrackingAuthorization { (status) in }

  3. I didn't find alternate for AppsFlyerTracker.shared().trackAppLaunch() in the latest AppsFlyerLib


Solution

  • if user in above iOS 14 you must need to add these condition

    based on your question :

    1. As according to guide lines in iOS 14, we need to add permission for user to accept it before any tracking. Is it applies to these AppsFlyers logEvent event too ?

    Ans : YES

    1. if we need to add permission then adding these lines will fill the purpose ?

    Ans : YES

    initially you need to add the framework App Tracking Transparency

    // The following block is optional for applications wishing to give users the option to block IDFA collection.
            // for iOS 14 and above - The user may be prompted to block IDFA collection.
            //                        If user opts-out, the IDFA will not be collected by the SDK.
            // for iOS 13 and below - The IDFA will be collected by the SDK. The user will NOT be prompted to block collection.
            if #available(iOS 14, *) {
                // Set a timeout for the SDK to wait for the IDFA collection before handling app launch
                // If timeout expires before user asks to block IDFA collection, the IDFA will be collected.
                AppsFlyerLib.shared().waitForATTUserAuthorization(timeoutInterval: 60)
                // Show the user the Apple IDFA consent dialog (AppTrackingTransparency)
                // MUST be called here before start() in order to prevent IDFA collection by the SDK
                ATTrackingManager.requestTrackingAuthorization { (status) in
                }
            }
    

    the above completion handler prompts the following two points

    • The completion handler will be called with the result of the user's decision for granting or denying permission to use application tracking.
    • The completion handler will be called immediately if access to request authorization is restricted.

    and your final question

    I didn't find alternate for AppsFlyerTracker.shared().trackAppLaunch() in the latest AppsFlyerLib

    Ans :

    func applicationDidBecomeActive(_ application: UIApplication) {
        // Start the SDK (start the IDFA timeout set above, for iOS 14 or later)
        if #available(iOS 14, *) {
            AppsFlyerLib.shared().start()
        } else {
            AppsFlyerTracker.shared().trackAppLaunch()
        }
    }
    

    you can get the sample project provided by AppsFlyer's team.