Firebase 事件跟踪排除测试自动化运行和质量检查测试事件

Firebase event tracking exclude test automation runs and qa testing events

我们面临一个问题,我们的测试自动化设置破坏了我们的分析。
我找到了一个解决方案,只是为了从测试中排除暂存风格,并添加了一个功能标志以将其打开以进行测试。

但是,我看到了通过检查设备是否处于调试视图模式并仅允许对这种情况进行测试跟踪来改进此逻辑的空间。 (因为调试视图中的设备会自动从统计信息中排除) 这就是 doc 所说的

Note: To prevent your testing and development from affecting your measurements, events logged while in debug mode will be excluded from your overall Analytics data, and will not be included in your daily BigQuery export.

adb shell setprop debug.firebase.analytics.app package_name

有没有办法检查这个值?

这是我找到的解决方案。 希望对某人有用

/**
 * we read user properties and if these properties contain our application id as a selected firebase analytics app
 * we enable tracking @see https://firebase.google.com/docs/analytics/debugview#android for more details
 */
private fun isDebugEnabled() = try {
    // Run the command to get properties for debug view for firebase
    val process = Runtime.getRuntime()
        .exec(arrayOf("/system/bin/sh", "-l", "-c", "getprop | grep debug.firebase.analytics.app"))
    val bufferedReader = BufferedReader(InputStreamReader(process.inputStream))

    // Grab the results
    bufferedReader.readLines().any { it.contains(applicationId) }
} catch (e: IOException) {
    false
}