StageUp
Mobile SDKDeep Link

Unity Deep Link

1. Overview

  • The AdStage Unity SDK provides deep link reception/handling and link creation across Android/iOS.
  • Ensure platform prerequisites are configured: Android (App Links), iOS (Universal Links/URL Schemes).

Notes

  • Android: intent filters in AndroidManifest, link domain/scheme configuration
  • iOS: URL Schemes in Info.plist, Associated Domains (AASA)

By default, the AdStage Unity SDK uses NBaseUnityActivity (Assets/Plugins/Android/src/com/nbase/unity/NBaseUnityActivity.java). If you use a custom Activity, add the following code:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    
    nbaseWrapper = new NBaseAndroidWrapper();
    nbaseWrapper.setAdStageApiKey("YOUR_API_KEY");
    nbaseWrapper.setUnifiedListener();
}
 
@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    setIntent(intent);
    
    if (nbaseWrapper != null) {
        nbaseWrapper.handleDeepLinkIntent(intent);
    }
}

By default, UnityAppController (Assets/NBaseSDK/Plugins/iOS/Source/NBaseAppController.mm) is used. If you use a custom AppController, add the following code:

@implementation NBaseUnityAppController

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [[NBaseUnityPlugin shared] setAdStageApiKey:@"YOUR_API_KEY" :nil];
    [[NBaseUnityPlugin shared] setAdStageUnifiedListener:^(AdStageDeepLink *deepLink) {
        // Handle deep link
    }];
    
    return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options {
    return [[NBaseUnityPlugin shared] handleAdStageDeepLink:url];
}

- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray *))restorationHandler {
    if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
        return [[NBaseUnityPlugin shared] handleAdStageUniversalLink:userActivity];
    }
    return [super application:application continueUserActivity:userActivity restorationHandler:restorationHandler];
}

Implement an event listener in your Unity scene to receive and route deep links.

using UnityEngine;
using NBaseSDK;
using System.Collections.Generic;
 
public class AdStageListener : MonoBehaviour, NBaseEventListener
{
    void Start()
    {
        DontDestroyOnLoad(this.gameObject);
        NBaseSDK.NBase.SetEventListener(this);
    }
 
    public void OnAdStageDeepLink(NBaseSDK.NBase.AdStageDeepLink deepLink)
    {
        Debug.Log($"Deep link received: {deepLink.Path}");
        Debug.Log($"Event type: {deepLink.EventType}");
 
        foreach (var param in deepLink.Parameters)
        {
            Debug.Log($"Parameter: {param.Key} = {param.Value}");
        }
 
        HandleDeepLink(deepLink);
    }
 
    private void HandleDeepLink(NBaseSDK.NBase.AdStageDeepLink deepLink)
    {
        switch (deepLink.EventType)
        {
            case "OPEN":
                // TODO: Route on open
                break;
            case "INSTALL":
                // TODO: Route after first open post-install
                break;
        }
    }
}

Create a complete deep link in-app and receive the result via callback.

public void CreateCompleteAdStageDeepLink()
{
    var customParameters = new Dictionary<string, object>
    {
        {"level", 10},
        {"stage", "boss_battle"},
        {"reward_type", "gold"},
        {"amount", 1000}
    };
 
    NBaseSDK.NBase.createAdStageDeepLink(
        name: "Special Event Link",
        description: "Boss Battle Event Promotion",
        channel: "facebook",
        campaign: "summer_event_2024",
        adGroup: "boss_battle_ads",
        creative: "boss_banner_v1",
        content: "special_reward",
        keyword: "boss,event,reward",
        parameters: customParameters,
        androidPackageName: "com.yourcompany.yourgame",
        androidAppScheme: "yourgame://",
        androidWebUrl: "https://yourgame.com/android",
        iosAppStoreId: "123456789",
        iosAppScheme: "yourgame://",
        iosWebUrl: "https://yourgame.com/ios",
        webUrl: "https://yourgame.com/web",
        completionHandler: (shortUrl, error) =>
        {
            if (error != null)
            {
                Debug.LogError($"Deep link creation failed: {error.message}");
                return;
            }
            Debug.Log($"Deep link created successfully: {shortUrl}");
        }
    );
}

6. Notes

  • Call setAdStageApiKey() at app startup.
  • Ensure Android/iOS lifecycle callbacks are added in the correct locations.
  • Verify domain/scheme registration in AndroidManifest and Info.plist.

Table of Contents