Skip to content

Commit ca7c96e

Browse files
committed
Update guide for screen tracking
1 parent 31e8084 commit ca7c96e

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

docs/screen-tracking.md

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,31 +33,23 @@ const getActiveRouteName = state => {
3333
};
3434

3535
export default function App() {
36-
const navigationRef = React.useRef();
3736
const routeNameRef = React.useRef();
3837

3938
return (
4039
<NavigationNativeContainer
4140
ref={navigationRef}
42-
onStateChange={() => {
43-
const navigation = navigationRef.current;
44-
45-
if (navigation) {
46-
const previousRouteName = routeNameRef.current;
47-
const currentRouteName = getActiveRouteName(
48-
// Get the root navigator state to find the active route
49-
navigation.getRootState()
50-
);
51-
52-
if (previousRouteName !== currentRouteName) {
53-
// The line below uses the @react-native-firebase/analytics tracker
54-
// Change this line to use another Mobile analytics SDK
55-
analytics().setCurrentScreen(currentRouteName, currentRouteName);
56-
}
57-
58-
// Save the current route name for later comparision
59-
routeNameRef.current = currentRouteName;
41+
onStateChange={state => {
42+
const previousRouteName = routeNameRef.current;
43+
const currentRouteName = getActiveRouteName(state);
44+
45+
if (previousRouteName !== currentRouteName) {
46+
// The line below uses the @react-native-firebase/analytics tracker
47+
// Change this line to use another Mobile analytics SDK
48+
analytics().setCurrentScreen(currentRouteName, currentRouteName);
6049
}
50+
51+
// Save the current route name for later comparision
52+
routeNameRef.current = currentRouteName;
6153
}}
6254
>
6355
{/* ... */}

0 commit comments

Comments
 (0)