-
Notifications
You must be signed in to change notification settings - Fork 929
FR: Disable automatic page views in analytics #3988
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
Comments
The value of the dataLayer variable only changes if the user specifies a custom dataLayer name using I am not 100% sure if calling a config on this measurement ID before Firebase does it will interfere with Firebase's ability to associate gtag events with your Firebase project. I don't think it should, but double check you're still getting events in the Firebase dashboard as you expect. If you don't want any page_view events fired on this page, it might be safer to use |
Thanks @hsubox76, based on your response my workaround is simplified to this snippet placed above the calls to firebase initializeApp() and analytics():
This seems to work as expected, no page views are sent. |
Will this issue be resolved in the future? |
I think it might be a good idea to allow users to set custom config options on init, perhaps using the |
The further problem I encounter, if I use the 'gtag' method on my APP, it's will be a potential security problem under high-standard security requirements. I think to use firebase method of sdk is the way to resolve fundamentally. |
I'm working on a method to allow setting gtag config settings such as But can I ask why using gtag is a security problem? Firebase Analytics is just wrapping gtag under the hood so if you're using Firebase Analytics you're already using it. |
Some additional observations: In addition to logging page views when the gtag is first initialized, a standard GA4 setup will log page view events from history state changes (it's one of the default "enhanced measurements"). So, for many SPAs, the initial But when using the Firebase library, history changes don't trigger page view events. Is this because the history change event is disabled for Firebase projects? Viewing and editing data stream settings from the GA console is disabled if it's connected to Firebase. It would be very helpful if this was documented. We can't use the built-in history change trigger, nor disable the first page view event. |
Yes,your opinion is right. But under may company security policy, it become a contradiction problem. You can skip it. |
We've added the ability to set a config on initialization of analytics in v9 as part of the settings object, see https://firebase.google.com/docs/reference/js/analytics.md#initializeanalytics |
[REQUIRED] Describe your environment
[REQUIRED] Describe the problem
I would like to be able to disable the default Google Analytics page_view measurement when using the firebase JS SDK. This can be done when using GA on its own (https://developers.google.com/analytics/devguides/collection/ga4/disable-page-view).
However when calling firebase.analytics(), which (among other things) causes the page view event to be fired, there is no option to prevent the default page_view measurement.
Steps to reproduce:
Create a firebase project and a web app within. Follow the instructions to install the firebase web app config on a simple web site (a local web server with a single html page is all you need). This will include adding a couple script tags to your page, including one that looks something like this:
Relevant Code:
That last call to
firebase.analytics()
involves a call to initializeIds which (I think) causes a page_view event to be logged.If there was an option to have
send_page_view:false
be added to the config options in there, it would be nice.In the meantime, here is the workaround I am attempting. I am placing the following ABOVE the firebase initialization scripts:
This script is based on the snippet GA gives you to when you create a Web Stream (Web Stream Details > Tagging Instructions > Add new on-page tag > Global site tag) combined with instructions to use Firebase with existing gtag.js tagging (https://firebase.google.com/docs/analytics/get-started?platform=web#firebase-gtag).
It seems to prevent the default page_view as I desire.
I am not sure how sustainable this is though, since the "dataLayer" variable is inside the firebase library. It could change at some point maybe?
The text was updated successfully, but these errors were encountered: