Search code examples
reactjsgoogle-analytics

Enable DebugView in google analytics with react-ga4


Edit: Restarting react fixed the issue, the following code works as expected.

I am trying to enable the DebugView mode in Google analytics but events are not being shown or are logging in any way. I am using react-ga4: https://www.npmjs.com/package/react-ga4 and it says here you can enable debug by passing in the config: https://support.google.com/analytics/answer/7201382?hl=en#zippy=%2Cglobal-site-tag-websites

I believe the following code should enable the DebugView mode in the google analytics:

ReactGA.initialize([
  {
    trackingId: "G-TRACKINGID",
    gaOptions: {
      debug_mode: true,
    },
    gtagOptions: {
      debug_mode: true,
    },
  },
]);

Then to trigger event I have the following code in an onClick handler:

ReactGA.event({
  action: "action_button",
  category: "category_button",
  label: "label_button",
  value: 44,
});

Solution

  • This worked for me :

    ReactGA.initialize("G-TRACKINGID", {
        gaOptions: {
          debug_mode: true,
        },
        gtagOptions: {
          debug_mode: true,
        },
      });