0

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 tried ReactGA.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"});
    }, []);
}

1 Answer 1

0

Even if you put it in dataLayer.push, it is not sent in events if the library is not configured correctly because react-ga4 does not automatically send debug_mode: true.

Also, ReactGA.send(...) is not supported in GA4, it was used in Universal Analytics. You should use ReactGA.event(...) or ReactGA.gtag(...) for custom events.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.