react-native-firebase icon indicating copy to clipboard operation
react-native-firebase copied to clipboard

[🐛] logEvent versus logScreenView

Open faljabi opened this issue 5 months ago • 33 comments

Issue

When switching to modular api for logging screens

await logEvent(analytics, 'screen_view', {
                firebase_screen: currentRouteName,
                firebase_screen_class: currentRouteName
});

I see UIViewController or MainActivity on the Analytics Dashboard. It was working fine with showing my screen names instead using the below:

await logScreenView(analytics, {
                screen_name: currentRouteName,
                screen_class: currentRouteName
});

Project Files

Javascript

Click To Expand

package.json:

"@react-native-firebase/analytics": "^22.4.0",
    "@react-native-firebase/app": "^22.4.0",
    "@react-native-firebase/crashlytics": "^22.4.0",
    "@react-native-firebase/firestore": "^22.4.0",
    "@react-native-firebase/remote-config": "^22.4.0",

firebase.json for react-native-firebase v6:

{
    "react-native": {
        "analytics_auto_collection_enabled": true,
        "google_analytics_automatic_screen_reporting_enabled": false,
        "crashlytics_debug_enabled": true,
        "crashlytics_disable_auto_disabler": true,
        "crashlytics_auto_collection_enabled": true,
        "crashlytics_is_error_generation_on_js_crash_enabled": true,
        "crashlytics_javascript_exception_handler_chaining_enabled": false
    }
}

Any advise?

iOS

Click To Expand

ios/Podfile:

  • [ ] I'm not using Pods
  • [x] I'm using Pods and my Podfile looks like:

faljabi avatar Jul 11 '25 16:07 faljabi

If I use directly logEvent passing analytics app instance, my IDE throw this:

TS2769: No overload matches this call. The last overload gave the following error. Argument of type "screen_view" is not assignable to parameter of type "add_to_cart" | "add_to_wishlist" | "remove_from_cart" index.d.ts(422, 25): The last overload is declared here.

I don't know if it could be relationated.

goltra avatar Jul 14 '25 06:07 goltra

Hi there, I am not sure what your issue is, could you please rephrase it? Are you saying that using Modular API does not work?

MichaelVerdon avatar Jul 14 '25 09:07 MichaelVerdon

Firstly my function was like this and work but I have a warning in console inviting me to use Modular api:

const analytic = getAnalytics();
const trackScreen = async (screenName: string, screenClass: string) => {
        await analytic.logEvent('screen_view',{screen_name: screenName, screen_class: screenClass});
    }

I have change for this:

const analytic = getAnalytics();
const trackScreen = async (screenName: string, screenClass: string) => {
        logEvent(analytic, "screen_view", {screen_name: screenName, screen_class: screenClass});
    }

but my IDE (phpstorm) show a warning

Image

If I launch the app, it works, but it's quite confusing and makes you doubt if you're doing it correctly

goltra avatar Jul 14 '25 10:07 goltra

sorry, I have seen my mistake. I have to pass firebase_screen and firebase_screen_class instead of screen_name and screen_class

goltra avatar Jul 14 '25 10:07 goltra

Hi there, I am not sure what your issue is, could you please rephrase it? Are you saying that using Modular API does not work?

Hi @MichaelVerdon, the issue is that when using logScreenView I can see my screens names correctly on the firebase dashboard, but when using

await logEvent(analytics, 'screen_view', {
                firebase_screen: currentRouteName,
                firebase_screen_class: currentRouteName
});

All screens are logged as "UIViewController" for iOS or "MainActivity" for Android and not my screen names provided! so for now I'm sticking with logScreenView and accepting the warning.

Image

faljabi avatar Jul 14 '25 10:07 faljabi

Hi there, thanks for further clarification, so simply, the screen names are not logged properly when using the modular reference as opposed to namespaced (which does show the correct names of all of your screens)?

MichaelVerdon avatar Jul 14 '25 11:07 MichaelVerdon

I believe you were using the correct method before. logScreenView is a method that exists on Modular references here: https://github.com/invertase/react-native-firebase/blob/main/packages/analytics/lib/modular/index.d.ts#L682 What you were previously doing was the correct Modular approach.

Just stick to:

await logEvent(analytics, 'screen_view', {
                firebase_screen: currentRouteName,
                firebase_screen_class: currentRouteName
});

Another way you can tell its modular is that you pass analytics as a parameter through it.

MichaelVerdon avatar Jul 14 '25 11:07 MichaelVerdon

Please read my issue.

I am using logEvent but it does not log the screen names I provide. It just logs UIViewController instead of the name I pass. And if I use logScreenView (although I am using the modular API) I get the deprecation warning to use logEvent.

faljabi avatar Jul 14 '25 13:07 faljabi

Please read my issue.

I am using logEvent but it does not log the screen names I provide. It just logs UIViewController instead of the name I pass. And if I use logScreenView (although I am using the modular API) I get the deprecation warning to use logEvent.

Hi there, yes I realise that that function is meant to be deprecated as well https://github.com/invertase/react-native-firebase/blob/main/packages/analytics/tests/analytics.test.ts#L1085. I will keep investigating. Is this only being experienced on Android?

MichaelVerdon avatar Jul 14 '25 15:07 MichaelVerdon

Analytics should automatically track screens. Try putting this in your manifest for now and see if it works whilst the problem gets diagnosed.

<meta-data android:name="google_analytics_automatic_screen_reporting_enabled" android:value="true" />

MichaelVerdon avatar Jul 14 '25 15:07 MichaelVerdon

I do not want to automatically log screens, and it is happening for both iOS and Android as I mentioned earlier.

faljabi avatar Jul 14 '25 17:07 faljabi

Also note I posted my firebase json file where I disabled automatic screen view logging.

faljabi avatar Jul 14 '25 17:07 faljabi

Using logEvent with "screen_view" does not work because of this issue: https://github.com/invertase/react-native-firebase/issues/8612

andrewwardmt avatar Jul 16 '25 12:07 andrewwardmt

It seems like logEvent is not working properly on Android or iOS and logScreenView has been deprecated.

alvinisasi avatar Jul 17 '25 07:07 alvinisasi

The call you use to logScreenView is here as I mentioned before and we should be using logEvent here instead. Ill talk with the team and see if I can go ahead and migrate it to logEvent as logScreenView is deprecated.

MichaelVerdon avatar Jul 21 '25 06:07 MichaelVerdon

Hi there, having investigated further, we do use logEvent here and it should work as logScreenView does use logEvent under the hood so we know logEvent should work. It could be down to how you are passing names in. You can see here for more information https://reactnavigation.org/docs/screen-tracking/ and mimic here https://rnfirebase.io/analytics/screen-tracking except using logEvent instead

MichaelVerdon avatar Jul 21 '25 07:07 MichaelVerdon

The docs there use logScreenView which raises a deprecation message. Using logEvent as documented by the Firebase modular web API:

logEvent(getAnalytics(), "screen_view", {
        firebase_screen: screenName, 
        firebase_screen_class: screenName,
});

produces the following error:

[App.debug.dylib] 11.15.0 - [FirebaseAnalytics][I-removed]
Parameter name uses reserved prefix. Ignoring parameter: firebase_screen
[App.debug.dylib] 11.15.0 - [FirebaseAnalytics][I-removed]
Parameter name uses reserved prefix. Ignoring parameter:
firebase_screen_class

Are you saying we should be doing this instead?

logEvent(getAnalytics(), "screen_view", {
        screen_name: screenName, 
        screen_class: screenName,
});

It would be great if this could be documented as this does not match the Firebase modular web API

andrewwardmt avatar Jul 21 '25 09:07 andrewwardmt

+1

Facing the same issue as @andrewwardmt. Documented my side from the Firebase debug console, showing that it is throwing an error as well link.

If this is so, then the typing here needs to be updated as well then

NX-Michael avatar Jul 21 '25 09:07 NX-Michael

Facing the same issue. I've tested this solution on Android Emulator & Firebase Console DebugView and it works:

await logEvent(analytics, 'screen_view', {
  screen_name: screenName,
  screen_class: screenName,
})

The only issue is it gives following typescript error: Image

So it should be either adjusted to use:

firebase_screen: screenName, 
firebase_screen_class: screenName,

or it should accept screen_name & screen_class

dawidzawada avatar Jul 21 '25 11:07 dawidzawada

Yes, I know and this is the bug. Hope can resolve because has no sense use different parameters depending platform and have a typescript error

goltra avatar Jul 21 '25 11:07 goltra

+1 after updating to modular api, the screen names are not logged correctly anymore

tux2nicolae avatar Jul 22 '25 08:07 tux2nicolae

+1 having the same exact issues :

  • when using the old way (which is the one documented) I get the deprecation warning.
  • when using the new modular :
    • if I use firebase_screen and firebase_screen_class I get a warning saying these options a re being ignored.
    • if I use screen_name and screen_class I get a typescript error saying : Argument of type '"screen_view"' is not assignable to parameter of type '"add_to_cart" | "add_to_wishlist" | "remove_from_cart"'.

The documentation needs to be updated and include a clear and correct way on how to use the new modular approach...

MKSisti avatar Jul 23 '25 13:07 MKSisti

I'm seeing this issue too. We're looking to migrate our analytics to Firebase, and my first impression is that the documentation does not match the API at all.

The docs say:

logScreenView(params: ScreenViewParameters): Promise<void>;

So I do this:

logScreenView(getAnalytics(), { screen_name: screenName, screen_class: screenName });

But I get a warning:

This method is deprecated (as well as all React Native Firebase namespaced API) and will be removed in the next major release as part of move to match Firebase Web modular SDK API. Please see migration guide for more details: https://rnfirebase.io/migrating-to-v22. Method called was `logScreenView`. Please use `logEvent()` instead.

So I change it to this, which matches the API spec here:

logEvent(getAnalytics(), 'screen_view', {
    firebase_screen: screenName,
    firebase_screen_class: screenName,
  });

But now I get an error in logcat (not even in the React Native console? It's a good thing I checked!):

 E  Name starts with reserved prefix. Type, name: event param, firebase_screen
 E  Name starts with reserved prefix. Type, name: event param, firebase_screen_class

After some googling, I try this:

logEvent(getAnalytics(), 'screen_view', {
    screen_name: screenName,
    screen_class: screenName,
  });

But I get a type error:

No overload matches this call.
  The last overload gave the following error.
    Argument of type '"screen_view"' is not assignable to parameter of type '"add_to_cart" | "add_to_wishlist" | "remove_from_cart"'.ts(2769)

Given that the documentation is entirely out of sync with the API spec and the native SDK, I get the impression that this package is unmaintained and unreliable.

peterfajner-ensemble avatar Aug 08 '25 18:08 peterfajner-ensemble

Definitive answer, the way to go v22+ screen tracking is:

logEvent(getAnalytics(), 'screen_view' as any, {
  screen_class: fullRouteName,
  screen_name: fullRouteName,
});

Looks like it's just a typing issue, hopefully that will get fixed. As you can see, in GA backend it gets reported the same way as usual:

Image

The depreciation of this method definitely warrants at least a mention in the v22 migration guide, as it was confusing for a second after I was 99% sure that I'd moved entirely to the new import system and it wasn't related to this.

This shows a deprecation error in strict mode:

logScreenView(getAnalytics(), {
                screen_class: fullRouteName,
                screen_name: fullRouteName,
});
// Causes warning, "Method called was `logScreenView`. Please use `logEvent()` instead. "

Then when we use logEvent() with firebase screen params, it won't report due to reserved names:

Image

So I am guessing this will be the answer in the future, once the typings are fixed?

logEvent(getAnalytics(), 'screen_view', {
  screen_class: fullRouteName,
  screen_name: fullRouteName,
});

(Just realised this is mostly the same comment as above, oh well). Am hoping that the change of parameter config won't interrupt reports, too.

TaylorDale avatar Aug 10 '25 03:08 TaylorDale

I have seen there is a new version (23) and I update package.. Now the error Event parameter name is reserved has disappear but in iOS screen_view doesn't work.

I haven't test in Android.

goltra avatar Aug 12 '25 10:08 goltra

Looking into this

@peterfajner-ensemble -->

Given that the documentation is entirely out of sync with the API spec and the native SDK, I get the impression that this package is unmaintained and unreliable.

Neither is the case however it is true that we are dealing with a few large-scale changes that cross-cut the entire set of packages at once - the API move from namespaced to modular for firebase ecosystem compatibility - as well as the react-native move to New Architecture (which implies a move to typescript and native code rewrite.

To keep things spicy there's been the tiny matter of AI becoming ascendant and the need to spin up the vertexai (soon to be just "ai") package.

All to say, it's busy here. We're doing our best but have resource constraints just like everyone, we do appreciate the patience

mikehardy avatar Aug 12 '25 14:08 mikehardy

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

github-actions[bot] avatar Sep 09 '25 14:09 github-actions[bot]

I opened a pr to fix the issue, keep it open, please. (Hope this comment marks it as active)

GoodSir42 avatar Sep 09 '25 14:09 GoodSir42

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

github-actions[bot] avatar Oct 07 '25 15:10 github-actions[bot]

The issue is still not stale, because there is a pr fixing it

GoodSir42 avatar Oct 07 '25 15:10 GoodSir42