How to prevent Play Store testing from affecting Firebase Analytics

三世轮回 提交于 2019-12-06 09:16:32

问题


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?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/39404078/how-to-prevent-play-store-testing-from-affecting-firebase-analytics

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!