Deep Linking for your App

Last Updated: Feb 06, 2017 01:35PM PST
Deep links can help drive returning users directly to the heart of your application. After doing a little leg work to implement deep links in your app, you can create URIs that that automatically load your application to a specific screen when clicked.

How does it work? Simply by leveraging built-in aspects of both iOS and Android platforms. After configuring your application to handle URIs, you can create deep links like these:
 
SampleCompanyName-SampleApp:// Launch application
SampleCompanyName-SampelApp://search?product=SampleProduct Open to search results for a specific item
SampleCompanyName-SampleApp://user Open the app to the user's profile page
SampleCompanyName-SampleApp://LastLevel Load last level user attempted

When combined with targeted campaigns, deep linking allows you to seamlessly re-engage users into your application.

Configuring iOS Apps for URL Scheme Deep-Linking

  1. First, you'll need to enable URI support in your iOS application. You have two options:
  • Manually update your info.plist file to include the CFBundeURLTypes key. This key needs to contain the CFBundleURLName and CFBundleURLSchemes properties.
    • CFBundleURLName - Generally, this is the bundle ID for your application. Please see Apple's Development doc for more information or other options.

    • CFBundleURLSchemes - Array of strings containing your desired URL scheme names, generally at least your application's name without spaces. You'll want to ensure these values are unique to your application.

    Here's an example of a simple CFBundeURLTypes key:

    <key>CFBundleURLTypes</key>
      <array>
        <dict>
          <key>CFBundleURLName</key>
          <string>com.samplecompany.sampleapp</string>
          <key>CFBundleURLSchemes</key>
          <array>
            <string>sampleappname</string>
          </array>
        </dict>
      </array>
  OR  
  • Using the XCode editor, edit the "URL types" under the Info section for your application:
  • Add the bundle ID for your application to the 'URL identifier' field.  Please see Apple's Development doc for more information or other options.
  • Add at least a single string to the 'URL Schemes' field, generally your application's name without spaces. You'll want to ensure values added here are unique to your application.
  1. Next you'll need to add some code to handle custom URIs with arguments, better known as 'Deep Links'.

    After adding URI support to your application, just clicking on a URL consisting of a scheme name for your application will launch your app. Using our example above, that would be: sampleappname://

    If you want to send a user to a specific part of your application, you'll need to add arguments to this base URL, creating a deep link. Here is a sample deep link with a path and query:
     
    sampleappname://samplepath?samplequery=samplevalue

    When a user clicks a URL containing your scheme (sampleappname:// in this example), your app's delegate is called, specifically the method application:openURL:sourceApplication:annotation. To handle deep links, you'll need to add your own code that properly routes the user based on the provided arguments. Below is a quick example, but please refer to Apple's own documentation for handling the NSURL object:
    (BOOL)application:(UIApplication *)application
                openURL:(NSURL *)url
                sourceApplication:(NSString *)sourceApplication
                annotation:(id)annotation
                {
                 NSString *path = [url path];
                 NSString *query = [url query];
                 // Your specialized code to send user to a designated screen
                 return YES;
                }

    Based on the above code and our sample deep link, path would be '/samplepath' and query would be 'samplequery=samplevalue'. Your added code would specify how to handle these arguments and where to send the user.

Configuring iOS Apps for Universal Links

Universal Links is a technology introduced with iOS 9.2, and ties your iOS application with a HTTPS web URL.  It is a increasing popular alternative to traditional URL scheme based deep-linking on iOS.  You can read more on Universal Links in our detailed guide here.  


Configuring Android Apps for Deep Linking

  1. First, you'll need to enable URI support in your Android application by adding an intent to your desired activities in your AndroidManifest.xml file. Here's an example intent:
    <activity android:name="com.samplecompany.sampleapp">
       <intent-filter>
          <action android:name="android.intent.action.VIEW"/>
          <category android: name="android.intent.category.DEFAULT"/>
          <category android:name="android.intent.category.BROWSABLE"/>
          <!-- Accept URIs that begin with sampleappname:// -->
          <data android:scheme="sampleappname" />
          <!-- Accept URIs that begin with
                                sampleappname://samplehost/samplepath -->
          <data android:scheme="sampleappname" android:host="samplehost"
                android:path="samplepath" />
       </intent-filter>
    </activity>

    The above intent will handle all URI requests starting with the following: sampleappname://
    Check out Google's own Android developer documentation for more information about intent filter options.

  2. Now, you can add some code to handle custom URIs with arguments, better known as 'Deep Links'.

    You can control which screen a deep link takes a user by adding intents to the different activities in your manifest file, but you can also interpret data from your intents to adjust the user's experience.

    Let's use a sample deep link to see how you can handle arguments in your custom URIs:
     
    sampleappname://samplehost/samplepath

    When a user clicks on the above sample URL, it starts your activity through the intent filter, allowing you to grab arguments from your custom URIs. You can access these arguments by adding your own code to your applicable activity's onCreate() or onStart() methods. Here's an example of accessing information from an intent in an  onCreate() method:
       public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);

          Intent intent = getIntent();
          Uri data = intent.getData();
          // Your specialized code to adjust the user's starting screen
       }

    Based on the above code and our sample deep link, data would contain the different aspects of the handled URI, 'sampleapname://samplehost/samplepath'. Your added code would specify how to handle the contents of this URI and how they would affect the user's starting screen. Please see Google's Android documentation for more information about retrieving info from intents.
support@apsalar.com
http://assets1.desk.com/
apsalarinc
Loading
seconds ago
a minute ago
minutes ago
an hour ago
hours ago
a day ago
days ago
about
Invalid characters found
/customer/en/portal/articles/autocomplete