Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent Play Store testing from affecting Firebase Analytics

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!

  1. 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.

  2. 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?

like image 525
Kamy Avatar asked Sep 09 '16 04:09

Kamy


2 Answers

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

like image 87
Kamy Avatar answered Oct 23 '22 00:10

Kamy


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.

like image 23
Sistr Avatar answered Oct 23 '22 02:10

Sistr