I'm implementing Analytics in a new project and it seems to have changed.
Now they have this Data Stream properties, where you collect a bunch of data automatically.
https://support.google.com/analytics/answer/9303323?hl=en
https://www.optimizesmart.com/introduction-to-google-analytics-apps-and-web-property/
My project is a Single Page App. The way I used to handle it with an Universal Tag was:
Every time my App renders a new page, I would call gtag("config")
to se
nd a new page view.
index.html
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
</script>
On every page change, I call this function:
export function sendPageView(pagePath,pageTitle) {
gtag("config", "UA_TAG", {
page_path: pagePath,
page_title: pageTitle
});
}
If I don't do this, my app would only send the 1st page view, but not subsequent page views, given that fact that my page is not re-loaded, because it's a single page app.
But now, on Google Analytics 4 Data Streams, we get this:
Does it mean that it will send a page view every time the browser history gets a new page? So does it mean I won't need to call gtag
over and over again? Has anyone tested it yet?
If this is true, this is good, but also bad, since you can't control the exact time that the page view event will be sent. So if you a page that gathers async
data before fully loading, the event will most likely not contain the correct page title, for example.
Has anybody implemented Google Analytics 4 data streams for a Single Page App? How does it work?