angulartics / angulartics-google-analytics

Google Analytics plugin for Angulartics
MIT License
133 stars 86 forks source link

Support gtag.js #112

Closed spaceribs closed 6 years ago

spaceribs commented 6 years ago

Semi-recently, gtag.js was released. It would be great if this library supported the new standard: https://developers.google.com/analytics/devguides/collection/gtagjs/migration

DanWilkerson commented 6 years ago

Thanks for the suggestion! As it turns out, all gtag.js does is load analytics.js and pass it commands. It's mean to act as a layer of syntactical sugar to support multiple Google tools, so we're actually kind of cracking the same nut here, as far as I can see.

spaceribs commented 6 years ago

Interesting! so basically the "ga" global is loaded in the page as well as "gtag"? are there any disadvantages to calling "ga" directly?

DanWilkerson commented 6 years ago

Yup, you got it; when gtag loads, it processes the config commands, then fetches whatever libraries it requires (in this case analytics.js) and sets up the command queue for that tool. You can see it all go down in the gtag.js source.

Gtag sets up a named tracker (similar to GTM), so trying to mix gtag and analytics.js will probably not go super great.