73

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

我正在努力寻找一种方法来测试这个新库,而无需先将我的应用程序添加到 Play 商店。通过广播接收器侦听 INSTALL_REFERRER 意图时,我可以通过活动管理器手动发送广播来模拟行为来进行测试。也就是说,我可以按照谷歌的这些步骤进行测试。

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

4

6 回答 6

36

有一个旧的 hack 可以测试这一点。

脚步:

  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 (您可以使用谷歌播放生成器:https ://developers.google.com/analytics/devguides/collection/android/v3/campaigns#google-play-url-builder )

  2. 不要点击安装按钮

  3. 使用 adb 安装您的测试版本。adb install -r app-debug.apk

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

于 2020-02-21T16:11:20.143 回答
3

这是我的测试总结:</p>

  1. 旧的广播方式可以测试。但它已被弃用,目前不支持
  2. 你可以测试安装使用adb设置的referrer lib,你会得到utm_source=google-play&utm_medium=organic,就像直接从Google Play下载一样。但我们无法获得更多信息,它只能测试您的库设置是否正确
  3. https://stackoverflow.com/a/60342463/12716149 by @Quickern。老实说,它的工作原理遵循这些提示
    • 确保应用程序 ID 相同。
    • 直接通过 Google Play 应用打开测试网址(请勿下载)
    • 使用 adb 安装您的测试应用程序
    • 打开您的应用程序,您将收到您在 url 中设置的内容
  4. 使用 Google Play 提供的 Beta 测试:https ://stackoverflow.com/a/49750758/12716149 。毫无疑问,它有效
  5. 使用模拟器:https://stackoverflow.com/a/59744213/12716149 @Marilia。我没有测试这个,因为带有Google Play Store的模拟器就像一个真实的设备。答案说条件是上传应用程序到Google Play商店,所以我认为它就像第4条一样
于 2020-08-25T08:11:03.623 回答
2

我能够使用模拟器测试 Play Install Referrer Library。卸载应用程序并再次运行它会启动连接并给我预期responseCodeonInstallReferrerSetupFinished.

于 2020-01-15T01:59:19.577 回答
1

步骤1

测试网址
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 工作室安装。 你得到结果。现在,如果您检查另一个链接,则需要以相同的方式执行上述步骤 bcz,

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

(从这里)

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

于 2021-06-30T12:17:19.350 回答
0

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

请注意 - 以下测试使用的是已弃用的广播接收器,而不是新的Play Install Referrer API (感谢注意到它的彼得基夫)。

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

 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

替换接收者的包名和路径:

your.package.name/path.to.receiver

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

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

于 2019-12-03T09:01:37.303 回答
-5

也许有些人会需要这个。我创建了测试应用程序,这里是只需要一项活动的源代码。这是关于如何添加 Play Install Referrer Library: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;
    }
}
于 2018-08-10T10:57:05.957 回答