Gtag.js makes processes much easier by keeping tags from different products in one place of code without making additional accounts or modifying settings on any separate interface. It also simplifies installation, accelerating product deployment and also gives us the opportunity to send information to different Tools by Google and third parties. This does so only once, instead of requesting different tagging.
Below we will see that the gtag.js code looks much more compact than the analytics.js code.
Google Analytics default code:
<!– Google Analytics –>
(i[r].q-i[r].q- ).push(arguments)-,i[r].l-1*new Date();a-s.createElement(o),
ga(‘create’, ‘UA-XXXXXXXX-X’, ‘auto’);
<!– End Google Analytics –>
<!– Global Site Tag (gtag.js) – Google Analytics –>
<script async src”https://www.googletagmanager.com/gtag/js?id=GA_TRACKING_ID><” /script>
window.dataLayer ? window.dataLayer ;
gtag(‘js’, new Date());
With regard to migration to gtag.js there are different opinions, since depending on the characteristics of the site in question it could be more complex or easier to carry it out.
While Google assures us that the data will not be affected in case we decide to switch to gtag, it is important to have a migration plan and do an in-depth analysis that allows us to choose the simplest and most effective path for the team.
To configure various tools on the same page, gtag.js makes it easy for us to implement in the same way and, for example, if we wanted to use Analytics and AdWords, it should only be added in the ‘config’ section within the same code:
Another scenario would be the setting of a tag for conversions with different cookies, in that case, the code would look like this:
gtag(‘config’, ‘AW-GOOGLE_CONVERSION_ID_1’, conversion_cookie_prefix: aw_prefix);
gtag(‘config’, ‘AW-GOOGLE_CONVERSION_ID_2’, conversion_cookie_prefix: aw_prefix);
gtag(‘config’, ‘AW-GOOGLE_CONVERSION_ID_3’, conversion_cookie_prefix: aw_prefix);
For more examples and help about implementing gtag.js we can find information at: https://developers.google.com/