Google Tag Manager: Installation and Basic Setup Guide

Google Tag Manager (GTM) is a free tool that lets you manage tracking codes without editing your website’s source code. Instead of asking developers to add scripts, you add them through a web interface — and they go live instantly.

Google Tag Manager overview diagram
How Google Tag Manager works

Why Use Google Tag Manager?

  • No coding required — add and update tags through a visual interface
  • Faster deployment — changes go live in minutes, not development cycles
  • Centralized management — all your tracking codes in one place
  • Version control — roll back changes if something breaks
  • Built-in debugging — test tags before publishing

If you only need basic GA4 tracking, you can install it directly. But if you plan to add conversion tracking, remarketing pixels, or custom events, GTM saves significant time.

Key GTM Concepts

GTM tags triggers variables explained
The three building blocks of Google Tag Manager

Before setup, understand these three components:

Tags

Code snippets that execute on your site. Examples:

  • Google Analytics 4
  • Google Ads conversion tracking
  • Facebook Pixel
  • Custom HTML/JavaScript

Triggers

Conditions that determine when tags fire. Examples:

  • All page views
  • Specific page (e.g., /thank-you)
  • Button clicks
  • Form submissions
  • Scroll depth

Variables

Dynamic values used in tags and triggers. Examples:

  • Page URL
  • Click text
  • Form field values
  • Custom JavaScript values

Step 1: Create a GTM Account

  1. Go to tagmanager.google.com
  2. Click Create Account
  3. Enter your Account Name (company name)
  4. Select your Country
  5. Enter a Container Name (website URL)
  6. Select Web as the target platform
  7. Click Create
  8. Accept the Terms of Service

Step 2: Install GTM on Your Website

After creating the container, you’ll see two code snippets:

Snippet 1: Head Code

<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXXXXX');</script>
<!-- End Google Tag Manager -->

Place this: As high as possible in the <head> section.

Snippet 2: Body Code (Fallback)

<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXXX"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->

Place this: Immediately after the opening <body> tag.

Platform-Specific Installation

WordPress

Option 1: Plugin (Recommended)

  1. Install GTM4WP or Insert Headers and Footers
  2. Enter your GTM Container ID (GTM-XXXXXXX)
  3. Save — the plugin handles placement

Option 2: Theme Files

  1. Edit header.php — add head code after <head>
  2. Add body code after <body>

Shopify

  1. Go to Online Store → Themes → Edit Code
  2. Open theme.liquid
  3. Paste head code after <head>
  4. Paste body code after <body>
  5. Save

Squarespace, Wix

These platforms have built-in GTM integration:

  • Squarespace: Settings → Advanced → Code Injection
  • Wix: Settings → Custom Code

Step 3: Add Google Analytics 4 Tag

Now let’s add GA4 through GTM:

  1. In GTM, click Tags → New
  2. Name it “GA4 – Configuration”
  3. Click Tag Configuration
  4. Select Google Analytics: GA4 Configuration
  5. Enter your Measurement ID (G-XXXXXXXXXX)
  6. Click Triggering
  7. Select All Pages
  8. Click Save

Step 4: Preview and Test

GTM preview mode debugging
Testing tags with GTM Preview mode

Before publishing, always test:

  1. Click Preview in the top right
  2. Enter your website URL
  3. Click Connect

Your website opens with the GTM debugger attached. You’ll see:

  • Which tags fired
  • Which triggers activated
  • Variable values
  • Data layer contents

Check that:

  • Your GA4 tag shows “Fired” on page load
  • No errors appear in the summary

Step 5: Publish Your Container

Once testing is complete:

  1. Click Submit in the top right
  2. Add a Version Name (e.g., “Initial GA4 Setup”)
  3. Add a Description of changes
  4. Click Publish

Your tags are now live on your website.

Common GTM Tags to Add

GA4 Event Tracking

Track specific actions (button clicks, form submissions):

  1. Create a new tag: Google Analytics: GA4 Event
  2. Select your Configuration Tag
  3. Enter the Event Name (e.g., “button_click”)
  4. Set trigger (e.g., Click – All Elements with conditions)

Conversion Tracking

Track goal completions:

  1. Create GA4 Event tag
  2. Event name: your conversion name
  3. Trigger: Page View on thank-you/confirmation page

Scroll Depth

Track how far users scroll:

  1. Enable built-in Scroll Depth variable
  2. Create trigger: Scroll Depth at 25%, 50%, 75%, 90%
  3. Create GA4 Event with scroll_depth parameter

GTM Best Practices

  • Use naming conventions — “GA4 – Event – Button Click” not “Tag 1”
  • Always preview before publishing — catch errors before they affect data
  • Add version descriptions — helps when you need to roll back
  • Use folders — organize tags by platform (GA4, Ads, Facebook)
  • Document complex setups — future you will thank present you

Troubleshooting

Tags Not Firing

  • Check trigger conditions are correct
  • Verify GTM code is installed on the page
  • Look for JavaScript errors blocking execution

Preview Mode Not Working

  • Disable ad blockers
  • Try incognito/private browsing
  • Clear browser cache

Duplicate Data in GA4

  • Check if GA4 is installed both directly AND via GTM
  • Remove direct installation if using GTM

Summary

Google Tag Manager simplifies tracking management by letting you add, edit, and remove tags without touching website code. The basic setup takes about 15 minutes:

  1. Create GTM account and container
  2. Install the two code snippets on your site
  3. Add tags (starting with GA4)
  4. Preview and test
  5. Publish

Once GTM is running, adding new tracking — conversion goals, remarketing pixels, or custom events — becomes significantly easier. For sites with multiple tracking needs, GTM is essential.

Aleksey Gromov
Written by

Aleksey Gromov

Web analytics consultant with 10+ years of experience helping businesses make data-driven decisions. Specializing in GA4, Matomo, and privacy-first tracking solutions. Passionate about making analytics accessible to everyone.

Leave a Reply 0

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