Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting custom screen name for bottom sheet screen for Firebase Analytics

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.

like image 680
Emarc Magtanong Avatar asked Jan 16 '17 03:01

Emarc Magtanong


1 Answers

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.

like image 164
MiguelHincapieC Avatar answered Sep 21 '22 12:09

MiguelHincapieC