android - 如何在我的 Android 应用中获取 Google 点击 ID (gclid)?
问题描述
我在 google adsense 中有一个针对我的 android 应用程序的广告,我知道当用户点击广告时,google 会创建包含用户信息的链接以进行跟踪。所以我想在其中获取该链接和 gclid 参数。我怎样才能做到这一点?
我已经尝试使用意图和 google play install referrer 来执行此操作,但意图返回 null,并且 google play install referrer 返回空字符串或有时 FEATURE_NOT_SUPPORTED
这是我获取代码的意图:
val intent = this.intent
val uri = intent?.data
urlFromIntent = uri.toString()
显现:
<receiver android:name="com.google.android.gms.analytics.CampaignTrackingReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
<service android:name="com.google.android.gms.analytics.CampaignTrackingService"
android:enabled="true"
android:exported="false" />
而我的 google play 安装引用代码:
mRefferClient = InstallReferrerClient.newBuilder(this).build()
mRefferClient.startConnection(object : InstallReferrerStateListener {
@SuppressLint("SwitchIntDef")
override fun onInstallReferrerSetupFinished(responseCode: Int) {
when (responseCode) {
InstallReferrerClient.InstallReferrerResponse.OK -> {
try {
if (BuildConfig.DEBUG) Log.d("InstallReferrerState", "OK")
var response = mRefferClient.installReferrer
urlFromReferClient = response.installReferrer
urlFromReferClient += ";" + response.referrerClickTimestampSeconds
urlFromReferClient += ";" + response.installBeginTimestampSeconds
mRefferClient.endConnection()
} catch (e: RemoteException) {
urlFromReferClient = e.toString()
}
}
InstallReferrerClient.InstallReferrerResponse.FEATURE_NOT_SUPPORTED -> {
urlFromReferClient = "FEATURE_NOT_SUPPORTED"
}
InstallReferrerClient.InstallReferrerResponse.SERVICE_UNAVAILABLE -> {
urlFromReferClient = "SERVICE_UNAVAILABLE"
}
}
}
override fun onInstallReferrerServiceDisconnected() {
// Try to restart the connection on the next request to
// Google Play by calling the startConnection() method.
}
})
解决方案
推荐阅读
- spring-boot - 不知道为什么我会收到模板解析错误
- url - 来自 GPS 追踪器 URL 的经纬度
- c++ - Git Bash 上的 MINGW64 是什么意思?
- php - PHPWord/templateProcessor 打开文档,替换模板中的占位符但保存一个空文档
- python - 如何在大多数数据框值中抑制科学记数法?
- bluetooth-lowenergy - 如何使用 BLE 唤醒设备?两个设备必须具备什么配置文件才能实现这一点?
- python - 从屏幕识别和记录数据
- spring - JPA @one-to-many // 重写存储的 ID
- mono.cecil - 在 Mono.Cecil 中如何识别覆盖抽象基类方法的方法?
- javascript - 子模块中的变量