I'm building a React app (using react-ga4) and trying to track pageviews/events with Google Analytics 4 (GA4). I want to verify events using the GA4 DebugView, but no events or debug devices ever show up, even after trying all the usual troubleshooting steps.
What I've tried:
- Using ReactGA.initialize("G-XXXXXXXXXX") with my correct GA4 Measurement ID.
- Sending pageviews with
ReactGA.send("pageview")and also triedReactGA.pageview(window.location.pathname) - Added window.dataLayer =
window.dataLayer || []; window.dataLayer.push({ 'debug_mode': true });before initializing GA. - Running the app on localhost:3000 (which should automatically enable debug mode).
- Disabled all ad blockers and privacy extensions, tried incognito and multiple browsers.
- Checked the Network tab: I see gtag/js loading, but never see g/collect requests.
- Tried sending manual events in the
console:
window.gtag('event', 'test_event', { debug_mode: true });Still nothing in DebugView. - Double-checked my Measurement ID matches the GA4 property.
- Waited several minutes and refreshed DebugView. No errors in the browser console.
ReactGA.initialize("G-XXXXXXXXXX");
const App = () => {
useEffect(() => {
ReactGA.send({ hitType: "pageview", page: "/index", title: "Home" });
ReactGA.event({category: "your category", action: "your action"});
}, []);
}