Код: Выделить всё
import { useEffect } from 'react';
import { useLocation } from 'react-router-dom';
import { trackPageView } from '../utils/analytics';
const PageViewTracker = ({ children }) => {
const location = useLocation();
useEffect(() => {
trackPageView(location);
}, [location]);
return children;
};
export default PageViewTracker;
Код: Выделить всё
return (
...
)
import ReactGA from 'react-ga4';
// Initialize Google Analytics with your measurement ID
const GA_MEASUREMENT_ID = 'G-ID_IS_HERE';
// Initialize Google Analytics
const initGA = () => {
ReactGA.initialize(GA_MEASUREMENT_ID);
// Send initial pageview
ReactGA.send({ hitType: "pageview", page: window.location.pathname + window.location.search });
};
// Track page views
const trackPageView = (location) => {
ReactGA.send({ hitType: "pageview", page: location.pathname + location.search });
};
export { initGA, trackPageView };
< /code>
Когда я смотрю на сайт, перейду на страницу Now и посмотрю на панель инструментов Google Analytics, я ничего не вижу. Как это исправить?
Подробнее здесь: https://stackoverflow.com/questions/797 ... reactjsvit