From 029922128717f3e560ebfd0a9a52a95d9bf42519 Mon Sep 17 00:00:00 2001 From: MohamadKh75 Date: Thu, 28 Jan 2021 01:00:03 +0330 Subject: [PATCH] Update screen-tracking.md --- versioned_docs/version-5.x/screen-tracking.md | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) 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() { {/* ... */} ); -} +}; + ```