Learn business growth with Google Analytics 4 Forums Google Analytics 4 Integrating Google Tag(gtag) and Google Tag Manager

  • Integrating Google Tag(gtag) and Google Tag Manager

    Posted by Jose on 27 November 2022 at 8:54 pm

    Hey, I have a GA4 system running on gtag on my website, and I want to add GTM as well. So, I was curious if it’s possible to use the same endpoint from GA4 (https://www.googletagmanager.com/gtag/js?id=), with the GTM tag replacing where ‘id’ is, plus GA4 and GTM again with config.

    I dug around the docs and found this code <script async src="https://www.googletagmanager.com/gtag/js?id=TAG_ID"></script>, but there wasn’t anything that specifically explained how to use Google Tag alongside Google Tag Manager. Most of it was about navigating the GTM interface.

    I also found that GTM seems to support googletag, but the endpoint for that is https://www.googletagmanager.com/gtm.js?. Can you help me with this?

    Kelsey replied 1 year, 4 months ago 3 Members · 2 Replies
  • 2 Replies
  • Scarlett

    Member
    3 May 2023 at 1:20 am

    Sure, let’s take a step back and look at what Google Tag Manager (GTM) and Google Analytics 4 (GA4)/gtag.js do.

    At the core, think of GTM as a “container” that can hold numerous tracking codes (including GA4/gtag.js). So, you put all your tracking code inside GTM, and then you only need to install GTM on your website once. That’s why it’s popular – you can manage multiple tags from one location.

    On the other hand, gtag.js is the JavaScript library that communicates directly with Google Analytics. It fires off the data you want to track to GA. You can run it independently, without GTM.

    Ideally, you should only use GTM. Put your GA4 tracking inside GTM, along with any other tracking codes you want. GTM smartly manages all the codes, tracks the data you want, and sends it to your Google Analytics in the most efficient way.

    But technically, you couldload both GTM and gtag.js separately on your site. While they won’t cause any syntax issues, it’s possible they could create some logical tracking conflicts. For instance, you may end up firing the same event twice – once from gtag.js and once from GTM – which can mess up your analytics. Also, they would use the same cookies.

    So in short, while you technically “can” use gtag.js and GTM together, it’s simpler, cleaner and more efficient to just use GTM and manage your GA4 tracking from there.

  • Kelsey

    Member
    13 June 2023 at 2:57 pm

    Certainly! Essentially, the two systems – Google Analytics 4 (GA4) and Google Tag Manager (GTM) – are somewhat independent and each has its own functionality. The ‘gtag.js’ and the ‘gtm.js’ files are two different libraries and they serve distinctive purposes, with the former being for GA4 and the latter being for GTM. When you use GTM, it essentially replaces the direct implementation of gtag.js for GA4 in your code. This means you no longer need to directly include the GA4 tracking in your code, as this will be managed via GTM. When you configure GTM, you’ll create an account and container, and obtain a specific container ID (represented as ‘GTM-XXXX’). This GMT-XXXX goes into the GTM script instead of the gtag script. Then, within the GTM interface, you can set up GA4 tags with their own tracking IDs, and add different events on your site. By doing this, you can manage all your tracking implementations, including GA4, via the GTM interface, centralizing your tag management and making it more manageable and tidier.

Log in to reply.