codler / react-ga4

React Google Analytics 4
https://www.npmjs.com/package/react-ga4
266 stars 34 forks source link

Is it possible to set "send_page_view" to "false" with this "react-ga4" ? #72

Open sin-to-jin opened 5 months ago

sin-to-jin commented 5 months ago

What

This time, I wrote the following pattern code to avoid sending "page_view", but all "page_view" were sent to GA4, so I made this issue. Is there any solution? If anyone knows of any solutions or workarounds, it would be appreciated.

ReactGA.initialize([
  {
    trackingId: "xxxxxxx",
    gaOptions: { send_page_view: false },
  }
])

Or,

ReactGA.ga('config', "xxxxxxx", { send_page_view: false })

Or,

ReactGA.initialize([
  {
    trackingId: "xxxxxxx",
  }
])
ReactGA.send({ send_page_view: false })

Refference

EPGDigital-MW commented 4 months ago

From my testing this appears to be working, I manually trigger the first page view in my app

ReactGA.initialize([{
    trackingId: TRACKING_ID,
    gaOptions: {
        send_page_view: false,
    }
}]);
EPGDigital-MW commented 4 months ago

Apologies, after more testing that wasn't working!

This appears to be working:

ReactGA.initialize(TRACKING_ID, {
    gaOptions: {
        send_page_view: false,
    }
});

This results in:

{
    0: "config",
    1: "TRACKING_ID",
    2: {
        send_page_view: false
    }
}
sin-to-jin commented 4 months ago

@EPGDigital-MW Thanks for the advice, I'll give it a shot! I'll post more on this ish if I find anything else.

sin-to-jin commented 4 months ago

I tried this approach, but it seems that page_view is still being sent in my environment...

soapraj commented 4 months ago

+1 I am facing the same issue as above. page_view events are sent even when send_page_view is set to false in the initialize call

Edit: This example works for me

ReactGA.initialize(TRACKING_ID, { gaOptions: { send_page_view: false, } });

In my case turning off "Page changes based on browser history events" in the GA4 admin and setting the send_page_view stopped all the page_view events from being collected automatically.

sin-to-jin commented 4 months ago

Thanks for the advice!

ReactGA.initialize(TRACKING_ID, {
    gaOptions: {
        send_page_view: false,
    }
});

It still doesn't seem to work...

EPGDigital-MW commented 3 months ago

In my case turning off "Page changes based on browser history events" in the GA4 admin and setting the send_page_view stopped all the page_view events from being collected automatically.

I've disabled this, then also disabled enhanced measurement as I don't need any other events, everything is triggered within the app manually.

sin-to-jin commented 3 months ago

I see, so you are saying that the GA side of the configuration needs to be changed. I'll have to check it out.