Deeplinking with your app

Deeplinking is a methodology for launching a native mobile application via a link. It connects a unique url to a defined action in a mobile app, seamlessly linking users to relevant content. This guide will cover how to enable deeplinking for trck.at tracking links.

A deeplink functions much like a traditional hyperlink on a webpage. It is composed of separate elements that make up what is referred to as a Uniform Resource Identifier (URI). The URI contains all the information that, when invoked, launches a mobile application with a specific screen.

Deeplink url

Overview

Setting up trck.at deeplink to open your app involves two steps:

  • Firstly, configure the DeepLink's Schema/Intent Filter & Host of the Deeplink in Dashboard Account Settings.
  • Once the deeplink is configured in Dashboard settings, This deeplink needs to be enabled in the App. Sections below cover this in detail for iOS platform.

Go to accounts page of your dashboard and fill in the DeepLink urls.

Deeplink settings

Register a custom URL

In your Xcode project, we will need to register a custom URL identifier. Access your info.plist file within your Supporting Files. Add a new row for URL Types. Expand Item 0 and create a URL identifier. Best practices assert naming your domain in reverse, for example, com.hypertracklive://track. For our purposes, we will not need to reference this URL identifier later.

Under Item 0 we can add a new row to create a URL scheme. This gives your application the specific naming convention. Now, when iOS is presented with your registered URL scheme, it knows to launch your application.

In your iOS simulator, test the URL scheme by opening Safari and entering into your scheme. For example, if your app has registered to the com.hypertracklive://track deep link URL, opening this URL in Sarafi will launch your application.

Deeplink register

Listen for custom URLs

Your URL scheme will open your application to its home screen. Let’s update our AppDelegate’s default behavior to listen for a host and a path. Add the following code to your AppDelegate. This allows for additional parameters to be passed into a custom URL:

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
    guard let url = url, let host = url.host else {
          return
          }

          if (host == "track") {
            let taskID = queryItems.filter {
                $0.name == "task_id"
            }.first?.value

            // Handle Intent here (Use Query Params like taskID etc.)
          }
}
-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    if([[url host] isEqualToString:@"track"]) {
        NSURLComponents *urlComponents = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO];
        NSArray *queryItems = urlComponents.queryItems;
        NSString *taskID = [self valueForKey:@"task_id" fromQueryItems:queryItems];

        // Handle Intent here (Use Query Params like taskID etc.)
  }
}

...

- (NSString *)valueForKey:(NSString *)key fromQueryItems:(NSArray *)queryItems {
      NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name=%@", key];
      NSURLQueryItem *queryItem = [[queryItems filteredArrayUsingPredicate:predicate]
                                       firstObject];
    return queryItem.value;
}

[warning] Limitations

The current approach has a caveat where on opening the tracking link on devices where the corresponding app is not installed, the following popup will be displayed.

Deeplink popup

results matching ""

    No results matching ""