We are facing an issue, where our test automation setup spoils our analytics.
There is a solution that I found just to exclude staging flavour from testing and added a feature flag to turn it on for testing purposes.
However, I see room to improve this logic, by checking if a device is in debug-view mode and allowing test-tracking only for this case. (because devices in a debug view are automatically excluded from statistics)
this is what doc says
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
Is there a way to check this value?
this is a solution that I found. Hope it would be useful for someone
/**
* 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
}