Search code examples
react-nativegoogle-analytics-apifirebase-analytics

In a Reactive-native app how to change the screen name of a page for better view in google Analytics


I tried to do it this way (On the main page):

import analytics from '@react-native-firebase/analytics'

 const trackPageView = (title) => {
    analytics().logEvent('page_view', {
      screen_name: title,
      screen_class: title,
    })
  }

  useEffect(() => {
    trackPageView("Main_page")
  }, []);

But this name doesn't show at all on the Analytics dashboard

I saw in the documentation this way of doing it, but I didn't understand how to make it work or even where to put it

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

Solution

  • Use logScreenView like this:

    await analytics().logScreenView({
      screen_name: <route-name>,
      screen_class: <route-name>
    });