diff --git a/react-app/src/navigation/AppRouter.tsx b/react-app/src/navigation/AppRouter.tsx index cc673761..8f85831e 100644 --- a/react-app/src/navigation/AppRouter.tsx +++ b/react-app/src/navigation/AppRouter.tsx @@ -12,51 +12,54 @@ import AppScaffold from "../components/AppScaffold/AppScaffold"; import ProposalDetailRouter from "../components/ProposalDetailScreen/ProposalDetailRouter"; import ValidatorDetailScreen from "../components/ValidatorDetailScreen/ValidatorDetailScreen"; import ValidatorScreen from "../components/ValidatorScreen/ValidatorScreen"; +import AnalyticsProvider from "../providers/AnalyticsProvider"; import AppRoutes from "./AppRoutes"; const AppRouter: React.FC = () => { const wallet = useWallet(); return ( - - }> - } /> - } /> - } /> - } /> - } - /> - } - /> + + + }> + } /> + } /> + } /> + } /> + } + /> + } + /> + } + /> + } /> + } + /> + + } + path={AppRoutes.NotFound} + element={} /> - } /> } + path={AppRoutes.ErrorInvalidAddress} + element={} /> - - - } - /> - } - /> - } /> - + } /> + - {wallet.status === ConnectionStatus.Connecting && ( - - )} + {wallet.status === ConnectionStatus.Connecting && ( + + )} + ); }; diff --git a/react-app/src/providers/AnalyticsProvider.tsx b/react-app/src/providers/AnalyticsProvider.tsx new file mode 100644 index 00000000..8048eff3 --- /dev/null +++ b/react-app/src/providers/AnalyticsProvider.tsx @@ -0,0 +1,37 @@ +import React, { useEffect, useState } from "react"; +import * as ReactGA from "react-ga"; +import { useLocation } from "react-router-dom"; +import Config from "../config/Config"; + +interface AnalyticsProviderProps { + children?: React.ReactNode; +} + +const AnalyticsContext = React.createContext(null as any); + +const AnalyticsProvider: React.FC = (props) => { + const { children } = props; + const [isInitialized, setIsInitialized] = useState(false); + const location = useLocation(); + + useEffect(() => { + if (!isInitialized) return; + + ReactGA.pageview(location.pathname + location.search); + }, [isInitialized, location]); + + useEffect(() => { + if (Config.googleAnalyticsId) { + ReactGA.initialize(Config.googleAnalyticsId); + } + setIsInitialized(true); + }, []); + + return ( + + {isInitialized && children} + + ); +}; + +export default AnalyticsProvider;