You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Unity集成AppsFlyer OneLink深层链接时onDeepLink回调未触发

AppsFlyer Unity集成:OnDeepLink回调未触发问题排查

问题描述

在Unity项目中集成AppsFlyer,通过OneLink处理深层链接,目标是捕获应用通过链接打开时的深层链接数据。已按文档完成SDK初始化、注册深层链接事件处理器、启动SDK等配置,但测试时使用深层链接打开应用,仅触发onConversionDataSuccess回调,onDeepLink回调完全未执行。应用能正常通过链接打开,onConversionDataSuccess能正确打印转换数据,说明SDK已正常初始化并工作。

相关代码

挂载在AppsFlyerObject GameObject上的脚本代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using AppsFlyerSDK;
using System;

namespace Example
{
    public class ExamplerAppsFlyerObjectScript : MonoBehaviour
    {
        void Start()
        {
            Debug.Log("AppsFlyerObjectScript Start");
            AppsFlyer.initSDK("devKey", "AppId", this);
            AppsFlyer.OnDeepLinkReceived += onDeepLink;
            AppsFlyer.startSDK();
        }

        void onDeepLink(object sender, EventArgs args)
        {
            Debug.Log("OnDeepLink Start");

            if (!(args is DeepLinkEventsArgs deepLinkEventArgs)) return;

            string campaign = deepLinkEventArgs.getCampaign();
            string mediaSource = deepLinkEventArgs.getMediaSource();
            Debug.Log($"Campaign: {campaign}, Media Source: {mediaSource}");

            Debug.Log($"DeepLink Status: {deepLinkEventArgs.status.ToString()}");

            switch (deepLinkEventArgs.status)
            {
                case DeepLinkStatus.FOUND:

                    if (deepLinkEventArgs.isDeferred())
                    {
                        Debug.Log("OnDeepLink: This is a deferred deep link");
                    }
                    else
                    {
                        Debug.Log("OnDeepLink: This is a direct deep link");
                    }

                    var deepLinkParamsDictionary = GetDeepLinkParamsDictionary(deepLinkEventArgs);
                    if (deepLinkParamsDictionary != null)
                    {
                        ParseDeepLinkParams(deepLinkParamsDictionary);
                    }
                    break;

                case DeepLinkStatus.NOT_FOUND:
                    Debug.Log("OnDeepLink: Deep link not found");
                    _deepLinkParamsDictionary = new Dictionary<string, object> { ["deep_link_not_found"] = true };
                    break;

                default:
                    Debug.Log("OnDeepLink: Deep link error");
                    _deepLinkParamsDictionary = new Dictionary<string, object> { ["deep_link_error"] = true };
                    break;
            }
        }

        // Other methods omitted for brevity
    }
}

AndroidManifest.xml深层链接配置

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="AppID">
    <application>
        <activity android:name="com.unity3d.player.UnityPlayerActivity">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="https" android:host="OneLinkWhichWorks" />
            </intent-filter>
        </activity>
    </application>
</manifest>

已检查项

  • AppsFlyer SDK已使用正确的dev key和app ID初始化
  • 深层链接事件处理器已在AppsFlyer.startSDK()之前注册
  • AndroidManifest.xml已正确配置深层链接

排查建议

  • 启用Unified Deep Link模式:检查AppsFlyer后台的OneLink配置,确认已启用Unified Deeplink选项,确保深层链接数据能正确传递到SDK。
  • 调整回调注册时机:将AppsFlyer.OnDeepLinkReceived += onDeepLink移到Awake()方法中执行,避免Start()方法执行顺序问题导致注册不及时。
  • 验证Intent原始数据:添加代码直接获取Android Intent中的深层链接数据,确认系统层面是否正确传递链接:
    void Start()
    {
        #if UNITY_ANDROID && !UNITY_EDITOR
        AndroidJavaClass intentClass = new AndroidJavaClass("android.content.Intent");
        AndroidJavaObject intent = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic<AndroidJavaObject>("currentActivity").Call<AndroidJavaObject>("getIntent");
        string action = intent.Call<string>("getAction");
        if (action.Equals("android.intent.action.VIEW"))
        {
            AndroidJavaObject uri = intent.Call<AndroidJavaObject>("getData");
            if (uri != null)
            {
                string deepLinkUrl = uri.Call<string>("toString");
                Debug.Log("Raw deep link from Intent: " + deepLinkUrl);
            }
        }
        #endif
    }
    
    若能拿到原始链接,说明问题出在SDK处理环节;若拿不到,需检查Manifest配置或链接格式。
  • 测试链接传递:使用adb命令直接触发深层链接,排除浏览器或其他应用拦截的可能:
    adb shell am start -W -a android.intent.action.VIEW -d "https://your-onelink-host.com/your-path" com.your.app.package
    
  • 开启调试日志:在SDK初始化前添加AppsFlyer.setDebugLog(true);,查看日志中关于深层链接处理的细节,是否存在检测或解析错误。
  • 检查延迟深层链接数据:若用户是点击链接后下载安装应用再打开(延迟深层链接),onConversionDataSuccess返回的数据中可能包含af_dp字段(深层链接信息),需在该回调中处理这类场景。
  • 确认版本兼容性:验证当前AppsFlyer Unity SDK版本与Unity 2020.3 LTS是否存在已知兼容性问题,必要时尝试降级或升级SDK版本。

内容的提问来源于stack exchange,提问作者Patrick Whelan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 04:47:07