我正在使用Google Analytics,我已经看到云测试实验室中的所有设备都被检测为"活动用户"one_answers"新用户"(这很有道理)。有没有什么方法可以检测到这一点而不计算它们?
我看到它们在Google Play中不被算作安装,所以我希望Analytics也有同样的行为。
可以通过将不同的版本上传到Alpha/Beta和具有不同跟踪ID的Production来避免这种情况,但如果将相同的Apk从Alpha/Bata升级到Production,那么云测试实验室功能会强大得多。
根据这个答案,您可以检查"firebase.test.lab"
系统变量是否设置为"true"
,这表明您是否在测试实验室设备上运行。
如上所述,您可以通过页面中列出的IP地址排除分析https://firebase.google.com/docs/test-lab/android/get-started#ip-阻止
以下是一些处理此问题的代码(需要apachecommons-net)这应该涵盖当前的所有案例。
注意:你只需要在应用程序启动时调用一次,因为测试实验室设备不会更改IP地址,而非测试实验室设备也不会变成IP地址。我想这有点假设wifi连接也建立了。。。
private static boolean isTestLabIpAddress(Context context) {
WifiManager wm = (WifiManager) context.getApplicationContext().getSystemService(WIFI_SERVICE);
String ip = Formatter.formatIpAddress(wm.getConnectionInfo().getIpAddress());
// Log.i(TAG, "isTestLabIpAddress: ip: " + ip); for diagnosis, you may want this temporarily to be able to check the TestLab device logcat logs
// https://firebase.google.com/docs/test-lab/android/overview#and_mobile_advertising
List<String> cidrAddrs = new ArrayList<>();
//Physical devices
cidrAddrs.add("108.177.6.0/23");
//Virtual devices
cidrAddrs.add("35.192.160.56/29");
cidrAddrs.add("35.196.166.80/29");
cidrAddrs.add("35.196.169.240/29");
cidrAddrs.add("35.203.128.0/28");
cidrAddrs.add("35.234.176.160/28");
cidrAddrs.add("199.192.115.0/30");
cidrAddrs.add("199.192.115.8/30");
cidrAddrs.add("199.192.115.16/29");
for (String cidrRange : cidrAddrs) {
SubnetUtils utils = new SubnetUtils(cidrRange); // build.gradle - implementation 'commons-net:commons-net:3.6'
boolean isInRange = utils.getInfo().isInRange(ip);
if (isInRange) {
//Log.d(TAG, "isTestLabIpAddress: true: " + ip);
return true;
}
}
return false;
}
取决于您所说的"不计算它们"的含义。如果这些云访问可以通过源/介质或其他唯一参数来识别,我认为最佳实践是创建另一个视图,在其中过滤这些访问。否则,您可以将一个线段应用于标准视图,该视图不包括这些访问。