diff --git a/package.json b/package.json index 1b223051d..c94da17cc 100644 --- a/package.json +++ b/package.json @@ -70,6 +70,7 @@ "react": "^16.13.1", "react-compound-slider": "^2.5.0", "react-dom": "^16.13.1", + "react-ga": "^3.3.0", "react-loading-skeleton": "^2.1.1", "react-modal": "^3.11.2", "react-phone-input-2": "^2.13.8", diff --git a/src/App.js b/src/App.js index a6ab99243..a0cbcfb43 100644 --- a/src/App.js +++ b/src/App.js @@ -1,10 +1,16 @@ -import React, { StrictMode } from 'react'; +import React, { StrictMode, useEffect } from 'react'; import { Provider } from 'react-redux'; import { PersistGate } from 'redux-persist/integration/react'; import AppRouter from 'routers/AppRouter'; import Preloader from 'components/ui/Preloader'; +import ReactGA from "react-ga"; -const App = ({ store, persistor }) => ( + +const App = ({ store, persistor }) => { + useEffect(()=>{ + ReactGA.initialize('Your-GA-ID') + }, []) + return( } persistor={persistor}> @@ -12,6 +18,6 @@ const App = ({ store, persistor }) => ( -); +)}; export default App; diff --git a/src/routers/AppRouter.js b/src/routers/AppRouter.js index 791a49c3b..c93f0a9b8 100644 --- a/src/routers/AppRouter.js +++ b/src/routers/AppRouter.js @@ -30,9 +30,14 @@ import AdminRoute from './AdminRoute'; import Shop from 'views/shop'; import FeaturedProducts from 'views/featured'; import RecommendedProducts from 'views/recommended'; +import ReactGA from "react-ga"; export const history = createBrowserHistory(); +history.listen((location) => { + ReactGA.pageview(location.pathname); +}); + const AppRouter = () => (