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.
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.
Consent mode, naming and access control
Consent mode passes the visitorβs consent choices (ad_storage, analytics_storage, ad_user_data, ad_personalization) to Google tags, which adjust their behaviour accordingly. Requirements depend on where your visitors are: for users in the European Economic Area, Google requires consent signals for some advertising features, and privacy laws in many regions require consent before non-essential tracking. Integrate a consent management platform through GTMβs consent settings and ask your legal or privacy team what applies to your audience; GTM implements consent, it does not decide what you need.
A few habits keep a container maintainable as it grows:
- Name everything by type and purpose: "GA4 Event - generate_lead", "Trigger - CE - generate_lead", "DLV - form_id". Anyone can then find things by searching.
- Use folders per vendor or per project, and delete tags for tools you no longer use.
- Give publish permission only to a small number of trusted people. Others can have Edit or Approve access so changes are reviewed before they go live.
- Treat Custom HTML tags as code deployments. They can read anything on the page, including form fields, so review the source of every third-party script and prefer built-in templates from the Community Template Gallery, which run in a sandbox with declared permissions.
- Remove access promptly when people or agencies leave, and review the user list regularly.
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.