Skip to main content

Deep Link

Deep linking

If you are using the adtrace tracker URL with an option to deep link into your app from the URL, there is the possibility to get info about the deep link URL and its content. Hitting the URL can happen when the user has your app already installed (standard deep linking scenario) or if they don't have the app on their device (deferred deep linking scenario). Both of these scenarios are supported by the Adtrace SDK and in both cases the deep link URL will be provided to you after you app has been started after hitting the tracker URL. In order to use this feature in your app, you need to set it up properly.

Standard deep linking scenario

If your user already has the app installed and hits the tracker URL with deep link information in it, your application will be opened and the content of the deep link will be sent to your app so that you can parse it and decide what to do next. With introduction of iOS 9, Apple has changed the way how deep linking should be handled in the app. Depending on which scenario you want to use for your app (or if you want to use them both to support wide range of devices), you need to set up your app to handle one or both of the following scenarios.

Deep linking on iOS 9 and later

In order to set deep linking support for iOS 9 and later devices, you need to enable your app to handle Apple universal links.

Once you have successfully enabled the universal links feature in the panel, you need to do this in your app as well:

After enabling Associated Domains for your app in Apple Developer Portal, you need to do the same thing in your app's Xcode project. After enabling Associated Domains, add the universal link which was generated for you in the adtrace panel in the Domains section by prefixing it with applinks: and make sure that you also remove the http(s) part of the universal link.

After this has been set up, your app will be opened after you click the adtrace tracker universal link. After app is opened, continueUserActivity method of your AppDelegate class will be triggered and the place where the content of the universal link URL will be delivered. If you want to access the content of the deep link, override this method.

- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity
restorationHandler:(void (^)(NSArray *restorableObjects))restorationHandler {
if ([[userActivity activityType] isEqualToString:NSUserActivityTypeBrowsingWeb]) {
NSURL *url = [userActivity webpageURL];

// url object contains your universal link content
}

// Apply your logic to determine the return value of this method
return YES;
// or
// return NO;
}

With this setup, you have successfully set up deep linking handling for iOS devices with iOS 9 and later versions.

We provide a helper function that allows you to convert a universal link to an old style deep link URL, in case you had some custom logic in your code which was always expecting deep link info to arrive in old style custom URL scheme format. You can call this method with universal link and the custom URL scheme name which you would like to see your deep link prefixed with, and we will generate the custom URL scheme deep link for you:

- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity
restorationHandler:(void (^)(NSArray *restorableObjects))restorationHandler {
if ([[userActivity activityType] isEqualToString:NSUserActivityTypeBrowsingWeb]) {
NSURL *url = [userActivity webpageURL];

NSURL *oldStyleDeeplink = [Adtrace convertUniversalLink:url scheme:@"adtraceExample"];
}

// Apply your logic to determine the return value of this method
return YES;
// or
// return NO;
}

Deferred deep linking scenario

You can register a delegate callback to be notified before a deferred deep link is opened and decide if the Adtrace SDK will try to open it. The same optional protocol AdtraceDelegate used for the attribution callback and for event and session callbacks is used.

Follow the same steps and implement the following delegate callback function for deferred deep links:

- (BOOL)adtraceDeeplinkResponse:(NSURL *)deeplink {
// deeplink object contains information about deferred deep link content

// Apply your logic to determine whether the Adtrace SDK should try to open the deep link
return YES;
// or
// return NO;
}

The callback function will be called after the SDK receives a deferred deep link from our server and before opening it. Within the callback function you have access to the deep link. The returned boolean value determines if the SDK will launch the deep link. You could, for example, not allow the SDK to open the deep link at the current moment, save it, and open it yourself later.

If this callback is not implemented, the Adtrace SDK will always try to open the deep link by default.