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

如何确认应用是否通过DeepLink/ReferLink安装并获取来源链接?

如何追踪DeepLink来源并传递Intent(Firebase/AppsFlyer/原生方案)

嘿,我来帮你把这个需求拆解清楚——完全可以实现!不管是用Firebase、AppsFlyer这类第三方归因工具,还是原生Android技术,都能搞定「用户从DeepLink/推荐链接跳转到Play商店安装App后,追踪来源、获取原始DeepLink并传递对应Intent」的需求。下面分情况给你详细说明:

一、第三方归因工具方案(省心首选)

这类工具已经封装好了全链路的归因逻辑,不用自己造轮子,是最推荐的方式。

Firebase的动态链接(Dynamic Links)专门解决这种跨场景的跳转与追踪需求:

  • 配置步骤:在Firebase控制台绑定你的App,创建Dynamic Link时设置跳转规则:用户未安装App时跳Play商店,已安装则直接打开App并携带参数。
  • 获取DeepLink并传递Intent:用户安装后首次打开App,Firebase会自动把原始DeepLink数据传递过来。你可以在启动Activity的onCreate方法里获取并处理:
// 在MainActivity的onCreate中添加
FirebaseDynamicLinks.getInstance()
    .getDynamicLink(intent)
    .addOnSuccessListener(this) { pendingDynamicLinkData ->
        pendingDynamicLinkData?.link?.let { deepLink ->
            // 拿到用户最初点击的DeepLink,生成对应Intent
            val targetIntent = Intent(this, CarDetailActivity::class.java)
            targetIntent.data = deepLink // 把DeepLink作为Intent的data传递
            startActivity(targetIntent)
        }
    }
    .addOnFailureListener(this) { e ->
        // 处理获取失败的情况,比如打印日志
        Log.e("FirebaseDL", "获取动态链接失败: ${e.message}")
    }

AppsFlyer的OneLink是专门做移动归因的解决方案,支持多渠道追踪:

  • 核心逻辑:在AppsFlyer后台创建OneLink,配置跳转规则(未安装跳Play商店,已安装打开App)。用户点击OneLink后,所有归因数据会被记录。
  • 获取归因数据并传递Intent:App首次启动时,通过监听回调获取原始DeepLink:
// 在Application类或启动Activity中初始化后添加监听
AppsFlyerLib.getInstance().registerConversionListener(getApplicationContext(), new AppsFlyerConversionListener() {
    @Override
    public void onConversionDataSuccess(Map<String, Object> conversionData) {
        String deepLink = (String) conversionData.get("deep_link");
        if (deepLink != null) {
            // 生成目标Intent并启动
            Intent targetIntent = new Intent(getApplicationContext(), CarDetailActivity.class);
            targetIntent.setData(Uri.parse(deepLink));
            targetIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(targetIntent);
        }
    }

    @Override
    public void onConversionDataFail(String errorMessage) {
        Log.e("AppsFlyer", "归因失败: " + errorMessage);
    }

    @Override
    public void onAppOpenAttribution(Map<String, String> attributionData) {
        // 处理已安装用户通过OneLink打开App的情况
    }

    @Override
    public void onAttributionFailure(String errorMessage) {
        Log.e("AppsFlyer", "归因监听失败: " + errorMessage);
    }
});

二、原生Android技术方案(无第三方依赖)

如果不想依赖第三方工具,可以用Play商店的Referrer API自己实现归因,不过需要手动处理参数编码和解码:

  • 原理:把DeepLink的关键信息编码后作为referrer参数附加到Play商店跳转链接中,用户安装App后,通过Referrer API获取这个参数,解码得到原始DeepLink。
  • 具体步骤:
    1. 生成带referrer的Play商店链接:比如你的DeepLink是mycarapp://detail?carId=123,编码后生成链接:
      https://play.google.com/store/apps/details?id=com.your.carapp&referrer=deeplink%3Dmycarapp%253A%252F%252Fdetail%253FcarId%253D123
    2. 在App中获取并解析referrer:推荐使用Google官方的Install Referrer Library(比广播更可靠):
// 先添加依赖:implementation 'com.android.installreferrer:installreferrer:2.2'
val referrerClient = InstallReferrerClient.newBuilder(this).build()
referrerClient.startConnection(object : InstallReferrerStateListener {
    override fun onInstallReferrerSetupFinished(responseCode: Int) {
        when (responseCode) {
            InstallReferrerClient.InstallReferrerResponse.OK -> {
                val response = referrerClient.installReferrer
                val referrer = response.installReferrer
                // 解码referrer得到原始DeepLink
                val decodedDeepLink = URLDecoder.decode(referrer.split("deeplink=")[1], "UTF-8")
                // 生成Intent并跳转
                val targetIntent = Intent(this@MainActivity, CarDetailActivity::class.java)
                targetIntent.data = Uri.parse(decodedDeepLink)
                startActivity(targetIntent)
                referrerClient.endConnection()
            }
            InstallReferrerClient.InstallReferrerResponse.FEATURE_NOT_SUPPORTED -> {
                Log.e("Referrer", "设备不支持Install Referrer API")
            }
            InstallReferrerClient.InstallReferrerResponse.SERVICE_UNAVAILABLE -> {
                Log.e("Referrer", "Install Referrer服务不可用")
            }
        }
    }

    override fun onInstallReferrerServiceDisconnected() {
        // 服务断开时尝试重新连接
        referrerClient.startConnection(this)
    }
})
  • 注意:原生方案的局限性在于,若用户通过无referrer的渠道安装App,就无法追踪;且referrer参数有长度限制,编码时需注意。

三、关键场景验证(汽车广告案例)

以你提到的场景为例,完整流程是:

  1. 用户未安装汽车App,点击广告中的DeepLink → 被引导至带归因参数的Play商店链接
  2. 用户安装并打开App → 工具/原生代码获取到原始DeepLink
  3. App解析DeepLink中的参数(比如车型ID),生成对应Intent跳转到车型详情页

几个重要提醒

  • 确保App在Play商店的签名与Firebase/AppsFlyer配置的签名一致,否则归因会失败。
  • 集成第三方SDK时,记得添加必要的权限(比如网络权限)。
  • 原生方案的广播接收方式可能被部分厂商ROM拦截,优先用Install Referrer Library。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 06:55:13