Last Updated on by Azib Yaqoob
Google Tag Manager (GTM) is a free tool that lets you add and change tracking, like GA4, Google Ads and the Meta pixel, without editing your website code each time. This guide walks you through it step by step, current as of November 2026.
It also shows how to use an AI assistant as a GTM co-pilot: planning what to track, writing small scripts, and working out why a tag did not fire. AI helps with the thinking and typing. You still test everything in Preview mode before you publish.
Quick answer: Create a free container at tagmanager.google.com, install the two snippets on your site, add a Google tag with your GA4 Measurement ID, test it in Preview (Tag Assistant), then Submit to publish. After that, add one event at a time: a trigger decides when it fires, variables supply the details. Use AI to draft your tracking plan, dataLayer code and debugging checklists, but never paste personal data into it.
Table of Contents
How Google Tag Manager works: tags, triggers and variables
GTM has three building blocks. Learn these and the rest of the interface makes sense.
- Tags are the tracking code that runs, such as the Google tag (for GA4), a GA4 event tag or a Google Ads conversion tag.
- Triggers decide when a tag runs: on every page, on a button click, or when a form is submitted successfully.
- Variables hold the details a tag needs: a page URL, an order value or a form ID.
Everything lives in a container, and nothing goes live until you publish. You can test first and roll back to an older version if something breaks.
One more idea matters later: the data layer. It is a JavaScript list called dataLayer where your website posts information (for example, “a purchase happened, value 49.00”). GTM reads it through Data Layer Variables. It is the cleanest way to get reliable data into GTM.

Step 1: Create your account and container
- Go to tagmanager.google.com and click Create account.
- Use your company name as the account name and your website address as the container name.
- Choose Web as the target platform and accept the terms.
- GTM shows two code snippets and a container ID that starts with
GTM-.
Google has been updating the Tag Manager interface through 2026. Its own update notes describe a new Settings section and an Advanced tab that groups Triggers, Variables, Templates and Folders. If your screen looks slightly different from this guide, look under those areas. The concepts are the same.
Step 2: Install GTM on your website
The first snippet goes in the <head> of every page and the second right after the opening <body> tag.
- WordPress: use a GTM plugin and enter your
GTM-ID. It adds both snippets for you. If you are still setting up analytics, my guide on setting up Google Analytics in WordPress, Shopify and Wix covers the platform differences. - Other websites: paste the snippets into your header template, or send them to your developer.
- Shopify: checkout does not allow GTM code directly, so purchase tracking needs Shopify’s customer events. See why Shopify GA4 purchases go missing.
Install GTM only once. Two copies of the container make every tag fire twice.
Step 3: Add your first tag (the Google tag for GA4)
- In GTM, click Tags, then New.
- Choose Google tag as the tag type and enter your GA4 Measurement ID (it starts with
G-). - For the trigger, choose Initialization – All Pages.
- Name it clearly, for example “Google tag – GA4”, and save.
If GA4 is already on your site through a theme or plugin, remove that first, or every page view is counted twice.
Step 4: Test in Preview mode with Tag Assistant
- Click Preview and enter your website address.
- Your site opens in a new tab connected to Tag Assistant. Check your tag appears under Tags Fired.
- In GA4, open Admin, then DebugView (or Reports, then Realtime) and confirm your visit shows up.
Turn off ad blockers while testing. They block GTM and make a working setup look broken.

Step 5: Publish
Click Submit, give the version a name that describes the change, such as “Added Google tag for GA4”, and publish. Version names make it easy to find and undo a change later.
Step 6: Add a real event (a GA4 event tag)
Your first event shows the full tag, trigger and variable pattern. Say you want to track clicks on a “Book a call” button.
- Create a trigger: type Click – All Elements (or Just Links), set to fire on Some Clicks, for example when Click Text equals “Book a call”.
- Create a tag: type Google Analytics: GA4 Event, enter your Measurement ID, and set the event name to something like
book_call_click. - Attach the trigger, save, and test in Preview. Click the button and confirm the tag fires on the click event.
- Publish only after it works.
For forms, the right trigger depends on how your form behaves. I cover it in tracking WordPress contact form submissions in GA4. In GA4 you then mark the event as a key event if it counts as a conversion.
Use AI as your GTM co-pilot
ChatGPT, Claude, Gemini and similar assistants are useful for the parts of GTM that are about planning and code. They cannot see your container, your site or your GA4 data unless you paste it in, and they can state wrong things confidently. Treat every answer as a draft to test in Preview.
Do not paste personal data. Remove emails, names, phone numbers, addresses, order IDs tied to customers, API keys and access tokens before you paste anything into an AI tool. Container exports and Tag Assistant output can contain these. Replace them with placeholders like EMAIL_REDACTED. If your client has a policy on AI tools, follow it.
Prompt 1: Plan a tracking spec
What it does: turns a plain description of your site into a list of events, triggers and variables. Paste in: a short description of your site and your goals.
You are a GA4 and Google Tag Manager consultant. My site: [describe: e.g. WordPress lead-gen site with a contact form and a pricing page].
My goals: [e.g. know which pages drive enquiries].
Create a tracking plan as a table with columns: event name (GA4 snake_case), when it should fire, GTM trigger type, parameters needed, and whether it needs a developer dataLayer push.
Use recommended GA4 event names where they exist. Keep it to the 6 most useful events. Flag any assumption you made.Prompt 2: Write a custom JavaScript variable
What it does: drafts a GTM Custom JavaScript variable. Paste in: what value you need and the page element or URL pattern it comes from.
Write a Google Tag Manager Custom JavaScript variable. It must be an anonymous function that returns a value.
Goal: return the product category from the URL path. Example URL: https://example.com/shop/shoes/running-shoe-123/
Return "unknown" if nothing matches. Use plain ES5 syntax (no arrow functions, no let/const) and add no external libraries.
Explain each line in one short sentence.Plain ES5 is the safest choice for GTM Custom JavaScript variables, because it avoids syntax errors. After you paste the code, check the variable’s value under the Variables tab in Preview.
Prompt 3: Generate dataLayer.push code for your developer
What it does: writes the snippet your developer places on the page, plus a short note explaining where it goes. Paste in: the event and the data you want.
Write a dataLayer.push snippet for a GA4 "generate_lead" event that fires after a successful form submission.
Include parameters: form_name (string) and form_location (string).
Do not include any personal data such as email or name.
Add a short note to a developer: where to place it, that window.dataLayer = window.dataLayer || [] should come first, and how to confirm it in GTM Preview.The result should look like window.dataLayer.push({ event: 'generate_lead', form_name: 'contact', form_location: 'footer' });. In GTM you then create a Custom Event trigger named generate_lead and Data Layer Variables for the parameters.
Prompt 4: Debug why a tag is not firing
What it does: gives you a ranked checklist of likely causes. Paste in: the tag settings, the trigger settings, and what Tag Assistant showed for the event (Tags Fired or Tags Not Fired, and the trigger conditions). Remove personal data first.
My GTM tag does not fire. Help me debug it.
Tag type and settings: [paste]
Trigger type and conditions: [paste]
What Tag Assistant shows: the tag is under "Tags Not Fired" on the event [event name]. The trigger conditions it lists are: [paste]
Variable values shown in Tag Assistant at that event: [paste, personal data removed]
List the 5 most likely causes in order of probability, and for each one tell me exactly what to check in GTM Preview. Do not guess about data you cannot see; ask me for it.Common causes the assistant should raise: a trigger condition that does not match the real variable value, an event name with different capitalisation, the tag firing before the data layer push, a consent setting blocking the tag, or the tag being in a different container than the one on the page.
Prompt 5: Review a container export
What it does: audits your container for duplicates, unused items and naming problems. Paste in: a JSON export (in GTM, go to Admin, then Export Container). Search the file for emails, names and keys and replace them first. Large containers may be too long for one message, so paste part of it or ask for a review one section at a time.
Below is a Google Tag Manager container export (JSON). Review it and list:
1. Tags that look like duplicates (same measurement ID or same event firing twice).
2. Triggers or variables that no tag appears to use.
3. Naming that is inconsistent or unclear.
4. Tags that fire on "All Pages" but probably should not.
5. Anything that looks risky (custom HTML tags, hard-coded IDs).
Only report what is in the JSON. If you cannot tell, say so. Do not invent items.
[paste JSON here]A reviewer that only reads text can miss things, such as whether a trigger really matches your site. Use its list as a starting point and verify each finding in the GTM interface.
Free resources for learning and extending GTM
You can do all of this at $0. These are the sources worth bookmarking.
| Resource | What it is for |
|---|---|
| Tag Manager Help | Google’s official documentation and getting-started guide. |
| Tag Assistant | Free debugger that powers GTM’s Preview mode. |
| Community Template Gallery | Google’s page about the gallery of ready-made tag and variable templates built by the community. You browse and add templates inside GTM. |
| google/data-layer-helper | Google’s open-source JavaScript library for working with dataLayer message queues. Useful for developers who want to understand how the data layer works. |
| mbaersch/datalayer-event-repeater | Open-source (Apache-2.0) GTM tag template that re-pushes matching dataLayer events. Handy when a tag loads too late and misses early events. |
| stape-io/user-data-extractor-variable | Open-source (Apache-2.0) variable template for server-side GTM that extracts user data from events. |

Treat community templates like any third-party code. Check who made them, read what data they send and where, and test them in Preview before publishing. You can also search GitHub’s gtm-template topic for more open-source templates.
Where server-side tracking and Google tag gateway fit
Everything above runs in the visitor’s browser. That is called web (client-side) tracking, and it is the right place to start.
Later you may want more control or more reliable data. Two Google options exist as of November 2026:
- Server-side GTM adds a server container that receives events and forwards them to GA4, ads platforms and others. It needs hosting. I compare the two common choices in Stape vs Google Cloud for server-side GTM.
- Google tag gateway for advertisers lets you serve Google tag scripts from your own domain. See Google’s official overview to see whether your hosting setup supports it.

If you run ads, the browser pixel and the server-side Conversions API do different jobs. My comparison Meta Pixel vs Conversions API explains when you need both.
Good habits for beginners
- Use clear names, like “GA4 – Event – generate_lead”, so anyone can understand the container.
- Give access only to people who need it, and use Publish permission sparingly.
- Change one thing, test it in Preview, then publish.
- Remove tags you no longer use.
- Use workspaces and version names so you can roll back.
Frequently asked questions
Is Google Tag Manager free?
Yes, the standard web version is free. As of November 2026, Google also offers a paid enterprise tier (Tag Manager 360). Server-side tagging has hosting costs that depend on your setup.
How do I use Google Tag Manager as a complete beginner?
Follow steps 1 to 5 above: create a container, install it, add a Google tag, test in Preview, and publish. Then add one event at a time.
Do I need to know how to code to use GTM?
Not for basics like page views and button clicks. For custom data, such as e-commerce purchases, a developer usually adds dataLayer code, and AI can draft it for them.
Can AI set up Google Tag Manager for me?
AI can plan, explain and draft code, but it cannot see or change your container unless you give it the data, and it can be wrong. You still build, preview and publish yourself.
Why is my GA4 tag not firing in GTM?
Open Preview and check whether the tag is under Tags Fired or Tags Not Fired. If it did not fire, compare the trigger conditions with the actual variable values Tag Assistant shows. Prompt 4 above helps you work through it.
Conclusion
Start small: one container, one Google tag, one tested event. Use AI for plans and drafts, use Preview for proof, and keep personal data out of your prompts. If you would rather have the setup done for you, including GA4, Meta and server-side GTM, see my tracking services.
