What is gtag.js and what is it for?

What is gtag.js and what is it for?

Global Site Tag is a library (a set of javascript variables, functions and programs that we can load on our site) designed to use the entire Google suite and third parties. It also simplifies labelling, exchange and analysis between different products.

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 –>
(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),

ga(‘create’, ‘UA-XXXXXXXX-X’, ‘auto’);
ga(‘send’, ‘pageview’);
<!– End Google Analytics –>

Gtag.js code:

<!– 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 [];
 function gtag()-dataLayer.push(arguments)-;
 gtag(‘js’, new Date());

 gtag(‘config’, ‘GA_TRACKING_ID’);

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.

GTag map

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:

gtag(‘config’, ‘UA-12345-6’);
gtag(‘config’, ‘AW-123456789’);

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/

Expert consulted,

Diana Gámiz

Data Collector.



Share on facebook
Share on twitter
Share on linkedin
Share on print
Share on email