philipwalton / analyticsjs-boilerplate

Examples and best practices for using analytics.js
ISC License
1.13k stars 59 forks source link

Tag Manager and Analytics Boilerplate #21

Open SiriusBits opened 6 years ago

SiriusBits commented 6 years ago

Hey Philip - I think this setup is excellent and have implemented various solutions for certain autotrack plugins (page scroll, clean URLs). However, it's not clear if using the boilerplate and GTM are mutually exclusive?

Is implementing with GTM possible/recommended? If so, any tips/gotchas?

Cheers!

amankapoor commented 5 years ago

Same question here.

coliff commented 5 years ago

Phil answered this over on the autotrack repo earlier, reposting his comment here:

gtag doesn't support tasks or plugins, so it's not really possible to do the advanced things autotrack does with it. Unless the gtag library is updated to support these features, I don't think it makes sense to make autotrack work with gtag.

And just to be clear, I think it's worth pointing out that gtag is it's not really an analytics.js replacement; instead, it's a wrapper library on top of analytics.js (and others), meaning the gtag library still needs to load analytics.js, and it still needs to convert all relevant gtag commands to analytics.js commands to run them.

As of right now, gtag is 54.5K and analytics.js is 33.7K, and since gtag will also load analytics.js, it's 262% more code for (in my opinion) less functionality. There's also the problem that gtag is site-specific (because you add your tracking ID as a query string), so it's unlikely your users will have it cached; analytics.js on the other hand is used all over the web, so it's very likely to already be in your visitors cache when they load your site.

For these reasons, I'd strongly recommend autotrack users continue to use analytics.js instead of gtag. The only time I think it makes sense to use gtag is if you're also using other gtag-enabled Google tags, e.g. Adwords.

mattez commented 4 years ago

philipwalton commented on Oct 3, 2017