📜 ⬆️ ⬇️

Global site tag (gtag.js) in Google Analytics. What is it and do you need it?

You are reading the translation of Amanda Schroeder’s " What is gtag.js with Google Analytics and Do I Need It? "


If you recently added a Google Analytics tracking code to your site, then you notice a completely different counter code that looks like this:



There was some confusion around this gtag.js code. This article should clarify everything. You will understand if you need gtag.js or not.


What is the Global Site Tag or gtag.js?


In recent years, Google Analytics released several updates to its JavaScript library, each of which added new features and was recommended to use.


However, it is not exactly the same. This is not just another library update. The Global Site Tag is designed to streamline and streamline tracking for all Google products .


The new gtag.js code will completely change the way we collect data. The change is aimed at sites in which several different codes are embedded on the page directly, such as Google Analytics and Google AdWords. Directly means without using a tag manager.


This is a new counter installation style with one goal - to have one centralized tag that sends data to all of Google’s marketing and analytics tools. You no longer need to spend hours setting up tags on your site.


This is not just a new library for Google Analytics. The same analytics.js is loaded on the background, and with it additional codes. The choice of libraries depends on which tools you use, such as conversions.js for Google AdWords.


Previously, we moved from the classical version of the code (ga.js) to Universal Analytics (analytics.js) and compared this with the replacement of a car engine. Six cylinders - the classic version and eight cylinders - Universal Analytics. Switching to gtag.js is completely different. You still use the eight-cylinder engine, but it works differently. We can compare this with the tuning or firmware of an existing engine ...


Together with gtag.js we get a lot of new features. Already decided to switch to new code to take advantage? No need to hurry.


Stand still Why do we then use the Google Tag Manager?


It is important to note that there is no need to use gtag.js if you are already using Google Tag Manager. If you are using GTM, just keep doing it. In fact, we recommend not to embed codes directly, but to use the Google Tag Manager tag manager. But if you are bound by circumstances and cannot do so, then continue reading.


How it works?


For example, take a typical site where the following codes are set:



These are FIVE separate tags for Google products!


The new gtag.js simplifies all this:



For example, if you use Google Analytics and Google AdWords, your gtag.js fragment will look like this:


<script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-1234567-8′); gtag('config', 'AW-1234567-8′); </script> 

The gtag.js code will be placed on every page of your site. config is a command that pulls the appropriate library for a selected product, such as analytics.js for Google Analytics or conversion.js for Google AdWords.


The config command will take care of some of the initial settings, send a page view to Google Analytics, or remarketing a hit to AdWords. You can and cancel these actions by default. Edit the config line like this:


gtag('config', 'UA-66848305-11′, { 'send_page_view': false });


Pay attention to this when you decide to add AdWords conversion tracking to your site. AdWords now also offers gtag-style installation.


The way that you set up event tracking, e-commerce, and cross-domain tracking for Google Analytics, as well as conversions for AdWords, will change. All this can be found in the gtag.js documentation for Google Analytics and Google AdWords .


Do I need gtag.js?


So should I update? We suggest using the following scheme to see if you should use gtag.js.



Remember: if you are currently using analytics.js, there is no need to rush to migrate to gtag.js. The amount of work required for this depends on how the codes are organized on your site.


There is nothing wrong with continuing to use the usual analytics.js. Refer to the analytics.js documentation .


')

Source: https://habr.com/ru/post/353572/


All Articles