我需要在我的 android 应用程序中获取 GCLID
I'm need to get GCLID inside my android app
我需要在我的 android 应用程序中获取 GCLID 值。我发现的是 Play Install Referrer Library,returns 我是一个 utm 标签,但我不确定 GCLID 值是否在 val referrer = response.installReferrer
内
代码示例:
fun getGCLID(){
referrerClient = InstallReferrerClient.newBuilder(this).build()
referrerClient.startConnection(object : InstallReferrerStateListener {
override fun onInstallReferrerSetupFinished(responseCode: Int) {
when (responseCode) {
InstallReferrerClient.InstallReferrerResponse.OK -> {
// Connection established.
val response: ReferrerDetails = referrerClient.installReferrer
val referrer = response.installReferrer
val clickTimestamp = response.referrerClickTimestampSeconds
val installTimestamp = response.installBeginTimestampSeconds
Log.d("TagGCLID", "onInstallReferrerSetupFinished: 1")
if ("gclid" in referrer) {
Log.d("TagGCLID", "GCLID is detected in referrer // is $referrer")
//report to Firebase Analytics
} else {
Log.d("TagGCLID", "no GCLID is detected in referrer\n" +
"$referrer")
//do something else
}
}
InstallReferrerClient.InstallReferrerResponse.FEATURE_NOT_SUPPORTED -> {
Log.d("TagGCLID", "InstallReferrerResponse: -1")
// API not available on the current Play Store app.
}
InstallReferrerClient.InstallReferrerResponse.SERVICE_UNAVAILABLE -> {
Log.d("TagGCLID", "InstallReferrerResponse: -2")
// Connection couldn't be established.
}
}
}
override fun onInstallReferrerServiceDisconnected() {
Log.d("TagGCLID", "onInstallReferrerServiceDisconnected: -3")
// Try to restart the connection on the next request to
// Google Play by calling the startConnection() method.
}
})
}
我应该怎么做才能获得 GCLID 值?
是的,我也有类似的问题,如果用户从浏览器切换到play市场,我可以得到这个gclid,但是如果广告是在play市场本身点击的,那么gclid就不会传输.您的方法编写正确,但只有在用户通过浏览器时才有效。
我需要在我的 android 应用程序中获取 GCLID 值。我发现的是 Play Install Referrer Library,returns 我是一个 utm 标签,但我不确定 GCLID 值是否在 val referrer = response.installReferrer
代码示例:
fun getGCLID(){
referrerClient = InstallReferrerClient.newBuilder(this).build()
referrerClient.startConnection(object : InstallReferrerStateListener {
override fun onInstallReferrerSetupFinished(responseCode: Int) {
when (responseCode) {
InstallReferrerClient.InstallReferrerResponse.OK -> {
// Connection established.
val response: ReferrerDetails = referrerClient.installReferrer
val referrer = response.installReferrer
val clickTimestamp = response.referrerClickTimestampSeconds
val installTimestamp = response.installBeginTimestampSeconds
Log.d("TagGCLID", "onInstallReferrerSetupFinished: 1")
if ("gclid" in referrer) {
Log.d("TagGCLID", "GCLID is detected in referrer // is $referrer")
//report to Firebase Analytics
} else {
Log.d("TagGCLID", "no GCLID is detected in referrer\n" +
"$referrer")
//do something else
}
}
InstallReferrerClient.InstallReferrerResponse.FEATURE_NOT_SUPPORTED -> {
Log.d("TagGCLID", "InstallReferrerResponse: -1")
// API not available on the current Play Store app.
}
InstallReferrerClient.InstallReferrerResponse.SERVICE_UNAVAILABLE -> {
Log.d("TagGCLID", "InstallReferrerResponse: -2")
// Connection couldn't be established.
}
}
}
override fun onInstallReferrerServiceDisconnected() {
Log.d("TagGCLID", "onInstallReferrerServiceDisconnected: -3")
// Try to restart the connection on the next request to
// Google Play by calling the startConnection() method.
}
})
}
我应该怎么做才能获得 GCLID 值?
是的,我也有类似的问题,如果用户从浏览器切换到play市场,我可以得到这个gclid,但是如果广告是在play市场本身点击的,那么gclid就不会传输.您的方法编写正确,但只有在用户通过浏览器时才有效。