5

I am using Google Analytics and I have seen that all the devices in the Cloud Test Lab are detected as "active users" and "new users" (which makes sense). Is there any way to detect this and do not count them ?

I see that they are not counted as installs in Google Play, so I would expect the same behaviour for Analytics.

It is possible to avoid this by uploading a different version to Alpha/Beta and Production with different tracking ids, but the Cloud Test Lab feature is much more powerful if the same Apk is promoted from Alpha/Beta to Production.

Javier Delgado
  • 2,343
  • 2
  • 17
  • 31

3 Answers3

1

As mentioned, you can exclude analytics by the IP addresses listed in the page https://firebase.google.com/docs/test-lab/android/get-started#ip-blocks

Here is some code to handle this (requires apache commons-net) This should cover all the current cases.

NOTE: You'll only need to call this once at app start, since a Test Lab device won't change IP addresses and a NON Test Lab Device will not become one. I guess this kinda assumes that the wifi connection is established also...

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;
}
levi
  • 23,693
  • 18
  • 59
  • 73
aaronvargas
  • 12,189
  • 3
  • 52
  • 52
1

According to this answer, you can check if "firebase.test.lab" system variable is set to "true" which indicates if you're running on a test lab device.

guy.gc
  • 3,359
  • 2
  • 24
  • 39
0

Depends on what you mean by "not count them". If these cloud visits are identifiable by source/medium or another unique parameter, I think best practice would be creating another view in which these visits are filtered out. Otherwise you could apply a segment to your standard view that excludes these visits.

  • Any idea on how to exclude that visits or how to identify them ? – Javier Delgado Mar 25 '16 at 16:16
  • Sessions from Cloud Test Lab should come through GA as IP within the range 108.177.6.0.x - 108.177.6.24.x. as referenced [here](https://developers.google.com/cloud-test-lab/best-practices#app_testing_best_practices). You should create a filtered view in GA that either filters or subsets the IPs in the range. Use filter type=custom. Looking at the IP address structure of Cloud visits, you will need to create a reg expression with both a range (0-24) and subnet (x) to include all IPs. This results in the following reg expression `^108\.177\.6\.[6-24]\.*$`. – Catherine Smith Mar 25 '16 at 16:47
  • 1
    According to the link posted by Catherine, the current IP range for test devices is `108.177.6.0/23`, so IP addresses will either start with `108.177.6.` or `108.177.7.`. Setting up two IP filters with those prefixes worked for me. – Tamás Szincsák Mar 18 '18 at 14:29