Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Analytics setScreenName deprecated

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)
}
like image 256
Rool Paap Avatar asked Jul 30 '20 07:07

Rool Paap


5 Answers

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])
like image 156
Laura Avatar answered Sep 28 '22 10:09

Laura


I did it in this way:

Deprecated code

Analytics.setScreenName(name, screenClass: className)

new code

Analytics.logEvent(AnalyticsEventScreenView, parameters: [AnalyticsParameterScreenName: name,
                                                          AnalyticsParameterScreenClass: className])
like image 44
RunesReader Avatar answered Sep 28 '22 09:09

RunesReader


Just in case it can help someone, here is the Objective-C version:

[FIRAnalytics logEventWithName:kFIREventScreenView parameters: @{kFIRParameterScreenName: screenName}];
like image 24
JonyMateos Avatar answered Sep 28 '22 10:09

JonyMateos


Here is the Android version:

Java

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);

Kotlin

val bundle = Bundle()
bundle.putString(FirebaseAnalytics.Param.SCREEN_NAME, screenName)
bundle.putString(FirebaseAnalytics.Param.SCREEN_CLASS,classname)
firebase.logEvent(FirebaseAnalytics.Event.SCREEN_VIEW, bundle)
like image 29
georkost Avatar answered Sep 28 '22 10:09

georkost


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

like image 23
Divyesh Gondaliya Avatar answered Sep 28 '22 08:09

Divyesh Gondaliya