我希望从聆听 Play 商店的 INSTALL_REFERRER 意图迁移到使用新的Google Play Install Referrer Library。
我正在努力寻找一种方法来测试这个新库,而无需先将我的应用程序添加到 Play 商店。通过广播接收器侦听 INSTALL_REFERRER 意图时,我可以通过活动管理器手动发送广播来模拟行为来进行测试。也就是说,我可以按照谷歌的这些步骤进行测试。
是否还有一种方法可以测试这个新库,而无需先将我的应用程序放到 Play 商店中?
我希望从聆听 Play 商店的 INSTALL_REFERRER 意图迁移到使用新的Google Play Install Referrer Library。
我正在努力寻找一种方法来测试这个新库,而无需先将我的应用程序添加到 Play 商店。通过广播接收器侦听 INSTALL_REFERRER 意图时,我可以通过活动管理器手动发送广播来模拟行为来进行测试。也就是说,我可以按照谷歌的这些步骤进行测试。
是否还有一种方法可以测试这个新库,而无需先将我的应用程序放到 Play 商店中?
有一个旧的 hack 可以测试这一点。
脚步:
使用活动链接在设备上启动 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 )
不要点击安装按钮
使用 adb 安装您的测试版本。adb install -r app-debug.apk
Google Play 现在将返回您的测试广告系列。
这是我的测试总结:</p>
我能够使用模拟器测试 Play Install Referrer Library。卸载应用程序并再次运行它会启动连接并给我预期responseCode
的onInstallReferrerSetupFinished
.
步骤1
步骤 2 点击上面的链接。打开 Play 商店(不要从 Play 商店安装)
第 3 步 从Android 工作室安装。 你得到结果。现在,如果您检查另一个链接,则需要以相同的方式执行上述步骤 bcz,
注意: 注意:安装引用信息将在90 天内可用,除非重新安装应用程序,否则不会更改。为避免在您的应用程序中调用不必要的 API,您应该在安装后的第一次执行期间仅调用一次 API。
注意:我的应用现在 Alpha 版(在 Play 商店中)
在阅读了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
也许有些人会需要这个。我创建了测试应用程序,这里是只需要一项活动的源代码。这是关于如何添加 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;
}
}