从Firebase Analytics日志中排除测试设备 [英] Exclude testing device from Firebase Analytics logging

查看:84
本文介绍了从Firebase Analytics日志中排除测试设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确信Firebase也在其分析中也算出了我所有的开发工作.我每天要打开我的应用程序数百次,以便在一些设备上进行调试和测试,这确实使我的阅读量产生了偏差.

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 my readings.

我使用了一个函数来给我一个表示设备的唯一ID,而忽略了通过代码进行的所有分析.

I have used a function to get me a somewhat unique ID to represent my devices and ignored all its analytics through code.

public static String getPsuedoID() {
    String m_szDevIDShort = "35" + (Build.BOARD.length() % 10)
    + (Build.BRAND.length() % 10) + (Build.VERSION.SDK_INT % 10)
    + (Build.DEVICE.length() % 10) + (Build.DISPLAY.length() % 10)
    + (Build.MODEL.length() % 10) + (Build.PRODUCT.length() % 10);

    String serial;
    try {
        serial = android.os.Build.class.getField("SERIAL").get(null).toString();
        return new UUID(m_szDevIDShort.hashCode(), serial.hashCode()).toString();
    } catch (Exception exception) {
        serial = "getUniquePsuedoIDfailed";
    }
    return new UUID(m_szDevIDShort.hashCode(), serial.hashCode()).toString();
}

但是我只是发现它并不像我想象的那样独特.显然,我的ID与少数几个用户相同.

But I just figured out it is not as unique as I assumed. Apparently, my ID was same as around a few (very few) users.

是否有一种万无一失的方法来做到这一点?

Is there a foolproof method to do just this?

推荐答案

使用ANDROID_ID的解决方案

1)获取 ANDROID_ID (这是用户首次设置设备时生成的64位唯一ID.此后保持不变.)

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

private static String getDeviceID(Context c) {
    return Settings.Secure.getString(c.getContentResolver(), Settings.Secure.ANDROID_ID);
}

2)将这些ID添加到数组中:

private static String testingDeviceIDs[] = {"8ab5946d3d65e893", "ada1247bfb6cfa5d", ...};

3)检查当前设备是否为测试设备之一.

private static boolean isDeviceForTesting(Context c) {
    for (String testingID : testingDeviceIDs)
        if (getDeviceID(c).equals(testingID))
            return true;
    return false;
}

4)最后,仅在设备不是测试设备时记录Firebase事件.

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

UPSIDE:与Firebase提供的控制分析收集的规定不同,该方法也适用于Release版本/APK.

这篇关于从Firebase Analytics日志中排除测试设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆