javascript - How to disable automatic page_view logging in Firebase analytics - Stack Overflow

I'm using the official Firebase JS SDK in a Vue-based SPA. To get more useful analytics through Fi

I'm using the official Firebase JS SDK in a Vue-based SPA. To get more useful analytics through Firebase's firebase.analytics() Google Analytics integration, I would like to disable automatic reporting of page_view events.

I'm aware that, under the hood, Firebase Analytics uses Google's gtag.js for reporting to Google Analytics and I know that I can configure gtag to not send that event automatically like so:

gtag('config', 'MEASUREMENT_ID', {
  'send_page_view': false
});

My problem is that I can't seem to find a way to set that kind of configuration value through firebase.analytics(). I've tried analytics.setUserProperties({ send_page_view: false }), but that doesn't seem to work as the page_view event is still reported to Google.

Is there any way to set this configuration value in Firebase analytics or is there another way to disable automatic page-view reporting here?

I'm using the official Firebase JS SDK in a Vue-based SPA. To get more useful analytics through Firebase's firebase.analytics() Google Analytics integration, I would like to disable automatic reporting of page_view events.

I'm aware that, under the hood, Firebase Analytics uses Google's gtag.js for reporting to Google Analytics and I know that I can configure gtag to not send that event automatically like so:

gtag('config', 'MEASUREMENT_ID', {
  'send_page_view': false
});

My problem is that I can't seem to find a way to set that kind of configuration value through firebase.analytics(). I've tried analytics.setUserProperties({ send_page_view: false }), but that doesn't seem to work as the page_view event is still reported to Google.

Is there any way to set this configuration value in Firebase analytics or is there another way to disable automatic page-view reporting here?

Share edited Oct 1, 2020 at 14:02 Frank van Puffelen 601k85 gold badges890 silver badges860 bronze badges asked Oct 1, 2020 at 12:35 Skye EwersSkye Ewers 4281 gold badge5 silver badges17 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

I am currently searching for this same solution. I am using firebase analytics in a react spa app. For me, the solution proposed by @Draven does not seem to work.

Using the GA Debug chrome extension, I can see Processing GTAG mand: ["config", "G-3MVDF7WX31", {send_page_view: false}] being called, but shortly after I also see Sending event "page_view" to undefined being called. After that, Processing GTAG mand: ["config", "G-3MVDF7WX31", {send_page_view: false}] is called again. Using the Google Analytics DebugView I can still see the page view event being logged.

UPDATE

Looking through the Firebase JS SDK, there does not seem to be a way to disable the default page_view, which occurs during the call to firebase.analytics(). However I came up with a workaround which, after light testing, seems to work. Place the following BEFORE you call firebase.analytics():

<script>
window.dataLayer = window.dataLayer || [];

function gtag() { dataLayer.push(arguments); }

gtag('set', { 'send_page_view': false });
</script>

See github issue: https://github./firebase/firebase-js-sdk/issues/3988

You can use Firebase with existing gtag.js tagging. Based on this documentation, you'll need to call firebase.analytics() first before sending events using gtag() and the data will be associated to Firebase.

<script async src="https://www.googletagmanager./gtag/js"></script>

...

firebase.analytics();

...

gtag('config', 'MEASUREMENT_ID', {
  'send_page_view': false
});

Firebase Analytics v9+

Support for this has been added to the newer versions of the Firebase JS SDK.

https://github./firebase/firebase-js-sdk/issues/3988#issuement-1029225843

....
import { initializeAnalytics } from 'firebase/analytics';

const initializedAnalytics = initializeAnalytics(firebaseApp, {
  config: {
    send_page_view: false
  }
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744924150a4601324.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信