• Courses
    • Courses
    • Course bundles
  • Blog
  • Services
  • Resources
    • Youtube channel
    • E-books and Guides
    • GTM Recipes
    • View All Resources
    • GTM Community
    • GA4 community
  • About
    • About
    • Contact
  • Login
  • Courses
    • Courses
    • Course bundles
  • Blog
  • Services
  • Resources
    • Youtube channel
    • E-books and Guides
    • GTM Recipes
    • View All Resources
    • GTM Community
    • GA4 community
  • About
    • About
    • Contact
  • Login

October 14, 2022

GTAG vs Google Tag Manager. What is the Difference? What to Choose?

Updated: October 14th, 2022

GTAG and Google Tag Manager are completely different beasts. But after seeing that people are looking for information about this topic, I have decided to write a blog post (and record a video).

In this article, I will compare GTAG vs Google Tag Manager. We will take a look at what they do and what purposes they serve.

 

Table of Contents

+ Show table of contents +

  • What is GTAG?
  • Tracking code
  • What is Google Tag Manager?
  • GTAG vs GTM
    • #1. Google Tag Manager allows you to manage tracking codes
    • #2. GTAG supports only several Google’s products
    • #3. GTAG means working directly with the code
  • When does it make sense to use gtag.js?
    • Strict developers that do not allow tag management
    • An older project that heavily uses gtag.js
  • Additional questions you might have
    • Should you use gtag.js in Google Tag Manager?
    • Using Tag Assistant (legacy) for debugging? Read this
  • Final words

 

Video tutorial

If you prefer video content, take a look at the tutorial from my Youtube channel.

 

What is GTAG?

When you create a new Google Analytics property, you have two options for how to install it on your website:

  • Via gtag.js
  • or via Google Tag Manager (GTM)

I always recommend using the Google Tag Manager option, and later in this blog post, you will learn why.

So what is GTAG?

GTAG (or gtag.js) is a JavaScript code library that a developer can install on a website can install. When this tracking code is added, it starts tracking standard events (like page_view and others).

In fact, gtag.js is used not only by Google Analytics (GA3 and GA4). Other Google products also rely on it, e.g. Google Ads.

 

Tracking code

In the past, Google Analytics and Google Ads were using different tracking codes. Google Analytics was using analytics.js library while Google Ads was using conversion.js.

conversion.js and analytics.js

But due to various changes in the industry, Google decided to choose a more unified approach, a single tracking code that is supported by multiple tools, gtag.js.

If you take a closer look at both codes in the screenshot below, you’ll notice that their structure is very similar.

<script async src="https://www.googletagmanager.com/gtag/js?id=SOME_ID"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){window.dataLayer.push(arguments);}
    gtag('js', new Date());

They both load a script from googletagmanager.com (maybe this causes confusion and forces people to compare GTAG vs GTM).

This code initiates the library.

window.dataLayer = window.dataLayer || [];
function gtag(){window.dataLayer.push(arguments);}
  gtag('js', new Date());

Once this is done, your developers can modify the code and add additional commands. For example:

gtag('config', 'GA_MEASUREMENT_ID');

This will send a page_view to a particular GA4 data stream.

Add this…

gtag('config', 'AW-XXXXXXXXX');

…will add Google Ads tracking (needed for retargeting).

To learn more about the gtag and how to use it, read the official documentation.

 

What is Google Tag Manager?

Now let’s take a look at what Google Tag Manager is (and then we will compare gtag.js vs GTM). By the way, if you want to learn more about Google Tag Manager, take a look at this tutorial too.

Before we do that, let’s take a quick look at the world we used to live in (a.k.a. “without tag management”). Every time you want to install Google Analytics, it prompts you to add its JavaScript code (a.k.a. tag) on your website. Pretty standard, right? Gtag.js is the code that your developers had to add.

Adding that one tag to a site isn’t big of a deal. You just ask a developer, and he/she will do that (sometimes on the same day, sometimes over several days, but still reasonable because this has to be done only once).

What if you want to track actions that Google Analytics isn’t capable of doing automatically (e.g. form submissions, sales, etc.)

That’s where the developer (and the IT department) becomes a bottleneck. Since he/she is working on his tasks/projects, marketing/analytics tasks often are a B priority. Therefore you and your team have to wait. And wait a bit more. And more. Sometimes even for weeks.

That’s where the GTM saves the day.

Google Tag Manager is a tag management solution that is a middleman between a website and marketing/analytics tools. You (or your developer) can install it on a website, and from that moment, you are in charge of the tracking codes (in most cases).

Want to track a particular form and send that data to Google Analytics? No problem. Create a tag (tracking code) in Google Tag Manager and GTM will activate the tag for you.

All you need to do is to add your tracking codes to GTM and then configure rules when they should be activated (on page load, click, form submission, etc.).

Google Tag Manager supports not only Google’s products. It can be used to add other tracking codes, too, like Facebook Pixel, Hotjar, or something else.

If it is not clear how Google Tag Manager works, read/watch this tutorial.

 

GTAG vs Google Tag Manager

Now that we have taken a quick look at GTAG and GTM, let’s compare them.

 

#1. Google Tag Manager allows you to manage tracking codes. Gtag.js is one of those codes.

GTM is a central place where you can keep your tracking codes, and manage them. When a page is loaded, Google Tag Manager will activate those codes based on your conditions (on page load, on purchase, on form submission, etc.).

One of the things that you can install is Google Analytics. And it uses gtag.js.

 

#2. GTAG supports only several Google’s products. GTM supports much more.

Gtag.js is used by tools like Google Analytics or Google Ads. It is a library that (after it is installed on a website) can load tracking codes related to the aforementioned platforms. But what if you want to also install Facebook Pixel, and track conversions with Twitter pixel?

Then you would need to ask a developer to implement those codes too directly in the source code of the website. And every time you need some changes in your tracking setup, you would need to ask a developer to do that. This is time-consuming.

Google Tag Manager, on the other hand, supports way more platforms, not only Google’s tools. Here are just several examples of what you can install with GTM:

  • Google Analytics
  • Facebook Pixel
  • Microsoft Ads conversion tracking
  • Google Ads conversion tracking
  • Hotjar

The list could go on and on.

 

#3. GTAG means working directly with the code. GTM – with user-friendly templates.

If you take a look at the documentation of GTAG, you will notice that all examples/instructions show how to edit the code of the library. This means that:

  • You need to have at least some basic knowledge of coding
  • You need to have access to the website’s code if you plan to do the modifications yourself (or you will need to send the code snippets and instructions to a developer who is going to implement this)

In the meantime, things in Google Tag Manager are much friendlier (at least, in many cases).

Want to install Google Analytics? Log in to your Google Tag Manager account, and go to Tags > New > GA4 Configuration tag.

You will see a form that looks like this.

Enter the information about what kind of information do you want to send (and where), and that’s it. After you test and publish this, GA4 will be activated on a website.

Instead of dealing with a code (and being afraid of messing things up), you just need to configure the tag by filling in the fields of a template.

 

When does it make sense to use gtag.js?

You are probably asking now, “why use gtag.js at all when we have Google Tag Manager?”. Well, in some cases using GTAG might make sense.

 

Strict developers that do not allow tag management

Maybe you are working in a company with a very strict CTO or head of development who does not want to have any tag managers.

After all, GTM is a script injector that is a risk for a company (someone might add malicious code to GTM or a marketer might unintentionally add some untested code that breaks the website). Thus, the strict CTO has a full right to see GTM as a threat.

In such cases, strict companies decide to adopt tracking codes that can be controlled only by developers and not allow marketers to break stuff. That’s when gtag.js looks like an appealing option. It’s better to have at least some sort of tracking setup rather the nothing at all.

However, those strict developers are just not aware of the powerful governance features that Google Tag Manager has to offer, for example:

  • User permissions (marketing can add codes, but only someone else (more experienced) can publish those changes)
  • allowList and blockList (developer can limit what kind of tags can be added to the container, e.g. “only Google Analytics and Google Ads tags are allowed. Custom scripts are forbidden.)

Therefore, in my opinion, GTM is still a better option because developers can feel safe, and marketers can keep some sort of flexibility. But if your company does not even want to hear about tag management, then gtag.js is an option for you.

 

An older project that heavily uses gtag.js

Another example that comes to my mind is an existing project that has A LOT of customized gtag.js code. Even though I would recommend migration from gtag to GTM, your company might not justify this kind of approach.

After all, this can cost a lot of time and resources, hence money. If that is your case, continuing to use GTAG might be the way to go.

 

Additional questions you might have

At this point, you might have some additional questions about GTAG vs Google Tag Manager. Let’s address them here. If you still have questions after reading the entire article, post a comment.

 

Should you use gtag.js in Google Tag Manager?

In Google Tag Manager, there are a couple of ways how you can add tracking codes. One of them is templates (like the one of GA4 that I previously showed), and the other one is a Custom HTML tag.

If you cannot find a readymade template for the tool you want to install, you can add that JavaScript via a Custom HTML tag.

And here is the question. How should you install Google Analytics 4 via Google Tag Manager? By using a GA4 tag template? Or by pasting gtag.js in the Custom HTML tag?

Even though it looks like gtag still can work in the Custom HTML tag, it is highly recommended to use the template instead because:

  • Google keeps the GA4 templates updated
  • It is easier to manage tags for non-developer because you don’t need to mess with the code
  • The probability of error is lower when you work with a template

You can find a template by going to Templates > New.

 

Using Tag Assistant (legacy) for debugging? Read this

If you have Universal Analytics (GA3) installed on a website and that is done with a hardcoded gtag.js snippet, this part of the blog post is for you.

If you use Tag Assistant (legacy) Chrome extension to debug the setup, you will see this:

One row for Google Analytics, one row for Global site tag, and both of them have the same GA tracking ID.

Don’t worry, this is normal. When gtag.js is used to install GA3, it also loads the older version of the Google Analytics JavaScript library, called analytics.js.

Therefore, one row in Tag Assistant represents gtag.js, and the other one analytics.js.

 

GTAG vs Google Tag Manager: Final words

Hopefully, this cleared up some things about the differences between GTAG and GTM.

Personally, I always choose Google Tag Manager because it is more powerful, more flexible, and does not limit me just to several Google products.

So when you want to install Google Analytics, always start thinking about Google Tag Manager.

New to Google Tag Manager? Take a look at this tutorial for beginners.

 

Julius Fedorovicius
In Google Tag Manager Tips
4 COMMENTS
Carlos M. Díaz Honrado
  • Mar 25 2022
  • Reply

If you implement parallel measurement (WA and GA 4) how should gtag's asynchronous script go?
That is, this
<script async="" src="https://www.googletagmanager.com/gtag/js?id=UA-12345678-1"></script>
A) Yes?
<script async="" src="https://www.googletagmanager.com/gtag/js?id=UA-12345678-1&id=G-XXXXXXXXXX"></script>

    Julius Fedorovicius
    • Mar 25 2022
    • Reply

    That will be explained in my GA4 course https://www.analyticsmania.com/courses/google-analytics-4-course/

      Carlos M. Díaz Honrado
      • Mar 25 2022
      • Reply

      OK, i will see
      Thkx

Kaylin
  • Aug 22 2022
  • Reply

Hello Julius.

We're currently going through the initial steps to migrate from UA GA to GA4 at my company. We have historically used gtag.js, partnering with our engineering team, to implement any event tracking to send to GA. We have hundreds of custom events and quite a few custom dimensions we have set up over time through this method.

I have installed GA4 tracking code to our site with GTM. Where I'm struggling now is trying to figure out whether we should have our engineering team migrate all of our old UA GA events to GA4 events via gtag, but with the new version you have to use with GA4 since you can't just easily migrate events like you can goals in the GA console. Or if we should go the route of setting up all of these UA GA events in GTM.

The problem I see with the approach of setting everything up in GTM is if we use event definition fields that rely on things in the code of that particular element (for example, a link click that relies on the element class), then if our developers go and update the code at any point and we are not aware of that element changing it could break our event tracking. This has happened to us many times when we have used the tool Heap to try to set up our own event tracking for product analytics and maintain that data over time. The definitions will often times break because of code changes.

Have you got any advice about the best way to go in this kind of scenario? Also do you have any resources to recommend to understand how to migrate UA GA events from the gtag.js setup to using the same method on GA4 rather than using GTM?

Leave a comment Cancel reply

Your email address will not be published. Required fields are marked *

 

Hi, I'm Julius Fedorovicius and I'm here to help you learn Google Tag Manager and Google Analytics. Join thousands of other digital marketers and digital analysts in this exciting journey. Read more
Analytics Mania
  • Google Tag Manager Courses
  • Google Tag Manager Recipes
  • Google Tag Manager Resources
  • Google Tag Manager Community
  • Login to courses
Follow Analytics Mania
  • Subscribe to newsletter
Recent Posts
  • Track Videos with Google Analytics 4 and Google Tag Manager
  • Debugging Incorrect & Missing Google Analytics 4 Transactions
  • A Guide to Referrer in Google Tag Manager
Analytics Mania - Google Tag Manager and Google Analytics Blog | Privacy Policy
Manage Cookie Settings