Skip to content Skip to sidebar Skip to footer

Exclude Testing Device From Firebase Analytics Logging

I am sure that Firebase is counting all my development work too in its analytics. I open my app like hundred times a day to debug and test on a few devices, it's really skewing up

Solution 1:

You can control analytics collection using manifest metadata with the setting defined by a manifestPlaceholder:

<application
    android:name="MyApplication"
    //... >
    <meta-data
        android:name="firebase_analytics_collection_deactivated"
        android:value="${analytics_deactivated}" />
    //...
 </application>

Then define the placeholder value in the build variant blocks of your build.gradle file:

buildTypes {
    debug {
        manifestPlaceholders = [analytics_deactivated: "true"]
        //...
    }

    release {
        manifestPlaceholders = [analytics_deactivated: "false"]
        //...
    }

Solution 2:

A solution using the ANDROID_ID

1) Get ANDROID_ID of all your testing devices (This is a 64-bit unique ID generated when the user first sets up the device. It remains constant thereafter.)

privatestaticStringgetDeviceID(Context c) {
    returnSettings.Secure.getString(c.getContentResolver(), Settings.Secure.ANDROID_ID);
}

2) Add these IDs to an array:

privatestaticString testingDeviceIDs[] = {"8ab5946d3d65e893", "ada1247bfb6cfa5d", ...};

3) Check if the current device is one of the testing devices.

privatestaticbooleanisDeviceForTesting(Context c) {
    for (String testingID : testingDeviceIDs)
        if (getDeviceID(c).equals(testingID))
            returntrue;
    returnfalse;
}

4) Finally, log Firebase events only if the device is not a testing device.

staticvoidlogFirebaseEvent(Context c, String name) {
    if (!isDeviceForTesting(c))
        FirebaseAnalytics.getInstance(c).logEvent(name, null);
}

UPSIDE: Unlike Firebase's provision of controlling analytics collection, this method will also work on Release builds/APKs.

Solution 3:

Should be able to do something like following:

    if (BuildConfig.DEBUG) {
        FirebaseAnalytics.getInstance(getApplicationContext()).setAnalyticsCollectionEnabled(false);
     }

Solution 4:

The firebase docs only describe that it can be disabled from within the apk.

AndroidManifest.xml

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

Activity.java

setAnalyticsCollectionEnabled(false);

source: https://firebase.google.com/support/guides/disable-analytics

Solution 5:

If what you were looking for, it was to disable the Firebase Analytics / tracking for the test devices that run the Firebase tests or the Play Console Pre-launch reports (which are actually Firebase tests), then you need to disable them based on a system string:

String testLabSetting = Settings.System.getString(context.getContentResolver(), "firebase.test.lab");
if ("true".equals(testLabSetting)) {
    FirebaseAnalytics.getInstance(context).setAnalyticsCollectionEnabled(false);
}

So basically, it's a combination of checking if your device is a Firebase Test device, and then you disable the FirebaseAnalytics for it.

However, it won't entirely stop Firebase Analytics, and the event session_start will keep showing up.

Post a Comment for "Exclude Testing Device From Firebase Analytics Logging"