The three building blocks
| Block | The question it answers | Where its input comes from | Examples |
|---|---|---|---|
| Tag | What should run, and where should the data go? | Its template or script, with fields filled from variables | GA4 event tag, Google Ads conversion tag, custom HTML for a vendor pixel |
| Trigger | When should it run, and when must it not? | The event the container is processing, filtered by conditions on variables | Page view on all pages; custom event generate_lead; a click on a link matching a pattern |
| Variable | What value goes in this field or this condition? | Built-in page and click data, the data layer, cookies, the DOM, lookup tables, your own JavaScript | Page path, click URL, the form's ID, a data layer value such as transaction_id |
The container processes the page as a sequence of events. Some are built in and fire on every page in a fixed order: the container script loading, the document becoming ready, the window finishing loading. Others come from the site through the data layerA structured object on a web page that passes values to a tag manager for tags to use., which the data layer guide covers, or from the container listening to the page for clicks, form submissions, scrolling and visibility. For every event, every trigger is evaluated. A tag fires when at least one of its firing triggers matches and none of its exception triggers does. As it fires, the fields in its configuration are filled by resolving the variables they reference, at that instant, so a variable's value is whatever the page and the data layer hold when the trigger matched. Variables are referenced by name inside double curly braces in any tag or trigger field, which is what lets one tag serve many events: its fields describe how to find a value, not the value itself.
Variables: built-in, data layer, lookup, custom JavaScript
Built-in variables are provided by the container and switched on individually in the variables pane. They cover the page (URL, hostname, path, referrer), the current event's name, the element that was clicked or the form that was submitted (its classes, ID, URL, text), the history change, and container metadata such as the container ID, whether preview mode is running and which environment is active. Enable only the ones a trigger or tag uses; a long list of enabled built-ins is noise for the next person.
User-defined variables are the ones you create, and they come in types. The most important is the data layer variable: it names a key, reads it from the container's data layer model, and can reach nested values with a dot-separated path. It has a default value for when the key is absent and two reading modes, of which the newer, default one merges nested objects across pushes so that page-level context pushed early is still readable later. A constant holds one fixed string, which is where a measurement ID belongs so it is defined once. A lookup table takes an input variable and returns an output for each matching value, with a default; a regex table does the same with pattern matching. URL variables return one component of the current address. First-party cookie and JavaScript variables read a named cookie or a global on the page. DOM element and element visibility variables read the page itself. Finally, a custom JavaScript variable is a function you write that returns a value, which can do anything and is therefore the last resort rather than the first.
A custom JavaScript variable that normalises the page path, trimming a trailing slash so that two spellings of one URL report as one, looks like this:
function () {
var path = document.location.pathname;
return path.replace(/\/$/, "") || "/";
}
The preference order is simple. Read from the data layer when the site can provide the value, because that is a contract the site keeps. Use built-ins for what the browser already knows. Reach for a lookup table before you write code. Write custom JavaScript only for what nothing else can do, and expect a reviewer to read it. Values scraped from the DOM break whenever a designer renames a class, which is precisely why the data layer exists.
Triggers: types, conditions, exceptions
Trigger types are grouped by what they listen for.
| Family | Types | Fire on | Typical use |
|---|---|---|---|
| Page view | Consent initialisation, initialisation, page view, DOM ready, window loaded | The built-in events during page load, in that order | Consent defaults first; the Google tag at initialisation; tags that need the DOM at DOM ready |
| Click | All elements, just links | A click anywhere, or on a link | Outbound links, buttons that do not push to the data layer, downloads |
| User engagement | Element visibility, form submission, scroll depth, YouTube video | The container's own listeners on the page | Promotional banner seen; a form sent; a long article read; video engagement |
| Other | Custom event, history change, JavaScript error, timer, trigger group | Data layer events, URL changes without a reload, errors, elapsed time, a set of triggers all having fired | Every event the site pushes; single-page app views; combining conditions across events |
Two of these do most of the work in a well-built container. The custom event trigger matches the event key
of a data layer push and is how every planned event reaches its tag; with pattern matching enabled, one
trigger can cover a list of event names. The page view family controls what happens during load, and the
order within it matters: consent initialisation fires before anything else, which is where a consent
platform sets its defaults, and initialisation fires next, which is where Google recommends placing the
Google tag so it runs before any event tag.
Conditions narrow a trigger. A trigger can fire on all events of its type or only when conditions on variables hold: page path matching a pattern, click URL containing a string, a data layer value equal to something. The form submission and click triggers also offer a wait-for-tags option that delays the page's own action briefly so that tags have time to send, and a validation option that only fires when the browser would actually submit the form; both are worth understanding because a form trigger that fires on every attempt, including failed validation, inflates the conversion rate (CVRShare of visits or clicks that convert.) the business reads. The form tracking tutorial replaces that trigger with a push the site sends once the server has accepted the submission.
Exceptions are the other half. A tag can carry blocking triggers as well as firing triggers; if a blocking trigger matches the same event, the tag does not fire. Because an exception is just a trigger, one rule can be written once and reused across many tags: a trigger for internal traffic, a trigger for a staging hostname, a trigger for a consent state. Each tag also has a firing option that decides whether it may fire once per event, once per page or without limit, which is the simplest guard against double firing when two triggers overlap.
Tags: templates vs custom HTML, tag sequencing
A tag's type decides what it can do and how safe it is. Built-in templates cover Google's own products: the
Google tag, GA4 events, Google Ads conversions and remarketing, Floodlight, and a few more. The community
template gallery adds templates written by vendors and practitioners; a gallery template runs in a sandbox,
declares the permissions it needs, such as reading cookies or sending requests to named domains, and shows
those permissions before you add it. Custom HTML tags accept arbitrary script, with an option to let it use
document.write; they can do anything, which means they must be read by someone who can judge what they do.
Custom image tags request a single pixel URL and are the safe choice for a vendor that only needs a beacon.
Every tag has advanced settings that shape how it runs. Tag firing priority orders tags that share a trigger, higher first, but it does not wait for one to finish before starting the next, so it is not a dependency mechanism. Tag sequencing is: a tag can name a setup tag to fire immediately before it and a cleanup tag to fire immediately after, with options to skip the main tag if the setup tag fails and to skip the cleanup if the main tag fails. Sequencing is how a container guarantees that a configuration or consent-related tag has run before a dependent one. Consent settings, covered in the consent mode guide, sit in the same panel. The GA4 through GTM tutorial shows the Google tag and GA4 event tag configured end to end, which is the most common use of all of this. Tags, triggers and patterns drafted by an AI tool need the same reading before they reach a workspace, and the tutorial on checking AI-written tracking code sets out that review against the tracking plan and both consent states.
Patterns: one tag many triggers, lookup tables, trigger groups
Composition is what separates a container that can be maintained from one that cannot. The patterns below recur in almost every well-run container.
One tag, many triggers; one trigger, many tags. A trigger is reusable and a tag can carry several, so the
same "all pages" trigger serves every page-level tag, and the same custom event trigger for purchase serves
the GA4Google's event-based analytics platform. event tag and the ad platform conversion tags alike. Resist creating a near-duplicate
trigger for each new tag.
The generic event tag. One GA4 event tag whose event name field reads the built-in event variable, attached to a custom event trigger that matches every planned event name by pattern, replaces a dozen one-event tags. Parameters come from an event settings variable or from data layer variables with the same names as the planned keys. The trade-off is visibility: the container shows one tag where a reviewer might expect many, so document the pattern where the next person will see it.
Lookup tables for mapping. A lookup table turns a page path into a content group, an event name into a Google Ads conversion label, or a hostname into a measurement ID. The mapping lives in one place and the tags read it, so adding a case means editing a table rather than cloning a tag.
Constants for IDs. Measurement IDs, conversion IDs and vendor account numbers belong in constant variables referenced by the tags, never typed into each tag by hand.
Trigger groups for combined conditions. A trigger group fires once all of its member triggers have fired at least once on the page, which is how "scrolled most of the article and stayed for a while" becomes one engagement event without custom code. The scroll half of that rule is a scroll depthHow far down a page a visitor scrolled, as a share of the page's total length. trigger set at the threshold the team has chosen.
Exceptions for environments and internal traffic. One blocking trigger each, attached to every tag that sends data outward, so staging and office traffic never pollute reports.
A lead-generation site's trigger set and lookup table
A commercial insurance broker has 14 quote forms across 9 landing pages, each built from one template. Instead
of 14 form triggers and 14 GA4 tags, the analyst uses a single custom event trigger on generate_lead, which
the site pushes after the server confirms the submission, and one GA4 event tag. A lookup table maps the
page path to a product line (fleet, liability, property and so on), with a default of "other", and that
output is sent as a product_line parameter. A second lookup table maps the same input to the matching
Google Ads conversion label, so one conversion tag covers all 14 forms. The office's static IP range feeds an
exception trigger attached to both tags. In the first fortnight the GA4 count for generate_lead is 312
against 318 confirmed submissions in the CRM, and the 6 missing are traced to a product line added to the
template without a row in the lookup table, which the default value had quietly labelled "other".
Common mistakes
- One trigger per tag, always. Dozens of near-identical triggers nobody dares delete. Reuse triggers and name them by what they match, not by the tag they were made for.
- Scraping the DOM instead of asking for a push. The trigger worked until the button's class changed. Anything the business depends on belongs in the data layer.
- Custom HTML for a vendor that has a template. Unreviewed script in the container when a sandboxed template exists. Check the gallery first.
- Priority as a dependency. Setting a higher priority on the configuration tag and assuming the event tag will wait. Use sequencing, or the initialisation trigger, when order matters.
- Form triggers that fire on attempts. Validation errors counted as leads. Push a confirmed event from the site, or at least enable validation on the trigger.
- Enabled built-ins and variables nobody uses. The variables pane becomes a graveyard. Prune on every review, as the containers guide suggests for versions.
- Testing the change list instead of the page. A trigger with a typo fires nowhere. Prove every tag in preview, following the debugging tutorial, before the version goes live. The Tag Manager hub lists the rest of this section.
