From what I can tell, how google recommends to set up gtag, it's a function that is always pushing more variables onto an array:
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
Following the docs on how to use it in a SPA, it seems I'm actually creating a memory leak.
gtag('config', 'GA_TRACKING_ID', {'page_path': '/new-page.html'});
console.log('window.dataLayer', window.dataLayer);
My console shows that every time I navigate to a new page the window.dataLayer array gets larger.
I'm assuming there's something I'm not understanding, because I doubt that Google wants me to create a memory leak in my app, but I'm stumped now.
Google Analytics and Google Tag Manager (GTM), though designed with traditional round-trip-based websites and web applications in mind, can be configured to work properly with single-page applications (or SPAs). Common technical issues encountered when tracking SPAs with these tools are: Only the first page is tracked.
You can track SPA's using the history change trigger in GTM. If the developer of the SPA page has implemented the browser history functionality, then you link this to GTM history, change the trigger and track the activity of the users on a single page application.
The Google tag (gtag. js) is a single tag you can add to your website to use a variety of Google products and services. Instead of managing multiple tags for different Google product accounts, you can use the Google tag across your entire website and connect the tag to multiple destinations.
To do this, go to Variables → Configure and activate all checkboxes under History. Once enabled, you will see those history variables in the Variables tab in the GTM preview pane. It depends on the architecture of your web SPA whether or not these history variables are useful for tracking.
The size of the dataLayer is capped at 300 (FIFO style) currently.
That's not currently documented and likely to change in the future. But the limit is there exactly to avoid blowing up memory in case repeated events happen inside the same page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With