如何使用Firebase Analytics从SPA(单页应用)网络应用发送page_view事件? [英] How to send a page_view event from an SPA (single page app) web app using Firebase Analytics?
问题描述
我有一个使用React + Firebase构建的SPA Web应用程序.
我现在正在使用Firebase Analytics,我想记录客户端路由页面的page_view
事件(因为我的应用程序是单页应用程序").
我在Firebase Analytics文档中没有找到任何有关单页应用程序的信息.
https://firebase.google.com/docs/analytics/events
但是我确实在gtag.js
文档中找到了一些东西.
发件人:: https://developers.google.com/analytics/devguides/collection/gtagjs/single-page-applications
来自: https://firebase.google.com/docs/analytics/events #log_events_3
您可以在 gtag.js事件参考.
从事件引用中,我们得到:
从上图中,我们可以看到page_view
事件似乎没有任何与之关联的参数.
问题
我可以看到Firebase Analytics在我的应用程序首次加载后已经发送了第一个page_view
事件.
但是,一旦我的用户单击我的内部链接并更改了其浏览器URL(客户端路由,没有服务器调用),如何为react-router-dom
生成的新URL触发另一个page_view
事件? >
如何使用Firebase Analytics实施此操作?我是否需要在发送事件之前更新页面路径,如gtag.js
文档中所述?我该怎么办?
由于您的应用程序是单页应用程序,因此只有一个page_view
事件.这实际上是正确的行为,因为这意味着您可以使用page_view
事件来跟踪应用程序/页面的加载频率.
当应用程序中显示特定屏幕时,您将要触发screen_view
事件.有关此示例,请参见跟踪屏幕浏览量.
I have an SPA web app that I've built using React + Firebase.
I am now using Firebase Analytics and I would like to log page_view
events for pages that are client-side routes (since I have my app is a Single Page App).
I didn't find anything about Single Page Apps in Firebase Analytics docs.
https://firebase.google.com/docs/analytics/events
But I did find something in the gtag.js
docs.
From: https://developers.google.com/analytics/devguides/collection/gtagjs/single-page-applications
From: https://firebase.google.com/docs/analytics/events#log_events_3
You can find implementation details for several events and their parameters in the gtag.js event reference.
And from that event reference, we get that:
From the image above, we can see that the page_view
event doesn't seem to have any parameter associated with it.
QUESTION
I can see that Firebase Analytics already sends the first page_view
event, after my app is first loaded.
But once my users click on my internal links and change its browser URL (client side routed, no server calls), how can I trigger another page_view
event for the new URL that was generated by react-router-dom
?
How can I implement this using Firebase Analytics? Do I need to update the page path before sending the event like it says on the gtag.js
documentation? How can I do it?
Since your app is a single-page application, there is only a single page_view
event. That is actually the correct behavior, because it means you can use page_view
events to track how often the application/page was loaded.
When a specific screen is shown in your application, you'll want to fire a screen_view
event. For an example of this, see the AngularFire library's documentation on tracking screen views.
这篇关于如何使用Firebase Analytics从SPA(单页应用)网络应用发送page_view事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!