The Global Site Tag or gtag.js was recently introduced as the recommended script format for installing Google Analytics (GA). But I have found that you can also use it to install Google Tag Manager (GTM).
http://jesscarranza.blogspot.com/2017/11/use-gtagjs-to-install-google-tag-manager.html
Can any JavaScript expert validate that the two scripts below are functionally identical?
GTM using gtag.js
<script async src="https://www.googletagmanager.com/gtag/js?id=GTM-XXXX"></script>
<script>window.dataLayer=window.dataLayer||[];
function gtag(){dataLayer.push(arguments);}
gtag('js',new Date());</script>
GTM official code:
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXX');</script>