I'm currently tracking events in GA4 successfully like so:
Loading script:
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id={{ url_escape(google_tag_manager_id) }}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { window.dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', {{ json_encode(google_tag_manager_id) }});
</script>
Firing call:
gtag('event', event, payload);
The marketing team also wants to support the old Universal Analytics. From my looking around it seems the way to load the script for that is:
<script type="text/plain" data-cookie-setter>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
(function(w,d) {
var gaId = 'DEMO';
var accountType = 'user';
w.ga('create', gaId, 'auto');
w.ga('set', 'dimension2', accountType);
w.ga('send', 'pageview');
})(window,document);
</script>
And firing events like this:
ga('send', 'event', [eventCategory], [eventAction], [eventLabel], [eventValue], [fieldsObject]);
My questions are: