diff --git a/versioned_docs/version-5.x/screen-tracking.md b/versioned_docs/version-5.x/screen-tracking.md
index 2ea4805d49b..cfd320f0b23 100755
--- a/versioned_docs/version-5.x/screen-tracking.md
+++ b/versioned_docs/version-5.x/screen-tracking.md
@@ -18,27 +18,32 @@ This example shows how to do screen tracking and send to Firebase Analytics usin
```js
-import * as React from 'react';
import * as Analytics from 'expo-firebase-analytics';
+import { useRef } from 'react';
import { NavigationContainer } from '@react-navigation/native';
-export default function App() {
- const routeNameRef = React.useRef();
- const navigationRef = React.useRef();
+export default () => {
+ const navigationRef = useRef();
+ const routeNameRef = useRef();
return (
routeNameRef.current = navigationRef.current.getCurrentRoute().name}
- onStateChange={() => {
+ onReady={() =>
+ (routeNameRef.current = navigationRef.current.getCurrentRoute().name)
+ }
+ onStateChange={async () => {
const previousRouteName = routeNameRef.current;
- const currentRouteName = navigationRef.current.getCurrentRoute().name
+ const currentRouteName = navigationRef.current.getCurrentRoute().name;
if (previousRouteName !== currentRouteName) {
// The line below uses the expo-firebase-analytics tracker
// https://docs.expo.io/versions/latest/sdk/firebase-analytics/
// Change this line to use another Mobile analytics SDK
- Analytics.setCurrentScreen(currentRouteName);
+ await analytics().logScreenView({
+ screen_name: currentRouteName,
+ screen_class: currentRouteName
+ });
}
// Save the current route name for later comparison
@@ -48,5 +53,6 @@ export default function App() {
{/* ... */}
);
-}
+};
+
```