How to prevent Play Store testing from affecting Firebase Analytics

扶醉桌前 提交于 2019-12-04 17:41:27

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.

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