Fortunitus Check your tracking

What is gtag.js, and when to use Google Tag Manager instead

gtag.js is the code behind the Google tag: two script lines that load Google Analytics 4 or Google Ads on a page. Google Tag Manager is a container that can load the same Google tag plus everything else. Most sites end up with one of the two, and some by mistake with both.

Short answer: gtag.js is Google's JavaScript library for the Google tag. You paste a short snippet with your ID (G- for GA4, AW- for Google Ads) into the <head>, and it sends page views and events to Google. Google Tag Manager (GTM) is a separate tool that loads the Google tag and any other tags from one container you edit in a web interface. Use gtag.js for a simple site with only GA4; use GTM when you also run ads, track events or add tools like Meta Pixel or Clarity.

What is gtag.js?

gtag.js stands for global site tag. Since 2022 Google calls it simply the Google tag: one tag that can send data to GA4, Google Ads and other Google products. The code you get in GA4 under Admin → Data streams → View tag instructions looks like this:

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

Line by line: the first script downloads the library from Google. The second creates the data layer, defines the gtag() function that pushes commands into it, and runs config with your ID, which sends the first page view. Yes, the file comes from googletagmanager.com, which is why people mix the two up. It is still gtag.js, not a GTM container.

What gtag commands do

  • gtag('config', 'G-XXXXXXX') connects the page to a GA4 property or Google Ads account and sends a page view.
  • gtag('event', 'generate_lead', {value: 50, currency: 'EUR'}) sends an event. This is how a form, call or purchase gets to GA4 without GTM.
  • gtag('set', {...}) sets values for all following events, such as a user property.
  • gtag('consent', 'default', {...}) and gtag('consent', 'update', {...}) pass the visitor's cookie choice for Consent Mode.
  • gtag('get', 'G-XXXXXXX', 'client_id', callback) reads a value back, for example to send the client ID to a CRM.

Every extra event means a developer adds a line of code to the site. That is the point where most businesses switch to Tag Manager.

gtag.js vs Google Tag Manager

Comparison of gtag.js and Google Tag Manager: gtag is code in the page, GTM a container; new tags need code changes with gtag and clicks with GTM; GTM handles Meta, TikTok and Clarity in one place and has preview mode and versions.

Google Tag Manager loads gtm.js instead. Inside the container you add a Google tag with your G- ID, so GA4 still runs on gtag.js under the hood; GTM just decides when it fires. The practical difference is who can change tracking: with gtag.js a developer edits the site, with GTM a marketer adds a tag, tests it in Preview mode and publishes a new version that can be rolled back.

Which one should you use?

  • gtag.js is fine for a small site that only needs GA4 page views and the automatic events from enhanced measurement. A WordPress plugin such as Google's Site Kit installs it for you.
  • GTM is better as soon as you have Google Ads conversions, form or phone tracking, Meta Pixel, Clarity or a cookie banner that has to control all of them. Our tracking setups always use GTM for that reason.

What you should not do is run both with the same GA4 ID: a gtag snippet in the theme and a Google tag in GTM. Every page view is then counted twice, sessions look normal but views per session double, and engagement numbers drift. If you move to GTM, remove the old snippet in the same release.

How to check which one a site uses

Our website tracking checker reads the page code and the public GTM container. A site with gtag.js only shows no Tag Manager (1) and GA4 found in the page code (2):

Tracking checker result for vilnius.lt: Google Tag Manager not found, Google Analytics 4 found in page code with ID G-VKL0YRZLFT.
vilnius.lt, November 2026. 1: no GTM container. 2: GA4 loaded directly with gtag.js.

A site with Tag Manager shows the container ID (1) and GA4 found inside the container (2):

Tracking checker result for w3schools.com: Google Tag Manager found in page code GTM-KTCFC3S, Google Analytics 4 found via GTM G-9YNMTB56NB.
w3schools.com. 1: GTM container in the page code. 2: GA4 loaded through GTM.

You can also look at the page source (Ctrl+U) and search for gtag/js?id= and gtm.js?id=. Seeing both with the same G- ID is the double-counting case. Tag Assistant shows the same thing live and also lists which tags actually fired.

Moving from gtag.js to Google Tag Manager

  1. Create a GTM container and add a Google tag with your GA4 ID, firing on Initialization - All Pages.
  2. Recreate each gtag('event', …) call as a GA4 event tag, ideally fed by data layer events instead of code in the theme.
  3. Test everything in Preview mode.
  4. Publish the container and remove the gtag.js snippet at the same time, so there is no gap and no double counting.
  5. Compare page views and key events for a week before and after.

Frequently asked questions

What is gtag.js used for?

gtag.js is the JavaScript library behind the Google tag. It loads on a page and sends page views and events to Google Analytics 4, Google Ads and other Google products using commands such as config and event.

Is gtag.js the same as Google Tag Manager?

No. gtag.js is the Google tag itself, pasted into the page code. Google Tag Manager is a container that can load the Google tag and other tags, and lets you change them in a web interface without editing the site.

Can I use gtag.js and Google Tag Manager together?

Yes, as long as they do not load the same GA4 or Google Ads ID twice. If the theme has a gtag snippet for G-XXXX and GTM also has a Google tag for G-XXXX, page views are counted twice.

Why does gtag.js load from googletagmanager.com?

Google serves the gtag.js library from the googletagmanager.com domain. The URL contains gtag/js?id= for the Google tag and gtm.js?id= for a Tag Manager container, which is how you tell them apart.

Do I need Google Tag Manager for GA4?

No. GA4 works with the gtag.js snippet alone. GTM becomes useful when you add events, Google Ads conversions, Meta Pixel, Clarity or a cookie banner that has to control several tags.

Check your own setup in 20 seconds

Run any website through the free tracking checker: GA4, Google Tag Manager, Google Ads, Meta Pixel, cookie banner and what sits inside the GTM container.