Unity SDK: Implementing Deep Links

Singular Unity SDK
Download
Singular Unity SDK version 1.3.8
Compatibility Unity 4.7.2+
Sample App Review our sample app for an example of a complete SDK integration based on best practices.
Integration Guides
  1. Basic Integration
  2. Tracking Events and Revenue
  3. Implementing Deep Links
  4. Advanced Options

 

Introduction

Deep links are links that lead into specific content inside an app. When a user clicks a deep link on a device that has the app installed, the app opens and shows a specific product or experience.

Singular tracking links can include deep linking as well as deferred deep linking (see our Deep Linking FAQ and the Singular Links FAQ for more information).

The instructions below will show you how to:

  1. Access the tracking link that led to your app being opened,
  2. Read the deep link destination, and
  3. Show the appropriate content.

Notes:

  • This article assumes your organization is using Singular Links - Singular's new tracking link technology, launched in 2019. Older customers of Singular may be using Singular's older tracking links (legacy links). To support deep linking with legacy links, see Handling Deep Links with Legacy Links.
  • The deep link destinations for your app need to be set up on the Apps page in Singular (see Configuring Deep Link URLs).

Deep Linking Prerequisites

iOS and Android Setup

Follow the instructions in Singular Links Prerequisites to enable deep linking.

Additional Setup for Unity

In the app’s AndroidManifest.xml file, change the activity name property from the default UnityPlayerActivity (e.g., <activity android:name="net.singular.unitysdk.UnityPlayerActivity">) to SingularUnityActivity:

<activity android:name="com.singular.unitybridge.SingularUnityActivity">

If you've implemented your own custom activity, just call this method in the onNewIntent in your activity:

@Override
protected void onNewIntent(Intent intent) {
    setIntent(intent);

    // Call this method from your custom activity in onNewIntent
    SingularUnityBridge.onNewIntent(intent);
}

Handling Deep Links

The Singular SDK provides a handler mechanism to read the details of the tracking link that led to the app being opened.

To use the handler:

  1. Implement the SingularLinkHandler interface.
  2. Call the SetSingularLinkHandler method at any point in the class to register the class as the handler for deep links.
  3. When you call SetSingularLinkHandler, the Singular SDK fetches the tracking link and calls the OnSingularLinkResolved method, passing the tracking link details to it. Override this method to read the link details and process them.

The following sample code shows the three steps:

public class Main : SingularLinkHandler {
    // ...
    void Awake () {
      // Register the class as the Singular Link handler.
      // You can call this method at any point in the app's run. It will fetch the tracking link details and call OnSingularLnkResolved.
      SingularSDK.SetSingularLinkHandler(this);
    }
    
    public void OnSingularLinkResolved(SingularLinkParams linkParams) {
      // The deep link destination, as configured in the Manage Links page
      string deeplink = linkParams.Deeplink;
      
      // The passthrough parameters added to the link, if any.
      string passthrough = linkParams.Passthrough;
      
      // Whether the link configured as a deferred deep link.
      bool isLinkDeferred = linkParams.IsDeferred;
      
      // Add code here to process the deeplink
    }
    
    // ...

 

SetSingularLinkHandler Method Details
Description Register a handler that retrieves the details of the tracking link that led to the opening of the app.
Signature
public void SetSingularLinkHandler(SingularLinkHandler 
handler)
Usage Example
public class Main : MonoBehaviour, SingularLinkHandler {
    void Awake () {
        SingularSDK.SetSingularLinkHandler(this)
    }
}
OnSingularLinkResolved Method Details
Description Callback method for SetSingularLinkHandler. Read the tracking link details and process them.
Signature
public void OnSingularLinkResolved(SingularLinkParams
linkParams)

Note: The SingularLinkParams object contains the following values:

    • Deeplink - The deep link destination, as configured in the Manage Links page in the Singular platform.
  • Passthrough - Passthrough parameters added to the link, if any.
  • IsDeferred - Is the link configured as a deferred deep link.
Usage Example
public void OnSingularLinkResolved(SingularLinkParams
linkParams){ // Read the tracking link details and log them Debug.Log("deeplink: " + linkParams.Deeplink); Debug.Log("passthrough: " + linkParams.Passthrough); Debug.Log("is_deferred: " + linkParams.IsDeferred); }

Handling Deep Links with Legacy Links

If you are an older Singular customer, you may be using legacy tracking links (Singular's older tracking link mechanism) rather than the newer Singular Links. Legacy links are managed in the Create Link and View Links pages, and they also provide deep linking and deferred deep linking functionality.

If your organization uses legacy links, you need to implement a handler for deep links called SingularDeferredDeepLinkHandler instead of the SingularLinksHandler described above. The implementation is very similar.

Was this article helpful?
0 out of 0 found this helpful