Android - "firebase.test.lab" setting fails to exclude play store testing activity from firebase analytics
Asked Answered
I

1

11

Each time upon uploading a new release to the google play store, I get about 8 new users logged in my Firebase analytics console within around 10 minutes. I have not released my app publicly yet, it's on a closed test track with nobody else opted in. The only possible cause seems to be internal testing by google, such as Pre-launch reports. These numbers will really mess up my analytics data, so I'd like to exclude this testing traffic from Firebase analytics.

After following the suggestions in these previous questions, unfortunately none of the solutions mentioned successfully exclude the testing activity

In my AndroidManifest.xml after the first line in the application tag I have:

<meta-data android:name="firebase_analytics_collection_enabled" android:value="false" />

At the beginning of onCreate() in my MainActicity I have:

if(!isTestDevice(this))
{
    FirebaseAnalytics.getInstance(this).setAnalyticsCollectionEnabled(true);
}

And I have the following function:

public static boolean isTestDevice(Context context) {
    String testLabSetting = Settings.System.getString(context.getContentResolver(), "firebase.test.lab");
    return "true".equals(testLabSetting);
}

At first I thought that the isTestDevice function may not be working properly, so I added the following debugging code to my home screen:

if(isTestDevice(linearLayout.getContext())) {
    TextView testText = new TextView(linearLayout.getContext());
    testText.setText("TEST DEVICE");
    testText.setId(linearLayout.generateViewId());
    linearLayout.addView(testText, 0, params);

    TextView disabledText = new TextView(linearLayout.getContext());
    disabledText.setText("Analytics disabled");
    disabledText.setId(linearLayout.generateViewId());
    linearLayout.addView(disabledText, 0, params);
}

And in the pre-launch reports screenshots I can see that the isTestDevice function is working:

Pre-launch report screenshot

Also, If I comment out the setAnalyticsCollectionEnabled(true); line, then no activity gets logged to the Firebase analytics console, which shows that the line in AndroidManifest.xml is correctly disabling the analytics until the setAnalyticsCollectionEnabled(true); line gets run.

Also, even if I disable pre-launch reports, the same activity gets logged, around 8 users within minutes of uploading the release.

It seems like the activity being logged is coming from some source other than the pre-launch reports, since I can see from the pre-launch screenshots that the pre-launch devices are correctly being detected as test devices, and furthermore, the activity still gets logged even if I turn off pre-launch reports. But even still, the activity is logged within 10 minutes of uploading a release.

How can I prevent this testing activity from being logged in firebase analytics? It seems like the solutions in the linked posts are no longer working.

EDIT: A main feature of my app is a game. I've been able to essentially work around the problem for now by only setting analytics to enabled if the user scores more than one point in the game. This effectively removes all traffic being logged by bots, since they just aimlessly click on anything and lack any intelligence required to score more than one point. But this is a really bad hack that I'd like to remove.

Invalid answered 28/4, 2020 at 11:14 Comment(0)
R
0

The only reliable way to avoid this is to exclude by IP address. As you discovered, disabling Pre-Launch Reports does not stop tests from being run since we use the information from these tests to detect issues with the app.

Rabbinate answered 9/7, 2020 at 22:13 Comment(4)
Could you give some more detail, such as which IP addresses to exclude?Invalid
firebase.google.com/docs/test-lab/android/…Rabbinate
Could you please elaborate "since we use the information from these tests to detect issues with the app". Is it ok to block the App UI for these bots completely by showing just an empty screen? Otherwise they will interact with my real users, which is really unpleasant... I don't understand how anybody can live with that behaviour in a production environment, I have the feeling I'm missing something crucial here :( !Phebe
I also got the same issue of Firebase test lab impacting my Analytics in Production. A simple solution seems necessary. In general, testing in lab shouldn't impact anything in Production.Agitator

© 2022 - 2024 — McMap. All rights reserved.