Google Analytics 检测到 Google Cloud Test Lab 测试作为活跃用户和新用户

Google Analytics detects Google Cloud Test Lab tests as Active Users and New Users

我正在使用 Google Analytics,我发现 Cloud Test Lab 中的所有设备都被检测为 "active users" 和 "new users"(这是有道理的)。有什么方法可以检测到这一点并且不计算它们吗?

我看到它们在 Google Play 中不计为安装,所以我希望 Analytics 有相同的行为。

可以通过将不同的版本上传到 Alpha/Beta 并使用不同的跟踪 ID 来避免这种情况,但是如果从 [=20= 提升相同的 Apk,云测试实验室功能会更强大] 生产。

取决于您所说的 "not count them" 是什么意思。如果这些云访问可以通过 source/medium 或其他唯一参数识别,我认为最佳做法是创建另一个视图,在其中过滤掉这些访问。否则,您可以将细分应用于排除这些访问的标准视图。

如前所述,您可以按页面中列出的 IP 地址排除分析 https://firebase.google.com/docs/test-lab/android/overview#and_mobile_advertising

这里有一些代码来处理这个问题(需要 apache commons-net) 这应该涵盖所有当前案例。

注意:您只需在应用程序启动时调用一次,因为测试实验室设备不会更改 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;
}

根据 回答,您可以检查 "firebase.test.lab" 系统变量是否设置为 "true",这表明您是否 运行 在测试实验室设备上。