chemerisuk/cordova-plugin-firebase-analytics

setScreenName on iOS and setCurrentScreen on Android are deprecated

Closed this issue · 4 comments

Android: https://firebase.google.com/docs/analytics/screenviews#java

Bundle bundle = new Bundle();
bundle.putString(FirebaseAnalytics.Param.SCREEN_NAME, screenName);
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.SCREEN_VIEW, bundle);

iOS: https://firebase.google.com/docs/analytics/screenviews#objective-c

[FIRAnalytics logEventWithName:kFIREventScreenView parameters:@{kFIRParameterScreenName: screenName}]

I'm not sure if it's mentioned in the docs but it's still not 100% clear to me how to switch to using logEvent as a replacement. Looking at the docs it looks like the event constant FirebaseAnalytics.Event.SCREEN_VIEW maps to screen_view and the bundle parameter FirebaseAnalytics.Param.SCREEN_NAME maps to screen_name so something like below would work?

cordova.plugins.firebase.analytics.logEvent('screen_view', { screen_name: 'screen-1' })

https://firebase.google.com/docs/analytics/screenviews#manually_track_screens

I think it'd be better to have a convenience method for handling manual screen tracking rather than relying on logEvent for a cleaner look and better usage of the native constant values.

@mcfarljw you are right - just use string constant values in your logEvent call:

cordova.plugins.firebase.analytics.logEvent('screen_view', {
  screen_name: 'screen-1', 
  screen_class: 'MainActivity'
});

Google decided to deprecate a convenience method I guess there is a reason. We can reimplement setCurrentScreen with logEvent inside but I'm not sure if it won't introduce a conflict in future.

@mcfarljw I've decided to undeprecate setCurrentScreen and reimplement it with logEvent + constants. In future other common methods could be added to simplify usage.