7.9 KiB
Complete GTM-GA4 Setup Guide
Prerequisites
- GTM Container Installed - GTM container code already on website
- GA4 Property Created - GA4 property with Measurement ID available
- GTM Editor+ Access - Required permissions to create/modify tags
Step-by-Step Setup
Step 1: Install GTM Container (If Not Already Installed)
GTM Container Code Location:
Place in <head> section (immediately after <head> tag):
<!-- 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 -->
Place noscript fallback in <body> (immediately after <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) -->
Step 2: Create GA4 Configuration Tag
In GTM Workspace:
- Navigate to Tags → New
- Tag Name: "GA4 - Configuration" (or "GA4 - Base Tag")
Tag Configuration:
- Click Tag Configuration box
- Select Google Tag (tag type)
- Tag ID: Enter GA4 Measurement ID (format:
G-XXXXXXXXXX)- Find in: GA4 Admin → Data Streams → Web Stream → Measurement ID
Configuration Settings (Optional):
- Click Configuration Settings (expand if needed)
- Set optional parameters:
- send_page_view: true (default - automatically sends page_view events)
- allow_google_signals: true (for Demographics/Remarketing)
- allow_ad_personalization_signals: true
Shared Event Settings (Optional):
- Click Shared Event Settings to add parameters sent with ALL events:
- Example:
user_tier,page_category, etc.
- Example:
Triggering:
- Click Triggering box
- Select Initialization - All Pages
- This fires BEFORE page_view
- Ensures GA4 loads on every page
Save:
- Click Save
Result: GA4 Configuration tag created and will fire on all pages
Step 3: Test GA4 Configuration Tag
Using GTM Preview Mode:
- Click Preview button (top-right of GTM)
- Enter your website URL
- Click Connect
- Tag Assistant opens in new window
Verify in Tag Assistant:
- Summary tab shows "Tag Fired: GA4 - Configuration"
- Tag appears in "Tags Fired" section
- Event:
gtm.js(GTM initialization) - Initialization trigger activated
Verify in GA4 DebugView:
- Open GA4 property
- Go to Admin → DebugView
- See events appearing in real-time:
page_view(automatic from GA4 Configuration tag)session_startfirst_visit(if first time)
Step 4: Create GA4 Event Tags
Example: Button Click Event
Create Tag:
- Tags → New
- Name: "GA4 - Button Click - Subscribe"
- Tag Configuration → Google Tag
- Tag ID: Same GA4 Measurement ID (G-XXXXXXXXXX)
- Event Name:
button_click
Event Parameters:
- Click Add Parameter
- Parameter entries:
- Parameter Name:
button_name→ Value:{{Button Text}}(variable) - Parameter Name:
button_location→ Value:header - Parameter Name:
button_id→ Value:{{Click ID}}
- Parameter Name:
Triggering:
- Click Triggering
- Click "+" to create new trigger
Create Trigger:
- Trigger Name: "Click - Subscribe Button"
- Trigger Type: Click - All Elements
- This trigger fires on: Some Clicks
- Filter:
- Click ID → equals →
subscribe-btn
- Click ID → equals →
- Click Save
Save Event Tag:
- Click Save
Step 5: Create Form Submission Event
Create Tag:
- Tags → New
- Name: "GA4 - Form Submit - Contact"
- Tag Configuration → Google Tag
- Tag ID: G-XXXXXXXXXX
- Event Name:
form_submit
Event Parameters:
- Add Parameters:
form_name→{{Form Name}}form_id→{{Form ID}}form_destination→/thank-you
Create Trigger:
- Triggering → New Trigger
- Name: "Form - Contact Form Submit"
- Type: Form Submission
- Fire on: Some Forms
- Filter: Form ID → equals →
contact-form - Save trigger and tag
Step 6: Implement Custom Event with Data Layer
On Website (in code):
// When user adds item to cart
document.querySelector('.add-to-cart-btn').addEventListener('click', function() {
dataLayer.push({
'event': 'add_to_cart',
'product_id': 'SKU_123',
'product_name': 'Blue T-Shirt',
'price': 29.99,
'quantity': 1
});
});
In GTM:
Create Data Layer Variables:
- Variables → New
- Name: "DL - Product ID"
- Type: Data Layer Variable
- Variable Name:
product_id - Save
Repeat for product_name, price, quantity
Create GA4 Event Tag:
- Tags → New
- Name: "GA4 - Add to Cart"
- Tag Type: Google Tag
- Tag ID: G-XXXXXXXXXX
- Event Name:
add_to_cart - Parameters:
product_id→{{DL - Product ID}}product_name→{{DL - Product Name}}price→{{DL - Price}}quantity→{{DL - Quantity}}
Create Trigger:
- Triggering → New
- Name: "Custom Event - Add to Cart"
- Type: Custom Event
- Event name:
add_to_cart - Save
Step 7: Test All Tags with Preview Mode
Preview Workflow:
- Click Preview in GTM
- Connect to website
- Navigate pages and interact with elements
- Tag Assistant shows:
- Which tags fired
- Which didn't fire (and why)
- Variable values
- Data layer state
Check Each Event:
- Click subscribe button → Verify "GA4 - Button Click" fires
- Submit contact form → Verify "GA4 - Form Submit" fires
- Add item to cart → Verify "GA4 - Add to Cart" fires
Verify in GA4 DebugView:
- All events appear with correct names
- Parameters populate with expected values
- No duplicate events
Step 8: Publish GTM Container
When Ready:
- Click Submit (top-right)
- Version Name: "GA4 Initial Setup - [Date]"
- Version Description:
- Added GA4 Configuration tag - Added button click tracking - Added form submission tracking - Added add_to_cart event via data layer - Click Publish
- Result: Changes live immediately on website
Step 9: Verify Production
After Publishing:
- Visit website (incognito/private mode)
- Enable Google Analytics Debugger Chrome extension
- Interact with tracked elements
- Check GA4 DebugView for events
Wait 24-48 hours:
- Events appear in standard GA4 reports
- Custom dimensions/metrics populate
Common Setup Issues
| Issue | Cause | Solution |
|---|---|---|
| Tags not firing | Wrong trigger conditions | Check trigger settings in Preview mode |
| GA4 Configuration not firing | Wrong trigger selected | Must use "Initialization - All Pages" |
| Parameters empty | Variables not created | Create Data Layer Variables first |
| Duplicate page_views | Both gtag.js and GTM | Remove gtag.js snippet from website |
| Events delayed | Normal processing | Events appear in DebugView immediately, reports in 24-48 hours |
Best Practices
Naming Conventions:
- Tags: "GA4 - [Event Name]"
- Triggers: "[Type] - [Description]"
- Variables: "DL - [Variable Name]" or "GTM - [Built-in Name]"
Organization:
- Use folders for related tags/triggers/variables
- Document changes in version descriptions
- Test thoroughly before publishing
- Keep GA4 Configuration tag separate from event tags
Performance:
- Use specific triggers (not "All Elements" when possible)
- Minimize data layer pushes
- Batch related events when feasible