Description
When adding a new site to Google Analytics the tracking code provided is now gtag.js which works a bit differently to the previously recommended analytics.js.
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXX-X"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-XXXXXX-X');
</script>
Google Universal Analytics (Analytics.js) is still available to users but I think we need to clarify in the documentation that the useful tracking snippets we currently have in H5BP (Anonymize IP addresses, Track jQuery AJAX requests, Track JavaScript errors and Track page scroll) are for analytics.js and not gtag.js.
Today I'm working on migrating a site from analytics.js to gtag.js (following this guide: https://developers.google.com/analytics/devguides/collection/gtagjs/migration) so will see if the snippets we have can be updated to work with gtag.js.
If anyone has any additional thoughts on this, please chime in.