In version 6.29.0 of Firebase Analytics the method
class func setScreenName(_ screenName: String?, screenClass screenClassOverride: String?)
is deprecated. The hint given is to Use +[FIRAnalytics logEventWithName:kFIREventScreenView parameters:] instead.
My question is what is the parameter for screenName? How do I rewrite my helper method:
import FirebaseAnalytics
func setScreenName(_ screenName: String) {
Analytics.setScreenName(screenName, screenClass: nil)
}
This is the code to rewrite the deprecated method:
Replace this line:
Analytics.setScreenName(screenName, screenClass: nil)
With this line:
Analytics.logEvent(AnalyticsEventScreenView, parameters: [AnalyticsParameterScreenName: screenName])
I did it in this way:
Deprecated code
Analytics.setScreenName(name, screenClass: className)
new code
Analytics.logEvent(AnalyticsEventScreenView, parameters: [AnalyticsParameterScreenName: name,
AnalyticsParameterScreenClass: className])
Just in case it can help someone, here is the Objective-C version:
[FIRAnalytics logEventWithName:kFIREventScreenView parameters: @{kFIRParameterScreenName: screenName}];
Here is the Android version:
Bundle bundle = new Bundle();
bundle.putString(FirebaseAnalytics.Param.SCREEN_NAME, screenName);
bundle.putString(FirebaseAnalytics.Param.SCREEN_CLASS, screenClass);
bundle.putString(MyAppAnalyticsConstants.Param.TOPIC, topic);
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.SCREEN_VIEW, bundle);
val bundle = Bundle()
bundle.putString(FirebaseAnalytics.Param.SCREEN_NAME, screenName)
bundle.putString(FirebaseAnalytics.Param.SCREEN_CLASS,classname)
firebase.logEvent(FirebaseAnalytics.Event.SCREEN_VIEW, bundle)
extension Analytics
{
static func setScreenName(_ screenName:String, screenClass:String)
{
Analytics.logEvent(AnalyticsEventScreenView, parameters: [AnalyticsParameterScreenName: screenName,AnalyticsParameterScreenClass:screenClass])
}
}
Simple add this extension in your project no need to change anything after this
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With