diff --git a/package.json b/package.json index da2c605..8988d10 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,6 @@ "prop-types": "^15.8.1", "react": "^18.2.0", "react-dom": "^18.2.0", - "react-ga": "^3.3.1", "react-google-recaptcha": "^2.1.0", "react-router-dom": "^5.3.3", "typescript": "^4.7.4", diff --git a/public/index.html b/public/index.html index 90db654..25fe9d2 100644 --- a/public/index.html +++ b/public/index.html @@ -14,6 +14,19 @@ Find Open-source projects with a social impact + + + diff --git a/src/components/Header.tsx b/src/components/Header.tsx index 62eadba..45e5f54 100644 --- a/src/components/Header.tsx +++ b/src/components/Header.tsx @@ -7,7 +7,10 @@ import Typography from '@mui/material/Typography'; import { Link as RouterLink } from 'react-router-dom'; +import useMinimalGaTracker from '../components/useMinimalGaTracker'; + export default function PageHeader() { + useMinimalGaTracker(); return (
diff --git a/src/components/useMinimalGaTracker.tsx b/src/components/useMinimalGaTracker.tsx new file mode 100644 index 0000000..98143f2 --- /dev/null +++ b/src/components/useMinimalGaTracker.tsx @@ -0,0 +1,17 @@ +import { useEffect } from 'react'; +import { useLocation } from 'react-router-dom'; + +const useMinimalGaTracker = () => { + const location = useLocation(); + + useEffect(() => { + if (!window.gtag) { + return; + } + window.gtag('config', 'G-C9SQS63TJQ', { + page_path: location.pathname + location.search, + }); + }, [location]); +}; + +export default useMinimalGaTracker; diff --git a/src/gtag.d.ts b/src/gtag.d.ts new file mode 100644 index 0000000..a6d0bcd --- /dev/null +++ b/src/gtag.d.ts @@ -0,0 +1,4 @@ +interface Window { + gtag(...args: any[]): void; +} + \ No newline at end of file diff --git a/src/index.tsx b/src/index.tsx index 987c836..bb97249 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,12 +1,8 @@ import React from 'react'; import { createRoot } from 'react-dom/client'; -import ReactGA from 'react-ga'; import App from './App'; -ReactGA.initialize('UA-177770802-1'); -ReactGA.pageview(window.location.pathname + window.location.search); - const root = createRoot(document.getElementById('root') as HTMLElement); root.render( diff --git a/yarn.lock b/yarn.lock index 5f131a1..2fd52c1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8829,11 +8829,6 @@ react-error-overlay@^6.0.11: resolved "https://registry.yarnpkg.com/react-error-overlay/-/react-error-overlay-6.0.11.tgz#92835de5841c5cf08ba00ddd2d677b6d17ff9adb" integrity sha512-/6UZ2qgEyH2aqzYZgQPxEnz33NJ2gNsnHA2o5+o4wW9bLM/JYQitNP9xPhsXwC08hMMovfGe/8retsdDsczPRg== -react-ga@^3.3.1: - version "3.3.1" - resolved "https://registry.yarnpkg.com/react-ga/-/react-ga-3.3.1.tgz#d8e1f4e05ec55ed6ff944dcb14b99011dfaf9504" - integrity sha512-4Vc0W5EvXAXUN/wWyxvsAKDLLgtJ3oLmhYYssx+YzphJpejtOst6cbIHCIyF50Fdxuf5DDKqRYny24yJ2y7GFQ== - react-google-recaptcha@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/react-google-recaptcha/-/react-google-recaptcha-2.1.0.tgz#9f6f4954ce49c1dedabc2c532347321d892d0a16"