As per the documentation google, Chrome Custom Tabs support app as the referrer. But when I checked on google analytics the traffic not refer to the app it's showing as direct. Resource: https://developer.chrome.com/multidevice/android/customtabs#add-your%20app%20as%20the%20referrer
Here is my code:
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))
}
My query is there anything I missed or any way to get a referral on google analytics.
So first thing first, I spent a lot of time thinking about the problem and tried a lot of things. So what I observed is this
The URL that I tried was https://www.whatismybrowser.com/ it just shows the referrer.
Snippet 1: In my first attempt, I used this one
customTabsIntent.intent.putExtra(Intent.EXTRA_REFERRER,"android-app://"+context.packageName)
but the site didn't show me the referrer at all. I said No Referrer / Hidden
Snippet 2: So Next I tried this one
customTabsIntent.intent.putExtra(Intent.EXTRA_REFERRER_NAME,"android-app://"+context.packageName)
by using EXTRA_REFERRER_NAME I was able to see the referrer i.e my package to be clear android-app://com.mypackage.something/
So, Now I replaced https://www.whatismybrowser.com/ with my original website which is already linked with google analytics account I was expecting it to show the traffic source as my app package name but unfortunately for no reason, I still got the traffic as direct instead of my package
So what is the alternative for this one?
So, I checked this blog : A Handy Guide to UTM Codes: Know Which of Your Campaigns Really Work
So, What they mentioned is just use utm_source & utm_medium in the URL while launching the URL using chrome custom tabs
I tried like this
browseUrlCustomTab(this,"https://www.mysitename.com?utm_medium=MyAndroidApp&utm_source=in.mypackage.app")
and it worked the package name shown up in the google analytics
My Conclusion:
I guess it is something to do with the google analytics itself. Because the https://www.whatismyreferer.com/ site shows the referrer i.e my package when I used the second snippet
So I guess and my assumption is, either I must setup google analytics account not properly or this EXTRA_REFERRER thing mentioned in docs is no more working.
And I don't know the workaround I mentioned is good or bad and I know nothing about its pros and cons. But I believe it would work as expected