diff --git a/public/index.html b/public/index.html index bedd85cc..5ad112b3 100644 --- a/public/index.html +++ b/public/index.html @@ -1,6 +1,16 @@
+ + + + diff --git a/src/App.js b/src/App.js index eb2c5ca2..acb66aa2 100755 --- a/src/App.js +++ b/src/App.js @@ -23,12 +23,14 @@ import { importAll } from './components/ImageBanner'; import preloadImages from './utils/preloadImages'; import showNewVersionToast from './utils/showNewVersionToast'; import useError from './hooks/useError'; +import useGoogleAnalytics from './hooks/useGoogleAnalytics'; import useInfo from './hooks/useInfo'; import useSuccess from './hooks/useSuccess'; import packageJson from '../package.json'; const commitRef = process?.env?.REACT_APP_COMMIT_REF || ''; export default function App() { + const { bodyStyle, setBodyStyle, @@ -44,6 +46,7 @@ export default function App() { const location = useLocation(); const isElectron = window.electron && window.electron.isElectron; + useGoogleAnalytics(); useEffect(() => { if (location.state?.scrollToTop) { diff --git a/src/hooks/useGoogleAnalytics.js b/src/hooks/useGoogleAnalytics.js new file mode 100644 index 00000000..626d0d89 --- /dev/null +++ b/src/hooks/useGoogleAnalytics.js @@ -0,0 +1,25 @@ +import { useEffect } from 'react'; +import { useLocation } from 'react-router-dom'; + +const GA_MEASUREMENT_ID = "G-2M2VYEFL7B"; + +const useGoogleAnalytics = () => { + const location = useLocation(); + +useEffect(() => { + if (typeof window.gtag === 'function') { + const fullPath = location.pathname + location.search + location.hash; + window.gtag('config', GA_MEASUREMENT_ID, { + 'page_path': fullPath, + }); + window.gtag('event', 'page_view', { + 'page_path': fullPath, + 'page_location': window.location.href.replace('/#', '') + }); + + } +}, [location]); + +}; + +export default useGoogleAnalytics;