<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Outfit:wght@600;700;800&family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap">
πŸ“£ Marketing guide

Google Tag Manager Setup Guide: Tags, Triggers, Data Layer and GA4

Set up Google Tag Manager properly: containers, tags, triggers, variables, the data layer, GA4, preview mode, publishing and access control.

πŸ“… Published 2026-11-15⏱️ 5 min readπŸ› οΈ 4 free tools

Google Tag Manager (GTM) lets you add and change tracking code on a website without editing the site itself. You install one container snippet, and from then on analytics tags, ad conversion pixels and other scripts are configured in the GTM interface and published when you are ready. That speed is the point, and also the risk: a container can run any JavaScript on every page of your site.

This guide covers the building blocks, how to pass data from your site through the data layer, setting up GA4 with the Google tag, testing in preview mode, publishing with versions you can roll back, consent mode, and how to keep a container tidy and safe as more people work in it.

Containers, tags, triggers and variables

A GTM account usually maps to a company, and each account holds one or more containers. A web container (ID GTM-XXXXXXX) is installed on a site with two snippets: a script as high as possible in the head and a noscript iframe immediately after the opening body tag. Use one container per site, or one container shared across sites that are measured together.

Inside the container, everything is built from three parts:

  • Tags: the code that runs, such as the Google tag for GA4, a GA4 event, a Google Ads conversion, or a third-party pixel.
  • Triggers: the conditions that fire a tag, such as all page views, a click on a specific button, a form submission, or a custom event pushed to the data layer.
  • Variables: values read at runtime, such as the page path, the clicked element’s text, or a value from the data layer. Built-in variables cover common needs; enable them under Variables before using them.

Use the data layer instead of scraping the page

GTM can read values from the page with CSS selectors and DOM variables, but those break as soon as a designer renames a class. The reliable approach is the data layer: a JavaScript array your site pushes structured events and values into, which GTM reads. Your developers own what goes into it; marketers decide what to do with it in GTM.

Define the data layer before the container snippet if you need values on page load, and push events at the moment something happens. Agree on event names and parameter names in a short shared document, using the GA4 recommended event names (such as purchase, sign_up, generate_lead) where they fit.

<script>
  window.dataLayer = window.dataLayer || [];
  // On page load, before the GTM snippet
  dataLayer.push({ page_type: 'product', user_logged_in: true });
</script>
<!-- GTM head snippet goes here -->

<script>
  // Later, when a form is submitted successfully
  dataLayer.push({
    event: 'generate_lead',
    form_id: 'contact_footer',
    lead_type: 'demo_request'
  });
</script>

Setting up GA4 through the Google tag

In GTM, GA4 uses two tag types. The Google tag (which replaced the old GA4 Configuration tag in 2023) takes your measurement ID (G-XXXXXXXXXX), loads GA4 and sends page views; fire it on the Initialization - All Pages trigger. Then add a Google Analytics: GA4 Event tag for each event you want, with a Custom Event trigger matching the event name from the data layer and event parameters mapped from data layer variables.

If GA4 is set up inside GTM, remove any hard-coded gtag.js snippet for the same measurement ID from the site, or every page view is recorded twice. On single-page apps, check whether GA4 enhanced measurement already records history changes as page views before adding your own virtual page view tags. Register custom event parameters as custom dimensions in GA4 if you want to report on them.

Preview, publish and roll back

Nothing you change in GTM affects the live site until you publish. Use Preview mode, which opens Tag Assistant connected to your site, to load pages and perform actions while it shows which tags fired, which did not, and the values of every variable at each event. Test every new tag there, including the case where it should not fire.

Each publish creates a numbered container version. Name it and describe what changed ("Add generate_lead event for footer form"); those notes are your change log. If a release breaks something, open Versions, choose the previous good version and publish it again. Workspaces let several people prepare changes in parallel without publishing each other’s unfinished work.

A setup checklist with Neemtools

Generate the head and body snippets with the Neemtools GTM Install Code Generator by entering your container ID, then paste them into your site template. After deploying, use the same tool’s checker on the live URL to confirm both snippets and the data layer are present, that the container ID is the one you expect, and whether any gtag.js IDs are also loaded directly, which is the usual cause of double-counted page views.

Then build the GA4 tags in GTM, test them in Preview mode, and publish a named version. For campaign traffic arriving at the site, build consistently tagged links with the UTM URL Builder so the data GTM sends to GA4 is attributed to the right source and medium. Finally, check the GA4 real-time report and DebugView to confirm events arrive with the parameters you expect.

More guides you might like

Ready to try it?

Open the free GTM Install Code Generator and apply what you just read. No sign-up, nothing uploaded.

Open GTM Install Code Generator β†’

← All guides