How Tag Managers Work
A tag manager runs through a script that the website loads in the browser.
The script does not run every possible tag by itself. It loads a container configuration, starts a runtime, watches browser activity, evaluates trigger rules, resolves variables, and runs the tags whose trigger rules match.
The Browser Flow
Most tag manager requests follow this flow:
- The website loads the container script.
- The browser requests the script from the tag manager or tracking domain.
- The script loads the current published container configuration.
- The runtime starts and reads the page context it can access.
- The runtime registers listeners for page, click, form, route, timer, scroll, visibility, or custom event behavior.
- When an event happens, the runtime checks matching triggers and conditions.
- If a trigger matches, the runtime resolves any variables the tag needs.
- The tag runs in the browser.
The result depends on the tag type. A tag can send an event request, fire a pixel, modify a link, push a custom event, inject HTML, or run JavaScript.
Trigger Evaluation
Triggers are usually made of two parts:
- the browser event to listen for
- optional conditions that narrow when the trigger is allowed to match
For example, a click trigger can listen for click events and then check the clicked URL, clicked element text, CSS selector, page path, referrer, query parameter, or data-layer value.
A page trigger can listen for DOM ready, window load, or route changes. A form trigger can listen for submit events. A visibility trigger can use browser intersection behavior to detect when an element appears in the viewport.
Variable Resolution
Variables are resolved when the runtime needs their values.
A variable can read from sources such as:
- the current URL
- query parameters
- referrer values
- cookies
- JavaScript variables
- data-layer state
- DOM elements
- the current click or form event
- constants or generated utility values
When a tag field uses a template such as {{order_id}}, the runtime looks up
the matching variable name and inserts the resolved value into that field.
Data Layers
A data layer is a structured way for the website and tag manager to exchange values.
Pages can push events or data into the data layer. The tag manager can read those values later, use them in trigger conditions, or pass them into tags.
Data layers are useful when the value a tag needs is not stable in the DOM or URL. For example, a checkout page might place order ID, order value, product SKU, currency, or customer state in a data layer so tags can read those values without scraping the page.
Publishing And Caching
Most tag managers separate editing from publishing.
Draft changes are saved in the tag manager interface. Published changes are compiled into the version the website can load. The browser may cache the published script for a short time, so the live page loads the latest published version according to the script serving and browser caching rules.
Was this page helpful?