aboutsummaryrefslogtreecommitdiff
path: root/src/App.tsx
diff options
context:
space:
mode:
authorIvan Chen <ivan@tagg.id>2021-04-14 23:13:20 -0400
committerGitHub <noreply@github.com>2021-04-14 23:13:20 -0400
commit2051515252c335ff71242830bdbd30331ab783d1 (patch)
tree529b0815c81e0f44c7fc13b6d9206c2aed61c0bc /src/App.tsx
parentbe07e46929587244adfb816fa8a5170af267a976 (diff)
parent51baf2073e884a1585756993237d54bdad35b774 (diff)
Merge pull request #366 from IvanIFChen/tma778-add-analytics
[TMA-778] Add Analytics
Diffstat (limited to 'src/App.tsx')
-rw-r--r--src/App.tsx22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/App.tsx b/src/App.tsx
index 8d823e1f..64f40bae 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -1,9 +1,11 @@
+import analytics from '@react-native-firebase/analytics';
import {NavigationContainer} from '@react-navigation/native';
-import React, {useState} from 'react';
+import React, {useRef, useState} from 'react';
import {Provider} from 'react-redux';
import {StreamChat} from 'stream-chat';
import {OverlayProvider} from 'stream-chat-react-native';
import {STREAM_CHAT_API} from './constants';
+import {getActiveRouteName} from './RootNavigation';
import {navigationRef} from './RootNavigation';
import Routes from './routes';
import store from './store/configureStore';
@@ -23,6 +25,7 @@ import {isIPhoneX} from './utils';
export const ChatContext = React.createContext({} as ChatContextType);
const App = () => {
+ const routeNameRef = useRef();
const [channel, setChannel] = useState<ChannelGroupedType>();
const chatClient = StreamChat.getInstance<
LocalAttachmentType,
@@ -34,11 +37,20 @@ const App = () => {
LocalUserType
>(STREAM_CHAT_API);
return (
- /**
- * This is the provider from the redux store, it acts as the root provider for our application
- */
<Provider store={store}>
- <NavigationContainer ref={navigationRef}>
+ <NavigationContainer
+ ref={navigationRef}
+ onStateChange={async (state) => {
+ const previousRouteName = routeNameRef.current;
+ const currentRouteName = getActiveRouteName(state);
+ if (previousRouteName !== currentRouteName) {
+ await analytics().logScreenView({
+ screen_name: currentRouteName,
+ screen_class: currentRouteName,
+ });
+ }
+ routeNameRef.current = currentRouteName;
+ }}>
<OverlayProvider bottomInset={isIPhoneX() ? 80 : 50}>
<ChatContext.Provider value={{channel, setChannel, chatClient}}>
<Routes />