如何在我的 Android 应用程序中获取 Google 点击 id (gclid)?

gat*_*ura 5 android google-analytics adsense firebase google-ads-api

我在 google adsense 中有一个针对我的 android 应用程序的广告,我知道当用户点击广告时,谷歌会创建包含用户跟踪信息的链接。所以我想获取其中的链接和 gclid 参数。我怎样才能做到这一点?

我已经尝试使用意图和谷歌播放安装引荐来源网址来做到这一点,但意图返回 null,并且谷歌播放安装引荐来源网址返回空字符串或有时 FEATURE_NOT_SUPPORTED

这是我的意图获取代码:

        val intent = this.intent
        val uri = intent?.data
        urlFromIntent = uri.toString()
Run Code Online (Sandbox Code Playgroud)

显现:

       <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" />
Run Code Online (Sandbox Code Playgroud)

我的谷歌播放安装引荐来源代码:


        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.
            }
        })

Run Code Online (Sandbox Code Playgroud)