Google Tag Manager Tutorial
Google Tag Manager (GTM) is a no-cost Google tool that lets you add and manage tracking code on a website from one web interface, without editing the site each time. You place one container on the site, then add tags for GA4, Google Ads, Meta and others, and control when each one fires.
- Container: One snippet on every page that holds all your tags.
- Tags: The tracking code, such as a GA4 event tag or a Google Ads conversion tag.
- Triggers: Rules that say when a tag fires, such as on a page view or a booking.
- Variables: Values that tags and triggers use, such as the page URL or the number of guests.
- Preview mode: A test session that shows which tags fired before you publish.
This Google Tag Manager tutorial follows one example: a family restaurant in Jaipur that takes table bookings on its website. It runs Google Ads for "rooftop restaurant in Jaipur" and Instagram ads for its weekend thali. The owner wants each booking recorded in GA4, Google Ads and Meta, without calling the web developer every time a new tag or a small change is needed.
Today the developer has pasted three different tracking codes straight into the site, and nobody on the marketing side knows exactly which ones still work or what each one sends. Moving all of them into one GTM container gives the owner a single place to see every tag, test changes safely and undo mistakes, while the developer only has to add the container and one booking event once.
Prerequisites for Google Tag Manager
- A Google account: Use a shared business account, not a personal one.
- Site access: Admin access to the site builder or its code, needed only once to add the container, after which most changes happen inside GTM.
- A GA4 property: Its Measurement ID (starting with "G-"), created as in the GA4 tutorial.
- An event plan: A short list of the events you want and the names you will use for them, designed as in GA4 events and conversions.
- A consent plan: Decide how the cookie banner will control tags, covered in Consent Mode v2.
Setup: Create a Container
- Go to tagmanager.google.com and select Create account.
- Account name: Use the business name, for example "Jaipur Rooftop Kitchen", and set the country to India.
- Container name: Use the website address as the name and choose Web as the target platform.
- Install the code: GTM shows two snippets, where the first goes high in the head of every page and the second goes right after the opening body tag. Many site builders and WordPress plugins only ask for the container ID, which starts with "GTM-".
- Avoid doubles: If the GA4 tag is already hard-coded on the site, remove it once GTM takes over, or page views will count twice.
Step-by-Step: Track Table Bookings with GTM
Step 1: Add the Google Tag
In the workspace, go to Tags > New. Choose Google Tag as the tag type and paste the GA4 Measurement ID. Set the trigger to Initialization - All Pages so it loads before other tags. Name the tag clearly, for example "GA4 - Google tag".
Step 2: Push the Booking to the dataLayer
The restaurant's developer adds one small piece of code that runs after a booking is saved, not when the button is clicked, so that bookings which fail or are abandoned are never counted.
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
event: "book_table",
guests: 4,
meal: "dinner",
booking_id: "JRK-20417"
});- event: The name GTM listens for, which should be lowercase with underscores so it matches your event plan.
- guests and meal: Details the owner wants to see in reports, such as whether weekend dinners bring larger groups.
- booking_id: A unique reference that helps spot duplicate bookings; never push the customer's name, phone number or email address.
Step 3: Create Variables
Go to Variables > User-Defined Variables > New and choose Data Layer Variable. Create one for guests, one for meal and one for booking_id, using the exact key names. Also switch on useful built-in variables such as Page Path and Click URL.
Step 4: Create a Trigger
Go to Triggers > New, choose Custom Event, and type book_table as the event name. It must match the dataLayer event name exactly, including case. Leave it on All Custom Events with that name.
Step 5: Create the GA4 Event Tag
Go to Tags > New > Google Analytics: GA4 Event. Enter the Measurement ID, set the event name to book_table, add the event parameters guests, meal and booking_id using the variables from Step 3, and attach the book_table trigger.
Step 6: Add Ad Platform Tags
Use the same trigger for other tags:
- Google Ads: A Google Ads Conversion Tracking tag with the conversion ID and label from the Ads account.
- Meta: The Meta Pixel through a community template or Meta's own setup, sending a Lead or Schedule event. Pair it with the Conversions API as explained in Meta Pixel and CAPI.
Step 7: Test in Preview Mode
Select Preview at the top of the workspace, enter the site address, and make a test booking in the window that opens. Tag Assistant lists each event on the left, in the order it happened. Select book_table and check that the GA4, Google Ads and Meta tags show as Fired, with the right values in the Variables tab. Then open GA4 DebugView to confirm the event arrived.
Step 8: Submit and Publish
Select Submit, write a version name and a note, such as "Booking tracking for GA4, Ads and Meta", and publish. GTM saves every version, so you can roll back if something breaks.
Common Mistakes in Google Tag Manager
- Tracking the click, not the result: A Click trigger on the Book button also counts people who clicked but did not finish, so use the dataLayer event that fires after success.
- Case mismatch: Book_Table in the code and book_table in the trigger means the tag never fires.
- Double tagging: GA4 installed by a plugin and by GTM doubles every page view.
- Publishing without preview: Small errors reach real data and are hard to clean up later.
- Unclear names: Tags called "Tag 1" and "New trigger" become impossible to manage, so name every item in the pattern "Platform - Type - Detail".
- Ignoring consent: Tags that should wait for consent must respect the visitor's choice on the banner, which you control through the consent settings inside each tag.
Next Steps
- Server-side: Move tags from the browser to a server you control with server-side tagging.
- Better matching: Send hashed first-party data to Google Ads with enhanced conversions.
- Campaign links: Tag every ad and WhatsApp link with UTM parameters so bookings are credited to the right source.
How AI Changes Google Tag Manager Work
What AI Automates Now
AI assistants can turn a tracking plan into dataLayer code, suggest tag, trigger and variable names, and explain why a tag did not fire when you paste the preview output. Some tools can read a container export (a JSON file) and list unused or duplicate tags.
What Still Needs a Human
Someone must decide what counts as a booking, test every change in preview mode, and approve each publish. AI cannot see your live site, the booking system or the payment flow, so any code it writes is only a draft until a person has tested it on the real site.
Risk to Watch
Generated code can use wrong tag type names, outdated settings or event names that GA4 treats differently, and it can look perfectly reasonable until you test it in preview mode. A pasted container export may also hold account IDs and settings you would not share publicly, so remove anything sensitive before sharing it with any AI tool.
Do It with AI
Use this prompt to plan tags, triggers and variables for one action. It works in ChatGPT, Claude or Gemini.
You are a Google Tag Manager specialist. Website: [type of business and platform, for example a restaurant site on WordPress] Action to track: [for example, a successful table booking] Details available after the action: [for example, number of guests, meal, booking ID] Platforms that need the event: [GA4, Google Ads, Meta] 1. Write the dataLayer.push code for the moment the action succeeds. 2. List the Data Layer Variables, the trigger and each tag, with clear names. 3. Give a preview mode test checklist, one line per tag. 4. List the most likely reasons a tag would not fire. Do not include personal data such as names, phone numbers or email addresses in the dataLayer.
- Describe the action you want to track and the platforms that need it in the prompt.
- Give the dataLayer code to your developer to add after the success step.
- Build the variables, the trigger and each tag in GTM, using the names the AI suggested or your own.
- Test every line of the checklist in preview mode, then publish.
Check Before You Use It
- Facts: Match every tag type, field name and event name against Google's and Meta's current help pages.
- Brand fit: Name events the way your reports and team already talk about them.
- Compliance: Respect consent choices, and keep personal data out of the dataLayer.
Quick Quiz
Pick an answer to check yourself. Nothing is saved.
Question 1 / 3
1. The restaurant wants the GA4 booking tag to fire only when a booking succeeds. What decides when a tag fires?
Frequently Asked Questions
Is Google Tag Manager the same as Google Analytics?
No. Google Analytics 4 stores and reports data. Google Tag Manager is a container that loads tracking code, such as the GA4 tag, the Google Ads tag or the Meta Pixel, on your site. GTM collects nothing by itself.
Does Google Tag Manager slow down my website?
The container itself is light, but every tag inside it adds work for the browser. A container with many old or duplicate tags can slow pages. Remove tags you no longer use and review the container every few months.
What is the dataLayer in Google Tag Manager?
The dataLayer is a JavaScript list on the page where the site places information, such as an event name or a booking value. GTM reads it to decide when tags fire and what details they send.
Do I need a developer to use Google Tag Manager?
A developer is needed once, to add the container code and to push important events like bookings or purchases into the dataLayer. After that, marketers can add and change most tags in GTM without code releases.
What happens if I publish a broken change in GTM?
GTM keeps every published version. Open Versions, choose the last working version and publish it again. Testing in preview mode before publishing avoids most problems.
Related Articles
- GA4 Events and ConversionsGA4 events explained: automatic, enhanced, recommended and custom events, and how to mark key events, with a coaching institute example and an AI prompt.
- GA4 Tutorial for BeginnersGA4 tutorial for beginners: create a property, install the Google tag, track purchases as key events and read your first reports, with a D2C store example.
- Server-Side Tagging (sGTM)Server-side tagging explained: how an sGTM server container works, what it improves, what it costs and where consent still applies, with a Kolkata example.
- Enhanced Conversions and Offline Conversion ImportEnhanced conversions and offline conversion import explained: hashed first-party data, GCLID uploads and consent, with a Gurugram interiors firm example.
- Meta Pixel and Conversions API (CAPI)Meta Pixel and Conversions API setup: send purchases from browser and server, deduplicate with event_id and respect consent, with a Surat saree store.
- Consent Mode v2Consent Mode v2 set up step by step: basic vs advanced mode, the four consent parameters and a working gtag example, so Google tags respect every visitor.