【问题标题】:Android - Is it possible to get install referrer programmaticallyAndroid - 是否有可能以编程方式安装引荐来源网址
【发布时间】:2015-07-18 03:50:32
【问题描述】:

我注意到浏览器中的一些 Google Play 应用链接具有 referrer= 属性,这显然会告诉引荐来源网址将您发送到 Google Play 中该应用的页面。

是否可以在我的应用程序代码中看到该引荐来源网址(如果有)?如果没有,在任何地方都可以看到它?

【问题讨论】:

    标签: android google-play


    【解决方案1】:

    广告系列参数用于将有关将用户引至您应用的 Google Play 商店页面的广告系列或流量来源的信息传递到您应用的 Google Analytics 实施中。

    创建广告系列参数字符串后,将其作为引荐来源网址参数的值添加到您的 Google Play 商店网址中,如下例所示:

    https://play.google.com/store/apps/details?id=com.example.app
    &referrer=utm_source%3Dgoogle
    %26utm_medium%3Dcpc
    %26utm_term%3Drunning%252Bshoes
    %26utm_content%3DdisplayAd1
    %26utm_campaign%3Dshoe%252Bcampaign
    

    Google Play 商店会将引用参数的值传递给您应用的 Google Analytics 实现。

    参考:https://developers.google.com/analytics/devguides/collection/android/v2/campaigns https://developers.google.com/analytics/devguides/collection/android/v2/campaigns#google-play-url-builder

    【讨论】:

    【解决方案2】:

    您可以使用com.android.vending.INSTALL_REFERRER

    Google Play com.android.vending.INSTALL_REFERRER Intent 是 从 Google Play 商店安装应用时广播。

    将此接收器添加到 AndroidManifest.xml

    <receiver
        android:name="com.example.android.InstallReferrerReceiver"
        android:exported="true"
        android:permission="android.permission.INSTALL_PACKAGES">
        <intent-filter>
            <action android:name="com.android.vending.INSTALL_REFERRER" />
        </intent-filter>
    </receiver>
    

    创建一个广播接收器:

    public class InstallReferrerReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            String referrer = intent.getStringExtra("referrer");
    
            //Use the referrer
        }
    }
    

    您可以按照answer 的步骤测试引荐跟踪。

    【讨论】:

    • 我刚刚更新了答案,提供了一个答案链接,该答案解释了如何测试推荐跟踪。
    • 刚刚做到了,直接从 Eclipse 安装时,我得到“广播完成:结果 = 0”。是这样吗?我是否需要在我的应用或 Google Play 链接中设置任何其他内容才能获得推荐人?
    • 您应该在BroadcastReceiveronReceive 中收到意图。如果您没有收到任何内容,可能是您在 AndroidManifest.xml 中配置接收器时犯了一些错误
    • 从 Google Play 商店安装应用程序时会广播意图。因此,当用户安装您的应用时,Google Play 商店会发送意图,并且您在 onReceiver 中的代码将被执行。
    • 我们可以有除referrer以外的其他参数,比如source吗?
    【解决方案3】:

    使用Google Play Referrer API(从 2017 年 11 月 20 日起)

    InstallReferrerClient mReferrerClient
    ...
    mReferrerClient = newBuilder(this).build();
    mReferrerClient.startConnection(this);
    
    @Override
    public void onInstallReferrerSetupFinished(int responseCode) {
       switch (responseCode) {
           case InstallReferrerResponse.OK:
               try {
                   ReferrerDetails response = mReferrerClient.getInstallReferrer();
                   String referrer = response.getInstallReferrer()
                   mReferrerClient.endConnection();
               } catch (RemoteException e) {
                   e.printStackTrace();
               }
               break;
           case InstallReferrerResponse.FEATURE_NOT_SUPPORTED:
               Log.w(TAG, "InstallReferrer not supported");
               break;
           case InstallReferrerResponse.SERVICE_UNAVAILABLE:
               Log.w(TAG, "Unable to connect to the service");
               break;
           default:
               Log.w(TAG, "responseCode not found.");
       }
    }
    

    【讨论】:

    • 你知道在将APP发布到google play store之前如何测试吗?
    • 我没试过,但是看看这个stackoverflow.com/questions/5890914/…,可能会有所帮助..
    • 我认为该链接不适用于新的 Google Play Referrer API:无法指定 adb 中使用的 BroadcastReceiver。
    • @YingboMiao 你有没有找到测试这个的方法?我找遍了SO,没有找到。
    • API 是否只返回未编码的引用者和参数?
    猜你喜欢
    • 2018-10-14
    • 2020-01-23
    • 1970-01-01
    • 2011-11-21
    • 1970-01-01
    • 1970-01-01
    • 2012-04-21
    • 2012-08-14
    • 1970-01-01
    相关资源
    最近更新 更多