Screen Tracking

Track Analytics screen views with logScreenView() and ScreenViewParameters via React Navigation or React Native Navigation listeners.

Prerequisites

  • @react-native-firebase/app and @react-native-firebase/analytics installed per Analytics usage (native config completed, New Architecture required from v26).
  • A navigation library if you want automatic screen-name wiring: React Navigation or wix/react-native-navigation. Manual logScreenView calls work without either.
  • Disable automatic native screen reporting in firebase.json when you want only your manual screen_view events (see Disable screenview tracking).

Example Expo Router screen: https://github.com/invertase/react-native-firebase/blob/main/test-expo/app/analytics.tsx

Manual screen views

Standard React Native applications run inside a single Activity/ViewController, so native Firebase SDKs do not see JavaScript navigation screen changes automatically. Call logScreenView with ScreenViewParameters (screen_name, screen_class) whenever the visible route changes. It logs a screen_view event, so logEvent(getAnalytics(), 'screen_view', { screen_name, screen_class }) is equivalent. When screen_class is not set, Analytics sets a default value based on the UIViewController or Activity in focus, which is the same native class for every JavaScript screen. The firebase-js-sdk setCurrentScreen function is not exported by React Native Firebase; use logScreenView instead.

js
import { getAnalytics, logScreenView } from '@react-native-firebase/analytics';

async function trackAnalyticsScreen(screenName, screenClass) {
  await logScreenView(getAnalytics(), {
    screen_name: screenName,
    screen_class: screenClass,
  });
}

await trackAnalyticsScreen('ProductDetails', 'ProductDetails');

React Navigation

The React Navigation library allows for various navigation techniques such as Stack, Tab, Native or even custom navigation. The NavigationContainer component which the library exposes provides access to the current navigation state when a screen changes, allowing you to use the logScreenView method the Analytics library provides:

jsx
// codeblock-ignore: imports @react-navigation/native, a third-party package that is not a dependency of React Native Firebase
import React from 'react';
import { Text } from 'react-native';
import { getAnalytics, logScreenView } from '@react-native-firebase/analytics';
import { NavigationContainer } from '@react-navigation/native';

const App = () => {
  const routeNameRef = React.useRef();
  const navigationRef = React.useRef();
  return (
    <NavigationContainer
      ref={navigationRef}
      onReady={() => {
        routeNameRef.current = navigationRef.current.getCurrentRoute().name;
      }}
      onStateChange={async () => {
        const previousRouteName = routeNameRef.current;
        const currentRouteName = navigationRef.current.getCurrentRoute().name;

        if (previousRouteName !== currentRouteName) {
          await logScreenView(getAnalytics(), {
            screen_name: currentRouteName,
            screen_class: currentRouteName,
          });
        }
        routeNameRef.current = currentRouteName;
      }}
    >
      <Text>Replace with your root navigator</Text>
    </NavigationContainer>
  );
};

export default App;

For a full working example, view the Screen tracking for analytics documentation on the React Navigation website.

React Native Navigation

The wix/react-native-navigation provides 100% native platform navigation for React Native apps. To manually track screens, you need to setup a componentDidAppear event listener and manually call the logScreenView method the Analytics library provides:

js
// codeblock-ignore: imports react-native-navigation, a third-party package that is not a dependency of React Native Firebase
import { getAnalytics, logScreenView } from '@react-native-firebase/analytics';
import { Navigation } from 'react-native-navigation';

Navigation.events().registerComponentDidAppearListener(async ({ componentName, componentType }) => {
  if (componentType === 'Component') {
    await logScreenView(getAnalytics(), {
      screen_name: componentName,
      screen_class: componentName,
    });
  }
});

To learn more, view the events documentation on the React Native Navigation website.

On this page