Setting custom screen name for bottom sheet screen for Firebase Analytics

折月煮酒 提交于 2019-12-12 08:54:23

问题


I have an activity with a sliding bottom sheet. I want to track how long does the user views the bottom sheet or the main activity screen.

I'm trying to use FirebaseAnalytics#setCurrentScreen(Activity activity, String screenName, String screenClassOverride) so that when the bottom sheet is shown. I specify the screenName with

FirebaseAnalytics.setCurrentScreen(activity, "bottom_sheet", null);

Then when the bottom sheet is closed I call

FirebaseAnalytics.setCurrentScreen(activity, null, null);

to revert to the main activity's name.

However I get a log from FA:

W/FA: setCurrentScreen cannot be called with the same class and name

If anyone can tell me how to properly set the screen name that would be great.


回答1:


The screenName is whatever you want to use to identify your Activity/Fragment/Dialog...

You should use setCurrentScreen in this way:

FirebaseAnalytics.setCurrentScreen(activity, "bottom_sheet", this.getClass().getSimpleName());

or

FirebaseAnalytics.setCurrentScreen(activity, "bottom_sheet", MyActivity.class.getSimpleName());

Remember that Firebase Analytics records your current Activity automatically, look at follow setCurrentScreen info from official Firebase docs:

Note that screen reporting is enabled automatically and records the class name of the current Activity for you without requiring you to call this function. The class name can optionally be overridden by calling this function in the onResume callback of your Activity and specifying the screenClassOverride parameter.

You can found this and more documentation here

Now, you are getting that error message

W/FA: setCurrentScreen cannot be called with the same class and name

When you are setting same screenName and screenClassOverride in setCurrentScreen()

Using Log.d in where you are calling that method can help you to see if you are calling same thing twice or more. But I guess you don't have to worry about it (it's a warning). I have been seen it in my current project and everything is working fine.



来源:https://stackoverflow.com/questions/41668955/setting-custom-screen-name-for-bottom-sheet-screen-for-firebase-analytics

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!