Skip to content

Deferred deep linking

optimove-andy edited this page Feb 22, 2024 · 6 revisions

Deep linking allows users to reach app content by clicking a link. This can be achieved even if the app is not installed.

Setup in Optimove

Go to settings and select 'Configuration' under the 'Deferred Deep Linking' heading to start.

Click 'Edit Configurations'

Enter the subdomain (of the lnk.click domain) that you want to use for your Deferred Deep Links.

To use Deferred Deep Links with your Android app, toggle the switch next to Android Config on. Enter the URL to your app in the Play Store, the Package for your app and the colon separated, SHA256 signing certificate fingerprint(s).

Note that if you are publishing to Google Play and app signing by Google Play is enabled, you need to add two SHA256 fingerprints: one obtained from signing APK locally and one obtained from Google Play console. Fingerprints are necessary for deep linking into your app without showing a disambiguation dialog.

************** Android **************

Add an intent filter to your main activity:

<intent-filter android:label="deepLabel" android:autoVerify="true">
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <!-- Specify which URIs should be matched. Note, domain should be .lnk.click -->
    <data android:scheme="https" android:host="subdomain.lnk.click"/>
</intent-filter>

Note that the subdomain you specify above should match the one you specified on the deep link configuration page on the Optimove UI.

Note that setting android:autoVerify="true" will verify ownership of the domain, so, instead of offering a list of apps to select from your app will open automatically. No further actions are needed to enable this.

Add following overrides to the main activity:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Optimove.getInstance().seeIntent(getIntent(), savedInstanceState);
}

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    Optimove.getInstance().seeInputFocus(hasFocus);
}

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    Optimove.getInstance().seeIntent(intent);
}

Configure a deep link handler:

OptimoveConfig config = new OptimoveConfig.Builder(
    "<YOUR_OPTIMOVE_CREDENTIALS>","<YOUR_OPTIMOVE_MOBILE_CREDENTIALS>"
    ).enableDeepLinking(null, new MyDeferredDeepLinkHandler())
    .build());

Optimove.initialize(this, config);

A stub implementation of the handler could be as follows:

public class MyDeferredDeepLinkHandler implements DeferredDeepLinkHandlerInterface {
    public void handle(Context context, DeferredDeepLinkHelper.DeepLinkResolution resolution, String link, @Nullable DeferredDeepLinkHelper.DeepLink data){
       //- Inspect the data payload and run code as needed.
   }
}

************** iOS **************

First, you need to associate a domain with your app. Note that the subdomain you specify here should match the one you specified on the deep link configuration page in the Optimove UI.

Add the Associated Domains capability to your main app target. Set 'domains' to applinks:{yourSubdomain}.lnk.click

Next, add the following to the AppDelegate.swift in your native project:

override func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
        return Optimove.shared.application(application, continue: userActivity, restorationHandler: restorationHandler)
    }
}