I am tracking android app activity screens under custom label. However, in the GA dashboard, activities are shown with their default path along with custom labels. Also the metric numbers being tracked under two labels of the same activity are different.
Attached is a screen shot for better illustration:
Here the MainActivity and Home screen are referring the same activity. But GA shows two separate labels. How can I get rid of one MainActivity label?
Google Analytics for Android show screen tracking under two labels
1k Views Asked by user1036908 At
2
There are 2 best solutions below
0
On
You can turn off automatic screen tracking by using enableAutoActivityTracking(false) in code:
Or via the XML file:
<bool name="ga_autoActivityTracking">false</bool>
https://developers.google.com/analytics/devguides/collection/android/v4/screens#automatic
Tracking things manually can be done using these:
fun trackScreen(context: Context, screenObject: Any, screenName: String? = null) {
if (screenName == null)
trackScreen(context, screenObject.javaClass)
else
trackScreen(context, screenObject.javaClass, screenName)
}
fun trackScreen(context: Context, clazz: Class<Any>, screenName: String = clazz.simpleName) {
if (BuildConfig.DEBUG)
return
val className = clazz.canonicalName ?: clazz.name
FirebaseAnalytics.getInstance(context).logEvent(FirebaseAnalytics.Event.SCREEN_VIEW) {
param(FirebaseAnalytics.Param.SCREEN_NAME, screenName)
param(FirebaseAnalytics.Param.SCREEN_CLASS, className)
}
}
So you can use registerActivityLifecycleCallbacks and use the above function, for example:
You probably have enabled automatic screen tracking. Turn it off and it should disappear.
See here for the description of the property if you use xml or here if you initialize it programmatically.