Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to disable the automatic pageview measurement ( send_page_view: false) in multi-page apps. #27

Open
EmaAlina opened this issue Apr 7, 2023 · 4 comments

Comments

@EmaAlina
Copy link

EmaAlina commented Apr 7, 2023

Hello,
On multi page apps we want to have only the custom/manually page_view events and to switch off the automatic page_view measurement.
The ReactGA is initialized when the root component of the app is rendered and the custom/manually page_view events are sent on each route change.

According to the following sample we must reset and reinitialize the config on each route change which is time consuming.
#12 (comment)

We've added the following source code(not ideal) on each route change but the automatic page_view measurement is still triggered.

ReactGA.reset(); // reset the `isInitialized` flag
ReactGA.initialize("your GA measurement id", {
  gtagOptions: {
    send_page_view: false
  }
});
ReactGA.send({ hitType: 'pageview', page: window.location.pathname });

Is there a way to set the 'send_page_view` flag to false, from source code, without reinitializing the RectGA ?

fyi:
Browser-history events is disabled in GA4.
image

@EmaAlina EmaAlina changed the title How to disable the automtaic pageview measurement ( send_page_view: false) in GA4 How to disable the automatic pageview measurement ( send_page_view: false) in multi-page apps. Apr 7, 2023
@ciampo
Copy link

ciampo commented Apr 24, 2023

Had the same issue, and I was also setting send_page_view: false under the gtagOptions object.

Fixed it by disabling enhanced measurements in the GA admin dashboard, like suggested in https://developers.google.com/analytics/devguides/collection/ga4/views?client_type=gtag#disable_pageview_measurement

@trevv16
Copy link

trevv16 commented May 11, 2023

My understanding of the problem is that in GA4 page view events happen automatically so defining a ReactGA.pageview in the code would make it count twice.

Is there a reason yall are opting to disable enhanced measurements/send send_page_view: false as opposed to just removing the ReactGA.pageview calls?

I also see it mentioned in the README here: https://github.com/codler/react-ga4#migrate-from-old-react-ga

I am trying to learn if there is something I have not accounted for in my migration. TYIA🚀

cc @ciampo @EmaAlina

@ciampo
Copy link

ciampo commented May 16, 2023

The example in the migration guide does mention "Send pageview with a custom path"

Maybe that should be interpreted as: "page view events are sent automatically without the need for an explicit call in the code. Use the send function only to send custom page views, ie. with custom paths, or from updates that didn't result in a page history alteration"

@sin-to-jin
Copy link

I wrote a new issue here.
#72

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants