Unified deep linking (UDL)

At a glance: Unified deep linking (UDL) enables you to send new and existing users to a specific in-app activity (for example, a specific page in the app) as soon as the app is opened.

📘

UDL privacy protection

The UDL method only returns parameters relevant to deep linking and deferred deep linking: deep_link_value and deep_link_sub1. If you try to get any other parameters (media_source, campaign, af_sub1-5, etc.), they return null.

Flow

UDL routes mobile users into a specific activity or content in an app.

The flow works as follows:

  1. User clicks a OneLink link.
    • If the user has the app installed, the Universal Links or URI scheme opens the app.
    • If the user doesn’t have the app installed, they are redirected to the app store, and after downloading, the user opens the app.
  2. The app open triggers the AppsFlyer SDK.
  3. The AppsFlyer SDK runs the UDL API.
  4. The UDL API retrieves OneLink data from AppsFlyer servers.
  5. The UDL API calls back the didResolveDeepLink() in the DeepLinkDelegate.
  6. The didResolveDeepLink() method gets a DeepLinkResult object.
  7. The DeepLinkResult object includes:
    • Status (Found/Not found/Failure)
    • A DeepLink object that carries the deep_link_value and deep_link_sub1 that the developer uses to route the user to a specific in-app activity, which is the main goal of OneLink.

Prerequisites

  • UDL requires AppsFlyer iOS SDK V6.1+.

Planning

When setting up OneLinks, the marketer uses parameters to create the links, and the developer customizes the behavior of the app based on the values received. It is the developer's responsibility to make sure the parameters are handled correctly in the app, for both in-app routing, and personalizing data in the link.

To plan the OneLink:

  1. Get from the marketer the desired behavior and personal experience a user gets when they click the URL.
  2. Based on the desired behavior, plan the deep_link_value and other parameters that are needed to give the user the desired personal experience.
    • The deep_link_value is set by the marketer in the URL and used by the developer to redirect the user to a specific place inside the app. For example, if you have a fruit store and want to direct users to apples, the value of deep_link_value can be apples.
    • The deep_link_sub1 parameter can also be added to the URL to help personalize the user experience. For example, to give a 10% discount, the value of deep_link_sub1 can be 10.

Implementation

Unified Deep Linking (UDL) API in iOS

Implement the UDL API logic based on the chosen parameters and values.

  1. Assign the AppDelegate using self to AppsFlyerLib.shared().deepLinkDelegate.
  2. Create DeepLinkDelegate as an extension of AppDelegate.
  3. Add application functions to support Universal Links and URI schemes.
  4. In DeepLinkDelegate, make sure you override the callback function, didResolveDeepLink().
    didResolveDeepLink() accepts a DeepLinkResult object as an argument.
  5. Use DeepLinkResult.status to query whether the deep linking match is found.
  6. For when the status is an error, call DeepLinkResult.error and run your error flow.
  7. For when the status is found, use DeepLinkResult.deepLink to retrieve the DeepLink object.
    The DeepLink object contains the deep linking information arranged in public variables to retrieve the values from well-known OneLink keys, for example, DeepLink.deeplinkValue for deep_link_value.
  8. Use deepLinkObj.clickEvent["deep_link_sub1"] to retrieve deep_link_sub1.
  9. Once deep_link_value and deep_link_sub1 are retrieved, pass them to an in-app router and use them to personalize the user experience.

Code example

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
  ...
  AppsFlyerLib.shared().deepLinkDelegate = self
  ...
}

extension AppDelegate: DeepLinkDelegate {
    func didResolveDeepLink(_ result: DeepLinkResult) {
        switch result.status {
        case .notFound:
            print("Deep link not found")
        case .found:
            let deepLinkStr:String = result.deepLink!.toString()
            print("DeepLink data is: \(deepLinkStr)")
            if( result.deepLink?.isDeferred == true) {
                print("This is a deferred deep link")
            } else {
                print("This is a direct deep link")
            }
            walkToSceneWithParams(deepLinkObj: result.deepLink!)
        case .failure:
            print("Error %@", result.error!)
        }
    }
}
// User logic
fileprivate func walkToSceneWithParams(deepLinkObj: DeepLink) {
    let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
    UIApplication.shared.windows.first?.rootViewController?.dismiss(animated: true, completion: nil)
    guard let fruitNameStr = deepLinkObj.clickEvent["deep_link_value"] as? String else {
         print("Could not extract query params from link")
         return
    }
    let destVC = fruitNameStr + "_vc"
    if let newVC = storyBoard.instantiateVC(withIdentifier: destVC) {
       print("AppsFlyer routing to section: \(destVC)")
       newVC.deepLinkData = deepLinkObj
       UIApplication.shared.windows.first?.rootViewController?.present(newVC, animated: true, completion: nil)
    } else {
        print("AppsFlyer: could not find section: \(destVC)")
    }
}

⇲ Github links: Swift

Updated about a month ago


Unified deep linking (UDL)


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.