~/TechPurAI
~/tutorials/google-analytics-mastery/installing-tracking-gtag-and-gtm
beginner·part 4 of 22·3 min read

Installing tracking: gtag.js, Google Tag Manager, and how they relate

Updated Aug 21, 2026Google Analytics

Part 2's Measurement ID needs an actual tracking snippet on the site to do anything. This part covers the two real ways to install it — directly with gtag.js, or through Google Tag Manager (GTM) — and why most real sites, including ones already running GTM for other tools, benefit from the second option.

Direct installation with gtag.js

html
<!-- In the <head> of every page on brightleafcoffee.com -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'G-XXXXXXXXXX');
</script>

This is the simplest possible path — paste this snippet, replacing the placeholder with the real Measurement ID from part 2, and GA4 begins tracking page_view and every enhanced measurement event automatically. For a site running only GA4 and nothing else, this direct approach is genuinely reasonable and requires no additional tooling.

The same setup through Google Tag Manager

text
GTM container already installed (the same one this site's own Google
Ads and Meta Ads series cover for GTM-based tag deployment)
  → new tag: Google Analytics: GA4 Configuration
  → Measurement ID: G-XXXXXXXXXX
  → trigger: All Pages

Rather than hardcoding the gtag.js snippet directly into the site's template, GTM lets the GA4 configuration be added and edited entirely through GTM's own interface — no code deployment needed to add, remove, or adjust tracking later.

Why GTM is usually the better real choice

text
A site running: GA4 + Google Ads conversion tracking (Google Ads series,
part 11) + Meta Pixel (Meta Ads series, part 8) + GA4's own tag

Once more than one tracking tag is in play — which is close to universal for any business running both organic measurement and paid advertising, exactly Bright Leaf Coffee and GreenDesk's real situation across this site's other series — managing each one as a separate hardcoded snippet becomes genuinely harder to maintain than managing all of them through one GTM container. GTM becomes the single place every tracking tag lives, with its own version history and testing tools, rather than tracking code scattered directly across a site's templates.

The real relationship between GTM and gtag.js

GTM doesn't replace gtag.js entirely — under the hood, a GTM-deployed GA4 configuration tag still ultimately uses the same gtag.js library to actually send data to Google's servers. GTM is a management and deployment layer sitting on top of it, not a fundamentally different tracking mechanism.

Verifying installation actually worked

text
GA4 → Reports → Realtime

The single fastest, most direct confirmation that tracking is live: open the site in a separate browser tab, then check GA4's Realtime report (covered fully in part 5) for an active user matching that visit. This is worth doing immediately after any installation change, rather than waiting and hoping data appears correctly in a report the next day.

A real installation checklist

text
1. Confirm the correct Measurement ID (matching part 2's property)
2. Confirm the tag fires on every page, not just the homepage
3. Confirm no ad blocker or browser privacy setting is suppressing the
   test visit itself (a real, common false-negative during verification)
4. Check Realtime report for the test visit

Step 3 is a genuinely common source of confusion during verification specifically — testing from a browser with an ad blocker or strict tracking-prevention setting enabled can make correctly-installed tracking appear broken, when the actual issue is the testing environment itself, not the installation.

Common mistake

Installing GA4 tracking directly via gtag.js on a site that also runs GTM for other tags, creating two separate, unmanaged tracking systems instead of one unified one. Consolidating everything into GTM — including GA4 itself — is what keeps tag management from becoming genuinely harder to audit and maintain as more tools get added over time.

Next: the actual reports this tracking feeds — Realtime, Acquisition, Engagement, and Monetization, and what each one is genuinely built to answer.

VK

Vijay Kumar

Founder of TechPurAI — writing hands-on tutorials and honest tool breakdowns.

LinkedIn ↗
← previous3. The GA4 data model: events, parameters, and why everything is an eventnext →5. Key reports: Realtime, Acquisition, Engagement, and Monetization