diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 7c74556af..6baa6682b 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -17,7 +17,7 @@ "history": "^5.3.0", "react": "^18.2.0", "react-dom": "^18.2.0", - "react-ga": "^3.3.1", + "react-ga4": "^2.1.0", "react-router-dom": "^6.14.2", "styled-components": "^6.0.4" }, @@ -14992,6 +14992,7 @@ "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", + "dev": true, "engines": { "node": ">=0.10.0" } @@ -15863,6 +15864,7 @@ "version": "15.8.1", "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.8.1.tgz", "integrity": "sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg==", + "dev": true, "dependencies": { "loose-envify": "^1.4.0", "object-assign": "^4.1.1", @@ -16254,14 +16256,10 @@ "integrity": "sha512-Fl7FuabXsJnV5Q1qIOQwx/sagGF18kogb4gpfcG4gjLBWO0WDiiz1ko/ExayuxE7InyQkBLkxRFG5oxY6Uu3Kg==", "dev": true }, - "node_modules/react-ga": { - "version": "3.3.1", - "resolved": "https://registry.npmjs.org/react-ga/-/react-ga-3.3.1.tgz", - "integrity": "sha512-4Vc0W5EvXAXUN/wWyxvsAKDLLgtJ3oLmhYYssx+YzphJpejtOst6cbIHCIyF50Fdxuf5DDKqRYny24yJ2y7GFQ==", - "peerDependencies": { - "prop-types": "^15.6.0", - "react": "^15.6.2 || ^16.0 || ^17 || ^18" - } + "node_modules/react-ga4": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/react-ga4/-/react-ga4-2.1.0.tgz", + "integrity": "sha512-ZKS7PGNFqqMd3PJ6+C2Jtz/o1iU9ggiy8Y8nUeksgVuvNISbmrQtJiZNvC/TjDsqD0QlU5Wkgs7i+w9+OjHhhQ==" }, "node_modules/react-inspector": { "version": "6.0.2", @@ -16275,7 +16273,8 @@ "node_modules/react-is": { "version": "16.13.1", "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", - "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==" + "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==", + "dev": true }, "node_modules/react-refresh": { "version": "0.11.0", diff --git a/frontend/package.json b/frontend/package.json index b2ffc4ca0..09d116701 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -24,7 +24,7 @@ "history": "^5.3.0", "react": "^18.2.0", "react-dom": "^18.2.0", - "react-ga": "^3.3.1", + "react-ga4": "^2.1.0", "react-router-dom": "^6.14.2", "styled-components": "^6.0.4" }, diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 0dc9985f2..574d45e3a 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -1,4 +1,4 @@ -import React, { Suspense } from 'react'; +import React, { Suspense, useEffect } from 'react'; import { styled } from 'styled-components'; import { Outlet } from 'react-router-dom'; import ToastProvider from './contexts/ToastContext'; @@ -8,22 +8,24 @@ import LoadingPage from './pages/LoadingPage'; import ModalProvider from './contexts/ModalContext'; import { QueryClientProvider, QueryErrorResetBoundary } from '@tanstack/react-query'; import { queryClient } from './hooks/query/queryClient'; -import ReactGA from 'react-ga'; import { createBrowserHistory } from 'history'; import ErrorBoundary from './components/ErrorBoundary/ErrorBoundary'; +import ReactGA from 'react-ga4'; -const gaTrackingId = process.env.REACT_APP_GA_TRACKING_ID; -if (gaTrackingId) { - ReactGA.initialize(gaTrackingId); -} +const App = () => { + useEffect(() => { + const gaTrackingId = process.env.REACT_APP_GA_TRACKING_ID; + if (gaTrackingId) { + ReactGA.initialize(gaTrackingId); + } -const history = createBrowserHistory(); -history.listen((response: { location: { pathname: string } }) => { - ReactGA.set({ page: response.location.pathname }); - ReactGA.pageview(response.location.pathname); -}); + const history = createBrowserHistory(); + history.listen((response) => { + ReactGA.set({ page: response.location.pathname }); + ReactGA.send(response.location.pathname); + }); + }, []); -const App = () => { ChannelService.loadScript(); if (CHANNEL_SERVICE_KEY) {