2024-01-19 google play andorid渠道判斷及測(cè)試方法

a.導(dǎo)入包

 implementation 'com.google.android.gms:play-services-analytics:18.0.1'
 implementation 'com.android.installreferrer:installreferrer:2.2'

b.核心代碼
google文檔

  private lateinit var sharedPreference: SharedPreferences
  private lateinit var referrerClient: InstallReferrerClient
  private val refererKey = "global_referer_key"

  private fun initReferer() {
        sharedPreference = getSharedPreferences("MainActivity", Context.MODE_PRIVATE)
        if (sharedPreference.contains(refererKey)) {
            val referrerUrl = sharedPreference.getString(refererKey, "")
              Log.i("ZHP", "referrerUrl:「$referrerUrl」")
        }
        referrerClient = InstallReferrerClient.newBuilder(this).build()
        referrerClient.startConnection(object : InstallReferrerStateListener {
            override fun onInstallReferrerSetupFinished(responseCode: Int) {
                when (responseCode) {
                    InstallReferrerClient.InstallReferrerResponse.OK -> {
                        val response: ReferrerDetails = referrerClient.installReferrer
                        val referrerUrl = response.installReferrer
                        Log.i("ZHP", "referrerUrl:「$referrerUrl」")
                    }

                    InstallReferrerClient.InstallReferrerResponse.FEATURE_NOT_SUPPORTED -> {
                        // API not available on the current Play Store app.
                        Log.i("ZHP", "referrerUrl:organic:FEATURE_NOT_SUPPORTED")
                    }

                    InstallReferrerClient.InstallReferrerResponse.SERVICE_UNAVAILABLE -> {
                        // Connection couldn't be established.
                        Log.i("ZHP", "referrerUrl:organic:SERVICE_UNAVAILABLE")
                    }
                }
            }

            override fun onInstallReferrerServiceDisconnected() {
                // Try to restart the connection on the next request to
                // Google Play by calling the startConnection() method.
                Log.i("ZHP", "referrerUrl:organic:onInstallReferrerServiceDisconnected")
            }
        })
    }

AndroidManifest.xml配置

        <activity>
              ...
        </activity>
        <service android:name="com.google.analytics.tracking.android.CampaignTrackingService" />
        <receiver
            android:name="com.google.analytics.tracking.android.CampaignTrackingReceiver"
            android:exported="true">
            <intent-filter>
                <action android:name="com.android.vending.INSTALL_REFERRER" />
            </intent-filter>
        </receiver>

c 測(cè)試
代碼在google的官網(wǎng)中都有介紹,關(guān)鍵說下測(cè)試流程

  1. 創(chuàng)建一個(gè)測(cè)試鏈接
https://play.google.com/store/apps/details?id=<com.xx.xx>  //yourAppId
&referrer=utm_source%3Dgoogle%26utm_medium%3Dcpc%26utm_term%3Dpodcast%252Bapps%26utm_content%3DdisplayAd1%26utm_campaign%3Dpodcast%252Bgeneralkeywords
  1. 網(wǎng)頁打開測(cè)試鏈接,正確彈出你的app頁面
  2. 點(diǎn)擊在google play中打開(記得提前卸載app)
  3. 在google play下載頁面,選擇adb或者as安裝debug包
    adb install -r app-debug.apk 
  1. 安裝成功后在google play頁面點(diǎn)擊啟動(dòng)

備注:如果google play的賬號(hào)之前測(cè)訂閱等問題被加入為測(cè)試賬號(hào),要?jiǎng)?chuàng)建一個(gè)新的google賬號(hào)來測(cè)試,不然refererUrl還是拿不到

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容