diff options
author | Ivan Chen <ivan@tagg.id> | 2021-04-14 16:36:08 -0400 |
---|---|---|
committer | Ivan Chen <ivan@tagg.id> | 2021-04-14 16:36:08 -0400 |
commit | 51baf2073e884a1585756993237d54bdad35b774 (patch) | |
tree | 8e4052e758e35915612d76989f5ed138f25b19b3 /src/App.tsx | |
parent | 0c6a50bb54499dca981e0ca72da6f1bfbbf0d724 (diff) |
added logic to log screen views
Diffstat (limited to 'src/App.tsx')
-rw-r--r-- | src/App.tsx | 22 |
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 /> |