Firebase Analytics setScreenName deprecated
Solution 1
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])
Solution 2
I did it in this way:
Deprecated code
Analytics.setScreenName(name, screenClass: className)
new code
Analytics.logEvent(AnalyticsEventScreenView, parameters: [AnalyticsParameterScreenName: name,
AnalyticsParameterScreenClass: className])
Solution 3
Just in case it can help someone, here is the Objective-C version:
[FIRAnalytics logEventWithName:kFIREventScreenView parameters: @{kFIRParameterScreenName: screenName}];
Solution 4
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)
Solution 5
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
![Rool Paap](https://i.stack.imgur.com/PLM7T.jpg?s=256&g=1)
Rool Paap
Hi, I’m Rool, a senior freelance iOS developer, working on internet, web, app, mobile and tablet projects since 1997. With over 20 years of experience in software development, I consider myself to be a well rounded professional.
Updated on June 20, 2022Comments
-
Rool Paap about 2 years
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) }
-
Rool Paap almost 4 yearsAh, I missed the AnalyticsParameterScreenName part. Thanks!
-
MavBzh over 3 yearsHi, sorry to ask this question but since you manually log the event (in your answer), isn't there a problem of data duplication due to Firebase automatic event collect. Screen views won't be logged twice?
-
Anilkumar iOS - ReactNative over 3 years@Laura, I have tried this but I am getting following error, Can you help us stackoverflow.com/questions/65843488/…
-
Anilkumar iOS - ReactNative over 3 yearsI tried this but, for me showing following error Use of unresolved identifier 'AnalyticsEventScreenView' Use of unresolved identifier 'AnalyticsParameterScreenName' Any Suggestions?
-
Anilkumar iOS - ReactNative over 3 yearsHi @Laura I tried your suggestions, But I am getting following errors Use of unresolved identifier 'AnalyticsEventScreenView' Use of unresolved identifier 'AnalyticsParameterScreenName' Even I am using latest version of analytics from firebase using pods, Any suggestions?
-
Harsh Phoujdar almost 3 yearsWhich file do we replace this in?
-
StormFoo almost 3 yearsYou can also add
kFIRParameterScreenClass
to your parameters to replacescreenClass
. -
Kowboj about 2 years@MavBzh you should place it in viewDidAppear, if you don't, Firebase (used to) automatically send it, with a "not set" screen name. Perhaps they changed it recently
-
Kowboj about 2 years@AnilkumariOS-ReactNative you probably need to import FirebaseAnalytics in this file, or use "kFIRParameterScreenName".