How to set up GTM for GA4 (the right way)
Step-by-step guide to configuring Google Tag Manager with Google Analytics 4. Learn the new Google Tag setup, event tracking, and best practices.
If you're doing anything beyond basic pageview tracking in GA4, you need Google Tag Manager. It gives you control over what gets tracked and when, without touching your site's code.
Let me walk you through the , including the recent changes to how GTM handles GA4.
What changed: GA4 Configuration Tag → Google Tag
If you set up GTM before 2024, you probably used a "GA4 Configuration" tag. That's been renamed to "Google Tag." Same functionality, different name.
Your existing tags still work. They were automatically converted. But new setups use the updated interface.
Phase 1: Setting up GTM
Create a GTM account (if you don't have one)
- Go to tagmanager.google.com
- Click Create Account
- Enter account name (usually your company name)
- Enter container name (usually your domain)
- Select Web as target platform
- Accept the terms
Install GTM on your site
You'll get two code snippets:
Snippet 1: Goes in the <head> section
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXXXXX');</script>
<!-- End Google Tag Manager -->
Snippet 2: Goes immediately after the opening <body> tag
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXXX"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
Replace GTM-XXXXXXX with your actual container ID.
Phase 2: Setting up the Google Tag
The Google Tag is your foundation. It initializes GA4 on every page.
Step-by-step
- In GTM, go to Tags → New
- Click Tag Configuration
- Select Google Tag
- Enter your Tag ID (your GA4 Measurement ID, starts with
G-) - Under Triggering, select Initialization - All Pages
- Name your tag (e.g., "GA4 - Google Tag")
- Save
Why Initialization trigger?
The Initialization trigger fires before other triggers, ensuring:
- GA4 is ready before events fire
- UTM parameters are captured properly
- No events get lost during page load
Some guides use "All Pages" which works, but Initialization is cleaner.
Find your Measurement ID
If you don't know your GA4 Measurement ID:
- Go to GA4 → Admin → Data Streams
- Click your web stream
- Copy the Measurement ID (format:
G-XXXXXXXXXX)
Phase 3: Setting up GA4 Event Tags
Now let's track specific actions.
Basic event tag structure
For each action you want to track:
- Go to Tags → New
- Select Google Analytics: GA4 Event
- Enter your Measurement ID (or use a , see below)
- Enter the event name
- Add event parameters if needed
- Set the appropriate trigger
- Save
Pro tip: Use a variable for Measurement ID
Instead of typing your Measurement ID in every tag:
- Go to Variables → User-Defined Variables → New
- Select Constant
- Enter your Measurement ID
- Name it "GA4 - Measurement ID"
Now use {{GA4 - Measurement ID}} in all your event tags. If you ever need to change it, update one place.
Example: Tracking button clicks
Let's track clicks on a CTA button.
Step 1: Enable click variables
- Go to Variables → Configure
- Enable under Built-In Variables:
- Click Element
- Click Classes
- Click ID
- Click URL
- Click Text
Step 2: Create the trigger
- Go to Triggers → New
- Select Click - All Elements
- Configure:
- Trigger fires on: Some Clicks
- Click Classes contains
cta-button(or whatever class your button uses)
- Name it "Trigger - CTA Button Click"
- Save
Step 3: Create the event tag
- Go to Tags → New
- Select Google Analytics: GA4 Event
- Configure:
- Measurement ID:
{{GA4 - Measurement ID}} - Event Name:
cta_click - Event Parameters:
- Parameter Name:
button_text/ Value:{{Click Text}} - Parameter Name:
page_path/ Value:{{Page Path}}
- Parameter Name:
- Measurement ID:
- Trigger: "Trigger - CTA Button Click"
- Name it "GA4 - CTA Click Event"
- Save
Example: Tracking form submissions
Method 1: Form submission trigger
If your forms do a traditional submit:
- Create trigger: Form Submission
- Configure:
- Wait for Tags
- Check Validation (optional)
- Trigger fires on forms where Form ID equals
contact-form
- Create GA4 Event tag with event name
form_submit
Method 2: Success page trigger
If your forms redirect to a thank-you page:
- Create trigger: Page View
- Configure:
- Page Path contains
/thank-you
- Page Path contains
- Create GA4 Event tag with event name
form_submit
Method 3: Custom event (Ajax forms)
For modern forms that don't reload:
- Add to your form success handler:
dataLayer.push({
'event': 'form_submit',
'form_name': 'contact'
});
-
Create trigger: Custom Event
- Event name:
form_submit
- Event name:
-
Create GA4 Event tag using this trigger
Settings Variables (new feature)
GTM now has Settings Variables to avoid repeating configurations.
Google Tag: Event Settings Variable
Good for parameters you want on every event:
- Go to Variables → New
- Select Google Tag: Event Settings
- Add common parameters:
page_location:{{Page URL}}page_title:{{Page Title}}
- Name it "GA4 - Event Settings"
Then reference this variable in your GA4 Event tags under Shared event settings.
Testing your setup
GTM Preview Mode
- Click Preview in GTM (top right)
- Enter your website URL
- Your site opens with the debug panel
In the debug panel:
- Left side shows all events fired
- Click an event to see which tags fired
- Check tag details to verify parameters
GA4 DebugView
- While in Preview Mode, go to GA4 → Admin → DebugView
- Perform actions on your site
- Watch events appear in real-time
Important: Preview Mode automatically enables GA4 DebugView. If you're not in Preview, install the GA Debugger extension.
Publishing your changes
Nothing goes live until you publish.
- Click Submit (top right)
- Enter a version name (e.g., "Added form tracking")
- Click Publish
Best practice: Version naming
Use descriptive version names:
- "Initial GA4 setup"
- "Added CTA click tracking"
- "Fixed form submission trigger"
You can always revert to previous versions if something breaks.
Common mistakes to avoid
Double tagging
Don't install GA4 via GTM AND via direct code. Pick one.
Using All Pages instead of Initialization
For the Google Tag, use Initialization trigger. It fires first, ensuring GA4 is ready.
Not testing before publishing
Always use Preview Mode. A broken tag can stop all tracking.
Hardcoding values that change
Use variables for anything that might change, like Measurement ID, domain names, etc.
Too many tags
Each tag adds load time. Consolidate where possible. One well-configured event with parameters beats five separate events.
Organization tips
Use folders
Group related tags, triggers, and variables:
/GA4 - Tags//GA4 - Triggers//Third Party/
Naming conventions
Be consistent:
- Tags:
GA4 - [Event Name] - Triggers:
Trigger - [Description] - Variables:
[Type] - [Description]
Document your setup
Use the Notes field in each tag to explain what it does and why.
What's next?
Once GTM is configured:
If you're managing multiple properties and want a simpler way to see your data, try Analayer. We turn your GA4 data into dashboards that actually make sense.
See your analytics clearly
Stop struggling with Google Analytics. Connect your account and get a cleaner, simpler view of your data in seconds.