测试 Google Play 安装引用程序库

我希望从监听 Play Store 的 INSTALL _ REFERRER 意图迁移到使用新的 Google Play 安装引用程序库

我正在努力寻找一种方法来测试这个新的库,而不必首先将我的应用程序添加到 Play Store。当通过 BroadcastReceiver 侦听 INSTALL _ REFERRER 意图时,我可以通过通过 Activity Manager 手动发送广播来模拟行为。也就是说,我可以用 遵循谷歌的这些步骤测试。

是否也存在一种方法,我可以测试这个新的库,而不必首先把我的应用程序在播放商店?

15130 次浏览

也许有些人会需要这个。我创建了测试应用程序,这里是源代码只有一个需要的活动。 这是关于如何添加 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;
}
}

在阅读了 https://developers.google.com/analytics/solutions/testing-play-campaigns中所需的步骤之后,我发现在将应用程序安装引用程序库发布到 Play Store 之前,可以使用 ADB 工具测试它。

请注意-下面的测试是使用废弃的广播接收器,而不是新的 Play Install Referrer API (感谢 Peter Keefe 的提醒)。

确保应用程序是 不是逃跑并在终端/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 _ media = test _ media & utm _ term = test _ term & utm _ content = test _ content & utm _ Campaign = test _ name

我能够使用模拟器测试 Play Install Referrer Library。卸载应用程序并再次运行它将启动一个连接,并给我在 onInstallReferrerSetupFinished期望的 responseCode

有个老黑客在测试这个。

步骤:

  1. 使用广告链接在设备上启动谷歌播放,例如,< a href = “ https://Play.Google.com/store/apps/Details? id = com.test.test _ project & amp; Referrer = utm _ source% 3Dtest _ source% 26utm _ media% 3Dtest _ media% 26utm _ term% 3Dtest-term% 26utm _ content% 3Dtest _ content% 26utm _ Campaign% 3Dtest _ name”rel = “ noReferrer”> 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 现在将返回您的测试活动。

这是我测试的总结:

  1. 旧的广播方式可以测试。但是现在已经不支持了
  2. 您可以测试安装引用库使用 adb 设置,您将获得 Utm _ source = google-play & utm _ media = 有机就像下载谷歌播放直接。 但是我们不能得到更多的信息,< strong > 它只能测试你的库设置是否正确
  3. Https://stackoverflow.com/a/60342463/12716149:@Quickern
  4. 使用 Google Play 提供的 Beta 测试: https://stackoverflow.com/a/49750758/12716149。 毫无疑问,它起作用了
  5. 使用模拟器: https://stackoverflow.com/a/59744213/12716149@Marilia。我没有测试这个,因为带有 Google Play Store 的模拟器就像一个真正的设备。答案是,条件是上传应用到 Google Play 商店,所以我认为这就像第四篇文章

第一步

测试 Url
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

第二步 点击上面的链接,打开 Play Store < strong > (不要从 Play Store 安装)

第三步安卓工作室。安装 你得到了结果。 现在,如果你检查另一个链接,你需要按照上面的步骤相同的方式 bcz,

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

(从这里开始)

注意: My App right now Alpha Version (In Play Store)