Skip to content

Commit 22e82b5

Browse files
jamschsatya164
authored andcommitted
update(screen-tracking) change analytics module example (react-navigation#555)
The repository for `react-native-google-analytics-bridge` has now been archived and users are now recommended to use `@react-native-firebase/analytics`. This commit changes the example to use the more relevant library.
1 parent b42dce6 commit 22e82b5

File tree

3 files changed

+15
-21
lines changed

3 files changed

+15
-21
lines changed

docs/screen-tracking.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@ This example shows how to do screen tracking and send to Google Analytics. The a
1717

1818
```js
1919
import * as React from 'react';
20-
import { GoogleAnalyticsTracker } from 'react-native-google-analytics-bridge';
20+
import analytics from '@react-native-firebase/analytics';
2121
import { NavigationNativeContainer } from '@react-navigation/native';
2222

23-
const tracker = new GoogleAnalyticsTracker(GA_TRACKING_ID);
24-
2523
// Gets the current screen from navigation state
2624
const getActiveRouteName = state => {
2725
const route = state.routes[state.index];
@@ -52,9 +50,9 @@ export default function App() {
5250
);
5351

5452
if (previousRouteName !== currentRouteName) {
55-
// The line below uses the Google Analytics tracker
53+
// The line below uses the @react-native-firebase/analytics tracker
5654
// Change this line to use another Mobile analytics SDK
57-
tracker.trackScreenView(currentRouteName);
55+
analytics().setCurrentScreen(currentRouteName, currentRouteName);
5856
}
5957

6058
// Save the current route name for later comparision

website/versioned_docs/version-3.x/screen-tracking.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ This example shows how to do screen tracking and send to Google Analytics. The a
1111

1212
```js
1313
import { createAppContainer, createStackNavigator } from 'react-navigation';
14-
import { GoogleAnalyticsTracker } from 'react-native-google-analytics-bridge';
15-
16-
const tracker = new GoogleAnalyticsTracker(GA_TRACKING_ID);
14+
import analytics from '@react-native-firebase/analytics';
1715

1816
// gets the current screen from navigation state
1917
function getActiveRouteName(navigationState) {
@@ -34,13 +32,13 @@ const AppContainer = createAppContainer(AppNavigator);
3432
export default () => (
3533
<AppContainer
3634
onNavigationStateChange={(prevState, currentState, action) => {
37-
const currentScreen = getActiveRouteName(currentState);
38-
const prevScreen = getActiveRouteName(prevState);
35+
const currentRouteName = getActiveRouteName(currentState);
36+
const previousRouteName = getActiveRouteName(prevState);
3937

40-
if (prevScreen !== currentScreen) {
41-
// the line below uses the Google Analytics tracker
38+
if (previousRouteName !== currentRouteName) {
39+
// The line below uses the @react-native-firebase/analytics tracker
4240
// change the tracker here to use other Mobile analytics SDK.
43-
tracker.trackScreenView(currentScreen);
41+
analytics().setCurrentScreen(currentRouteName, currentRouteName);
4442
}
4543
}}
4644
/>

website/versioned_docs/version-4.x/screen-tracking.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ This example shows how to do screen tracking and send to Google Analytics. The a
1111

1212
```js
1313
import { createAppContainer, createStackNavigator } from 'react-navigation';
14-
import { GoogleAnalyticsTracker } from 'react-native-google-analytics-bridge';
15-
16-
const tracker = new GoogleAnalyticsTracker(GA_TRACKING_ID);
14+
import analytics from '@react-native-firebase/analytics';
1715

1816
// gets the current screen from navigation state
1917
function getActiveRouteName(navigationState) {
@@ -34,13 +32,13 @@ const AppContainer = createAppContainer(AppNavigator);
3432
export default () => (
3533
<AppContainer
3634
onNavigationStateChange={(prevState, currentState, action) => {
37-
const currentScreen = getActiveRouteName(currentState);
38-
const prevScreen = getActiveRouteName(prevState);
35+
const currentRouteName = getActiveRouteName(currentState);
36+
const previousRouteName = getActiveRouteName(prevState);
3937

40-
if (prevScreen !== currentScreen) {
41-
// the line below uses the Google Analytics tracker
38+
if (previousRouteName !== currentRouteName) {
39+
// the line below uses the @react-native-firebase/analytics tracker
4240
// change the tracker here to use other Mobile analytics SDK.
43-
tracker.trackScreenView(currentScreen);
41+
analytics().setCurrentScreen(currentRouteName, currentRouteName);
4442
}
4543
}}
4644
/>

0 commit comments

Comments
 (0)