android - Chrome 自定义标签 EXTRA_REFERRER 不起作用

标签 android kotlin webview google-analytics chrome-custom-tabs

根据 Google 文档,Chrome 自定义标签支持应用程序作为引荐来源网址。但当我检查谷歌分析时,流量并未指向应用程序,它显示为直接。资源:https://developer.chrome.com/multidevice/android/customtabs#add-your%20app%20as%20the%20referrer

这是我的代码:

fun browseUrlCustomTab(context: Context, url: String) {
        var url = url
        if (!url.startsWith("http") && !url.startsWith("https"))
            url = "http://$url"
        val builder = CustomTabsIntent.Builder()
                .addDefaultShareMenuItem()
                .setToolbarColor(ContextCompat.getColor(context, getThemePrimaryDarkColor()))
                .setShowTitle(true)
                .enableUrlBarHiding()
                //.setStartAnimations(context, android.R.anim.slide_in_right, R.anim.slide_out_left)
                .setExitAnimations(context, android.R.anim.slide_in_left, android.R.anim.slide_out_right)
                .setCloseButtonIcon(getBitmapFromVectorDrawable(context, R.drawable.ic_back)!!)
        val customTabsIntent = builder.build()
        customTabsIntent.intent.setPackage("com.android.chrome")
        //customTabsIntent.intent.flags = Intent.FLAG_ACTIVITY_NO_HISTORY or Intent.FLAG_ACTIVITY_NEW_TASK
        customTabsIntent.intent.putExtra(Intent.EXTRA_REFERRER,
                Uri.parse(""+Intent.URI_ANDROID_APP_SCHEME + "//" + context.packageName))
        customTabsIntent.launchUrl(context, Uri.parse(url))
    }

我的疑问是我错过了什么,或者有什么方法可以在 Google Analytics 上获得推荐。

最佳答案

首先,我花了很多时间思考这个问题并尝试了很多东西。所以我观察到的是这样的

我尝试的 URL 是 https://www.whatismybrowser.com/它只显示引荐来源网址。

fragment 1:在我的第一次尝试中,我使用了这个

customTabsIntent.intent.putExtra(Intent.EXTRA_REFERRER,"android-app://"+context.packageName)

但该网站根本没有向我显示推荐人。我说无推荐人/隐藏

fragment 2:接下来我尝试了这个

customTabsIntent.intent.putExtra(Intent.EXTRA_REFERRER_NAME,"android-app://"+context.packageName)

通过使用 EXTRA_REFERRER_NAME 我能够清楚地看到引荐来源网址,即我的包裹 android-app://com.mypackage.something/

所以,现在我替换了 https://www.whatismybrowser.com/我的原始网站已经与谷歌分析帐户链接,我希望它将流量源显示为我的应用程序包名称,但不幸的是,无缘无故,我仍然直接获得流量而不是我的包

那么这个的替代方案是什么?

所以,我检查了这个博客:A Handy Guide to UTM Codes: Know Which of Your Campaigns Really Work

所以,他们提到的只是在使用 chrome 自定义选项卡启动 URL 时在 URL 中使用 utm_source 和 utm_medium

我尝试过这样

browseUrlCustomTab(this,"https://www.mysitename.com?utm_medium=MyAndroidApp&utm_source=in.mypackage.app")

它的工作原理是在谷歌分析中显示包名称

enter image description here

我的结论:

我想这与谷歌分析本身有关。因为https://www.whatismyreferer.com/网站显示引荐来源网址,即我使用第二个 fragment 时的包

所以我猜想,我的假设是,要么我必须不正确地设置谷歌分析帐户,要么docs中提到的EXTRA_REFERRER事情。不再工作了。

而且我不知道我提到的解决方法是好是坏,我对其优缺点一无所知。但我相信它会按预期工作

关于android - Chrome 自定义标签 EXTRA_REFERRER 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63194589/

相关文章:

android - Unity GoogleMobileAdsMediationTestSuite 抛出异常 setAdListener 必须在主 UI 线程上调用

Android firestore RecyclerView 正在加载错误的图像

java - 用 spock 模拟的值不会转移到 Kotlin 吗?

android - 如何在 android webview 中使用代码发送 POST 数据

Android : 5. 0 : WebChromeClient. FileChooserParams 无法解析为类型

java - Dagger 2 单例组件依赖于单例

java - GSON JsonSyntaxException 反序列化 Java 日期对象

javascript - Android Cordova插件开发-JS接口(interface)错误

java - 使用 java lambda 调用 kotlin 函数时,Kotlin 无法访问 kotlin.jvm.functions.Function1

java - Raspberry Pi 2 Java - 无法加载主类/未找到类 WebView