Available for plans: L | VIP | Enterprise
What is the difference between gtag.js and analytics.js?
The short answer is: features.
The long answer: The difference between analytics.js and gtag.js follows this logic. Analytics.js has gained an enormous audience since its release in 2013, and has a complete feature-set compared to its predecessor. gtag.js is like analytics.js, but makes it easier to integrate other services.
This tutorial walks you through the process of upgrading an existing gtag.js implementation to use analytics.js.

To migrate from gtag.js to analytics.js, do the following for every web page of your site:
1/ Replace the gtag.js snippet with the analytics.js snippet.
<!-- Global Site Tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=GA_MEASUREMENT_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'GA_MEASUREMENT_ID');
</script>
2/ With the following analytics.js snippet:
<!-- Google Analytics -->
<script>
(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','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'GA_MEASUREMENT_ID', 'auto');
ga('send', 'pageview');
</script>
<!-- End Google Analytics -->

To learn more about this process, we recommend visiting the Google Help Center.
Comments
0 comments
Please sign in to leave a comment.