How to send a page_view event from an SPA (single page app) web app using Firebase Analytics?

人走茶凉 提交于 2020-03-05 02:53:07

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/59932980/how-to-send-a-page-view-event-from-an-spa-single-page-app-web-app-using-fireba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!