测试Google Play安装推荐人库

时间:2018-02-28 23:00:50

标签: java android google-analytics google-play install-referrer

我希望从收听Play商店的INSTALL_REFERRER意图迁移到使用新的Google Play Install Referrer Library

我很难找到一种方法来测试这个新库,而无需先将我的应用添加到Play商店。通过BroadcastReceiver监听INSTALL_REFERRER意图时,我可以通过活动管理器手动发送广播来模拟行为进行测试。也就是说,我可以通过following these steps from Google进行测试。

是否还有一种方法可以测试这个新库,而无需先将我的应用程序放在Play商店中?

6 个答案:

答案 0 :(得分:17)

有一个古老的黑客可以对此进行测试。

步骤:

  1. 使用广告系列链接在设备上启动Google Play,例如https://play.google.com/store/apps/details?id=com.test.test_project&referrer=utm_source%3Dtest_source%26utm_medium%3Dtest_medium%26utm_term%3Dtest-term%26utm_content%3Dtest_content%26utm_campaign%3Dtest_name (您可以使用Google Play生成器:https://developers.google.com/analytics/devguides/collection/android/v3/campaigns#google-play-url-builder

  2. 不要轻按安装按钮

  3. 使用adb安装测试版本。

Google Play现在将返回您的测试广告系列。

答案 1 :(得分:2)

我能够使用模拟器测试Play安装引荐来源库。卸载该应用并再次运行它会启动连接,并在responseCode中提供预期的onInstallReferrerSetupFinished

答案 2 :(得分:1)

Maby有些人会需要这个。我创建了测试应用程序,此处仅是一项所需活动的源代码。 关于如何添加Play Install Referrer库:https://developer.android.com/google/play/installreferrer/library

这也是一个很好的描述:https://android-developers.googleblog.com/2017/11/google-play-referrer-api-track-and.html

package com.cat.red.rsamazingapp;

import android.os.RemoteException;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

import com.android.installreferrer.api.InstallReferrerClient;
import com.android.installreferrer.api.InstallReferrerStateListener;
import com.android.installreferrer.api.ReferrerDetails;

import java.text.SimpleDateFormat;
import java.util.GregorianCalendar;

public class MainActivity extends AppCompatActivity implements InstallReferrerStateListener {

    private static final String TAG = "RSD";
    InstallReferrerClient mReferrerClient;
    TextView txtBody;
    StringBuilder stringBuilder;

    private int attemps = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        txtBody = (TextView) this.findViewById(R.id.txt_body);
        stringBuilder = new StringBuilder();
        stringBuilder.append("\nonCreate");

        mReferrerClient = InstallReferrerClient.newBuilder(this).build();
        stringBuilder.append("\n1. onCreate.isReady == " + mReferrerClient.isReady());
        mReferrerClient.startConnection(this);
        stringBuilder.append("\nstartConnection");
        stringBuilder.append("\n2. onCreate.isReady == " + mReferrerClient.isReady());
    }

    @Override
    public void onInstallReferrerSetupFinished(int responseCode) {
        stringBuilder.append("\nonInstallReferrerSetupFinished");

        switch (responseCode) {
            case InstallReferrerClient.InstallReferrerResponse.OK:
                // Connection established
                stringBuilder.append("\nonInstallReferrerSetupFinished. InstallReferrer conneceted. Success");
                stringBuilder.append("\nisReady == " + mReferrerClient.isReady());

                try {
                    ReferrerDetails installReferrerDetails = mReferrerClient.getInstallReferrer();
                    if (installReferrerDetails == null) {
                        stringBuilder.append("\ninstallReferrerDetails == NULL");
                    }

                    if (installReferrerDetails != null) {
                        stringBuilder.append("\ngetInstallReferrer = " + installReferrerDetails.getInstallReferrer());
                        stringBuilder.append("\ngetInstallBeginTimestampSeconds = " + installReferrerDetails.getInstallBeginTimestampSeconds());
                        stringBuilder.append("\ngetReferrerClickTimestampSeconds = " + installReferrerDetails.getReferrerClickTimestampSeconds());
                    }
                } catch (RemoteException e) {
                    stringBuilder.append("\nonInstallReferrerSetupFinished. exception: " + e.getMessage());
                    txtBody.setText(stringBuilder.toString());
                    e.printStackTrace();
                }
                break;
            case InstallReferrerClient.InstallReferrerResponse.FEATURE_NOT_SUPPORTED:
                stringBuilder.append("\nonInstallReferrerSetupFinished. Install Referrer API not supported by the installed Play Store app.");
                stringBuilder.append("\nisReady == " + mReferrerClient.isReady());
                break;
            case InstallReferrerClient.InstallReferrerResponse.SERVICE_UNAVAILABLE:
                // Connection could not be established
                stringBuilder.append("\nonInstallReferrerSetupFinished. Could not initiate connection to the Install Referrer service.");
                stringBuilder.append("\nisReady == " + mReferrerClient.isReady());
                break;
            case InstallReferrerClient.InstallReferrerResponse.SERVICE_DISCONNECTED:
                stringBuilder.append("\nonInstallReferrerSetupFinished. Play Store service is not connected now - potentially transient state");
                stringBuilder.append("\nisReady == " + mReferrerClient.isReady());
                break;
            case InstallReferrerClient.InstallReferrerResponse.DEVELOPER_ERROR:
                stringBuilder.append("\nonInstallReferrerSetupFinished. General errors caused by incorrect usage.");
                stringBuilder.append("\nisReady == " + mReferrerClient.isReady());
                break;
            default:
                stringBuilder.append("\nonInstallReferrerSetupFinished. responseCode not found. code = " + responseCode);
                stringBuilder.append("\nisReady == " + mReferrerClient.isReady());
        }

        stringBuilder.append("\nisReady == " + mReferrerClient.isReady());
        mReferrerClient.endConnection();
        stringBuilder.append("\nendConnection");
        stringBuilder.append("\nisReady == " + mReferrerClient.isReady());

        txtBody.setText(stringBuilder.toString());
    }

    @Override
    public void onInstallReferrerServiceDisconnected() {
        // Try to restart the connection on the next request to
        // Google Play by calling the startConnection() method.
        stringBuilder.append("\nonInstallReferrerServiceDisconnected. attemptCount = " + attemps);
        stringBuilder.append("\nisReady == " + mReferrerClient.isReady());

        if (attemps < 3) {
            attemps++;
            stringBuilder.append("\nonInstallReferrerServiceDisconnected. RE-startConnection");
            mReferrerClient.startConnection(this);
        } else {
            stringBuilder.append("\nonInstallReferrerServiceDisconnected. endConnection");
            stringBuilder.append("\nisReady == " + mReferrerClient.isReady());
            mReferrerClient.endConnection();
            stringBuilder.append("\nendConnection");
            stringBuilder.append("\nisReady == " + mReferrerClient.isReady());
        }

        txtBody.setText(stringBuilder.toString());
    }

    @Override
    protected void onResume() {
        super.onResume();
        stringBuilder.append("\nonResume. isReady == "+ mReferrerClient.isReady());
    }

    public static String format(GregorianCalendar calendar){
        SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
        fmt.setCalendar(calendar);
        String dateFormatted = fmt.format(calendar.getTime());
        return dateFormatted;
    }
}

答案 3 :(得分:1)

这是我的考试摘要:

  1. 旧的广播方式可以测试。但已过时,目前不支持
  2. U可以测试使用adb设置的安装引荐来源库,您将获得 utm_source = google-play&utm_medium = organic ,就像直接从Google Play下载一样。 但是我们无法获得更多信息,它只能测试您的媒体库设置是否正确
  3. @Quickern的
  4. https://stackoverflow.com/a/60342463/12716149。老实说,有效请遵循以下提示
  5. 使用Google Play提供的Beta测试:https://stackoverflow.com/a/49750758/12716149。 毫无疑问,它有效
  6. 使用模拟器:https://stackoverflow.com/a/59744213/12716149 @Marilia。我没有进行测试,因为Google Play商店中的模拟器就像一个真实的设备。答案是条件是将应用程序上传到Google Play商店中,所以我认为它就像第4条一样。

答案 4 :(得分:0)

第一步

测试网址
https://play.google.com/store/apps/details?id=com.test.test_project&referrer=utm_source%3Dtest_source%26utm_medium%3Dtest_medium%26utm_term%3Dtest-term%26utm_content%3Dtest_content%26utm_campaign%3Dtest_name

第 2 步 点击上面的链接。打开 Play 商店 (不要从 Play 商店安装)

第 3 步Android Studio 安装。 你得到结果。 现在,如果您检查另一个链接,则需要以相同的方式执行上述步骤 bcz,

注意: 注意:安装引用信息将在 90 天内可用,除非重新安装应用程序,否则不会更改。为避免应用程序中不必要的 API 调用,您应该在第一次执行时只调用一次 API安装后。

(From Here)

注意:我的应用现在是 Alpha 版(在 Play 商店中)

答案 5 :(得分:-1)

在阅读https://developers.google.com/analytics/solutions/testing-play-campaigns中的必要步骤后,我发现可以使用ADB工具测试应用安装引荐来源库,然后再将其发布到Play商店。

请注意-以下测试使用的是不推荐使用的广播接收器,而不是新的 Play Install Referrer API (感谢Peter Keefe指出了这一点。)

确保应用程序未运行,并在终端/ CMD(与adb连接的设备上)中运行以下shell代码以触发安装意图:

 echo 'am broadcast \
-a com.android.vending.INSTALL_REFERRER \
-n "your.package.name/path.to.receiver" \
--es "referrer" \
  "utm_source=test_source&utm_medium=test_medium&utm_term=test_term&utm_content=test_content&utm_campaign=test_name"; \
exit' | ./adb shell

替换包裹名称和收件人的路径:

  

您的包裹名称/接收者路径

此外,不要忘记替换utm url参数以跟踪不同的安装源:

  

utm_source = test_source&utm_medium = test_medium&utm_term = test_term&utm_content = test_content&utm_campaign = test_name