Skip to content

Commit bc26293

Browse files
docs: update Screen Tracking example to remove expo-firebase-analytics (react-navigation#1183)
* docs: update Screen Tracking example to be generic * Add mock implementation of tracker * Apply feedback * Update screen-tracking.md
1 parent 355399a commit bc26293

File tree

4 files changed

+22
-29
lines changed

4 files changed

+22
-29
lines changed

static/examples/5.x/screen-tracking-for-analytics.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as React from 'react';
22
import { View, Button } from 'react-native';
3-
// import * as Analytics from 'expo-firebase-analytics';
43
import { NavigationContainer } from '@react-navigation/native';
54
import { createStackNavigator } from '@react-navigation/stack';
65

@@ -32,20 +31,19 @@ export default function App() {
3231
return (
3332
<NavigationContainer
3433
ref={navigationRef}
35-
onReady={() => routeNameRef.current = navigationRef.current.getCurrentRoute().name}
34+
onReady={() =>
35+
(routeNameRef.current = navigationRef.current.getCurrentRoute().name)
36+
}
3637
onStateChange={() => {
3738
const previousRouteName = routeNameRef.current;
38-
const currentRouteName = navigationRef.current.getCurrentRoute().name
39+
const currentRouteName = navigationRef.current.getCurrentRoute().name;
3940

4041
if (previousRouteName !== currentRouteName) {
41-
// The line below uses the expo-firebase-analytics tracker
42-
// https://docs.expo.io/versions/latest/sdk/firebase-analytics/
43-
// Change this line to use another Mobile analytics SDK
44-
// Analytics.setCurrentScreen(currentRouteName, currentRouteName);
42+
// Replace the line below to add the tracker from a mobile analytics SDK
4543
alert(`The route changed to ${currentRouteName}`);
4644
}
4745

48-
// Save the current route name for later comparision
46+
// Save the current route name for later comparison
4947
routeNameRef.current = currentRouteName;
5048
}}
5149
>

static/examples/6.x/screen-tracking-for-analytics.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as React from 'react';
22
import { View, Button } from 'react-native';
3-
// import * as Analytics from 'expo-firebase-analytics';
43
import { NavigationContainer } from '@react-navigation/native';
54
import { createStackNavigator } from '@react-navigation/stack';
65

@@ -40,14 +39,11 @@ export default function App() {
4039
const currentRouteName = navigationRef.current.getCurrentRoute().name;
4140

4241
if (previousRouteName !== currentRouteName) {
43-
// The line below uses the expo-firebase-analytics tracker
44-
// https://docs.expo.io/versions/latest/sdk/firebase-analytics/
45-
// Change this line to use another Mobile analytics SDK
46-
// Analytics.setCurrentScreen(currentRouteName, currentRouteName);
42+
// Replace the line below to add the tracker from a mobile analytics SDK
4743
alert(`The route changed to ${currentRouteName}`);
4844
}
4945

50-
// Save the current route name for later comparision
46+
// Save the current route name for later comparison
5147
routeNameRef.current = currentRouteName;
5248
}}
5349
>

versioned_docs/version-5.x/screen-tracking.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ To get notified of state changes, we can use the `onStateChange` prop on `Naviga
1313

1414
## Example
1515

16-
This example shows how to do screen tracking and send to Firebase Analytics using [expo-firebase-analytics](https://docs.expo.io/versions/latest/sdk/firebase-analytics/). The approach can be adapted to any other analytics SDK.
16+
This example shows how the approach can be adapted to any mobile analytics SDK.
1717

18-
<samp id="screen-tracking-for-analytics" />
18+
<samp id="screen-tracking-for-analytics" />
1919

2020
```js
21-
import * as Analytics from 'expo-firebase-analytics';
2221
import { useRef } from 'react';
2322
import { NavigationContainer } from '@react-navigation/native';
2423

@@ -35,12 +34,13 @@ export default () => {
3534
onStateChange={async () => {
3635
const previousRouteName = routeNameRef.current;
3736
const currentRouteName = navigationRef.current.getCurrentRoute().name;
37+
const trackScreenView = () => {
38+
// Your implementation of analytics goes here!
39+
};
3840

3941
if (previousRouteName !== currentRouteName) {
40-
// The line below uses the expo-firebase-analytics tracker
41-
// https://docs.expo.io/versions/latest/sdk/firebase-analytics/
42-
// Change this line to use another Mobile analytics SDK
43-
await Analytics.setCurrentScreen(currentRouteName);
42+
// Replace the line below to add the tracker from a mobile analytics SDK
43+
await trackScreenView(currentRouteName);
4444
}
4545

4646
// Save the current route name for later comparison
@@ -51,5 +51,4 @@ export default () => {
5151
</NavigationContainer>
5252
);
5353
};
54-
5554
```

versioned_docs/version-6.x/screen-tracking.md

100755100644
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ To get notified of state changes, we can use the `onStateChange` prop on `Naviga
1313

1414
## Example
1515

16-
This example shows how to do screen tracking and send to Firebase Analytics using [expo-firebase-analytics](https://docs.expo.io/versions/latest/sdk/firebase-analytics/). The approach can be adapted to any other analytics SDK.
16+
This example shows how the approach can be adapted to any mobile analytics SDK.
1717

18-
<samp id="screen-tracking-for-analytics" />
18+
<samp id="screen-tracking-for-analytics" />
1919

2020
```js
21-
import * as Analytics from 'expo-firebase-analytics';
2221
import {
2322
NavigationContainer,
2423
useNavigationContainerRef,
@@ -37,15 +36,16 @@ export default () => {
3736
onStateChange={async () => {
3837
const previousRouteName = routeNameRef.current;
3938
const currentRouteName = navigationRef.getCurrentRoute().name;
39+
const trackScreenView = () => {
40+
// Your implementation of analytics goes here!
41+
};
4042

4143
if (previousRouteName !== currentRouteName) {
4244
// Save the current route name for later comparison
4345
routeNameRef.current = currentRouteName;
4446

45-
// The line below uses the expo-firebase-analytics tracker
46-
// https://docs.expo.io/versions/latest/sdk/firebase-analytics/
47-
// Change this line to use another Mobile analytics SDK
48-
await Analytics.setCurrentScreen(currentRouteName);
47+
// Replace the line below to add the tracker from a mobile analytics SDK
48+
await trackScreenView(currentRouteName);
4949
}
5050
}}
5151
>

0 commit comments

Comments
 (0)