简体   繁体   English

如何在 Firebase 分析中禁用自动 page_view 日志记录

[英]How to disable automatic page_view logging in Firebase analytics

I'm using the official Firebase JS SDK in a Vue-based SPA.我在基于 Vue 的 SPA 中使用官方Firebase JS SDK To get more useful analytics through Firebase's firebase.analytics() Google Analytics integration, I would like to disable automatic reporting of page_view events.为了通过 Firebase 的firebase.analytics() Google Analytics 集成获得更有用的分析,我想禁用page_view事件的自动报告。

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:我知道,在幕后,Firebase Analytics 使用 Google 的 gtag.js 向 Google Analytics 报告,我知道我可以将 gtag 配置为不自动发送该事件,如下所示:

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() .我的问题是我似乎找不到通过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.我试过analytics.setUserProperties({ send_page_view: false }) ,但这似乎不起作用,因为 page_view 事件仍然报告给谷歌。

Is there any way to set this configuration value in Firebase analytics or is there another way to disable automatic page-view reporting here?有没有办法在 Firebase 分析中设置这个配置值,或者有没有其他方法可以在这里禁用自动页面浏览报告?

I am currently searching for this same solution.我目前正在寻找同样的解决方案。 I am using firebase analytics in a react spa app.我在 react spa 应用程序中使用 firebase 分析。 For me, the solution proposed by @Draven does not seem to work.对我来说,@Draven 提出的解决方案似乎不起作用。

Using the GA Debug chrome extension, I can see Processing GTAG command: ["config", "G-3MVDF7WX31", {send_page_view: false}] being called, but shortly after I also see Sending event "page_view" to undefined being called.使用 GA Debug chrome 扩展,我可以看到Processing GTAG command: ["config", "G-3MVDF7WX31", {send_page_view: false}]被调用,但不久之后我也看到Sending event "page_view" to undefined被调用。 After that, Processing GTAG command: ["config", "G-3MVDF7WX31", {send_page_view: false}] is called again.之后, Processing GTAG command: ["config", "G-3MVDF7WX31", {send_page_view: false}]再次被调用。 Using the Google Analytics DebugView I can still see the page view event being logged.使用Google Analytics DebugView我仍然可以看到正在记录的页面查看事件。

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() .查看 Firebase JS SDK,似乎没有办法禁用在调用 firebase.analytics firebase.analytics()期间发生的默认 page_view。 However I came up with a workaround which, after light testing, seems to work.但是,我想出了一个解决方法,经过轻度测试,它似乎有效。 Place the following BEFORE you call firebase.analytics() :在调用firebase.analytics()之前放置以下内容:

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

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

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

See github issue: https://github.com/firebase/firebase-js-sdk/issues/3988见github问题: https : //github.com/firebase/firebase-js-sdk/issues/3988

You can use Firebase with existing gtag.js tagging.您可以将 Firebase 与现有的 gtag.js 标记结合使用。 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.根据此文档,您需要先调用 firebase.analytics(),然后再使用 gtag() 发送事件,数据将关联到 Firebase。

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

...

firebase.analytics();

...

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 是否可以将数据附加到 Firebase Analytics page_view 事件? - Is it possible to append data to the Firebase Analytics page_view event? 如何使用 Firebase Analytics 从 SPA(单页应用)网络应用发送 page_view 事件? - How to send a page_view event from an SPA (single page app) web app using Firebase Analytics? 在 Google 跟踪代码管理器和 Google Analytics 4 (GA4) 中手动触发 page_view 的规范方法是什么? - What is the canonical way to manually fire page_view in Google Tag Manager and Google Analytics 4 (GA4)? 如何在网络单页应用程序中使用 Firebase Analytics 跟踪页面浏览量? - How to track page view with Firebase Analytics in a web, single page app? 是否可以在单击按钮时发送 gtag('event', 'page_view') - Is it ok to send gtag('event', 'page_view') on button click 如何在analytics.js中设置Google Analytics的页面速度记录 - How to set up page speed logging for google analytics in analytics.js 如何禁用默认的Google Analytics(分析)虚拟页面记录 - How to disable default Google analytics virtual page record 如何在我的页面上永久禁用 Google Analytics 跟踪? - How do I permanentely disable Google Analytics Tracking on my page? Web 的 Firebase 分析调试视图 - Firebase Analytics Debug View for the Web 如何在Google Analytics(分析)中跟踪网站搜索,而不将其计为网页浏览量? - How to track site search in Google Analytics and not count as a page view?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM