I just launched a new app and I am using Firebase Analytics. However, every time I upload a new release to the play store, it is automatically tested by Google on 11 devices. Which is great!
Is there a way to prevent those tests from impacting the analytics? I am starting with a small user base, so it can affect it greatly.
I also created an anonymous Auth. Is there a way to prevent it from creating anonymous accounts for those pre-release tests? Can I identify them so I can delete them on Firebase?
After lots of research, trials and error, I found something that finally works. I added this code at the beginning of onCreat() in my MainActicity (launch activity). I hope that helps others!
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
String testLabSetting =
Settings.System.getString(getContentResolver(), "firebase.test.lab");
if ("true".equals(testLabSetting)) {
//You are running in Test Lab
mFirebaseAnalytics.setAnalyticsCollectionEnabled(false); //Disable Analytics Collection
Toast.makeText(getApplicationContext(), "Disabling Analytics Collection ", Toast.LENGTH_LONG).show();
}
Reference code in Firebase docs
For the first question: What you could do is have a user property for these test like "environement" and set the value to "alpha"/"beta"/"prod" whatever you like. You setup x audience for "alpha user", "beta users", etc, and the first thing you do when you launch the app is to set that user property to the right value. For instance you could get the Android ID of all your test device, and if you are on one of these device you set the value to "alpha" or "test", else you set it to "prod". When you'll look at all your user in the prod audience you'll not see your test users.
Question 2: Right after you set the user property to "alpha" you can store a value in the user account information like "test_account: true" and lter you can either write a script to delete them, or delete them manually depending on how many account you have.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With