react-ga4
react-ga4 copied to clipboard
Is it possible to set "send_page_view" to "false" with this "react-ga4" ?
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
- https://github.com/codler/react-ga4/issues/27
- https://developers.google.com/analytics/devguides/collection/ga4/views?client_type=gtag#disable_pageview_measurement
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,
}
}]);
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
}
}
@EPGDigital-MW Thanks for the advice, I'll give it a shot! I'll post more on this ish if I find anything else.
I tried this approach, but it seems that page_view is still being sent in my environment...
~~+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.
Thanks for the advice!
ReactGA.initialize(TRACKING_ID, {
gaOptions: {
send_page_view: false,
}
});
It still doesn't seem to work...
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.
I see, so you are saying that the GA side of the configuration needs to be changed. I'll have to check it out.
Any updates?
The gaOptions is for the old analytics, as in the readme the reference link leads to nowhere. You could use the gtagOptions now. My example:
ReactGA.gtag("consent", "default", {
ad_storage: "denied",
ad_user_data: "denied",
ad_personalization: "denied",
analytics_storage: "denied",
});
// https://developers.google.com/tag-platform/security/guides/consent?consentmode=advanced#update-consent
if (hasUserConsent()) {
allConsentGranted();
}
const config = [{ trackingId: ga4Id }];
if (gAdsId) {
config.push({ trackingId: gAdsId });
}
ReactGA.initialize(config, {
gtagOptions: {
user_id: userId, // Set user ID globally if available, or undefined
send_page_view: false, // Without sending default pageviews
},
});
ReactGA.set({
send_to: ga4Id, // Only send most events to GA4 unless locally specified otherwise
});
// Default pageview for every page
ReactGA.send({
hitType: "pageview",
page: window.location.pathname,
title: document.title,
});