Google Tag Manager Setup on Wix
Google Tag Manager (GTM) is the recommended approach for managing multiple marketing tags on Wix. This guide covers installation methods, Wix-specific configuration, and best practices.
Why Use GTM on Wix?
Advantages
- Centralized tag management - Deploy and update tags without editing Wix code
- Version control - Track changes and roll back if needed
- Preview mode - Test tags before publishing
- Multiple tags in one container - GA4, Meta Pixel, ads pixels, etc.
- Advanced tracking - Custom triggers and variables
- Reduced code bloat - One GTM script instead of multiple vendor scripts
Limitations on Wix
- No native Wix data layer - Must build your own with Velo
- SPA navigation challenges - Wix AJAX transitions require special handling
- Limited DOM access - Wix's structure makes some selectors difficult
- Custom code restrictions - Must use Premium Wix plan
- No staging environment - Testing must be done carefully in production
Prerequisites
- Wix Premium plan (required for custom code)
- Google Tag Manager account (free)
- GTM Container ID (format: GTM-XXXXXXX)
Installation Method 1: Custom Code (Recommended)
This is the standard GTM installation for Wix.
Step 1: Create GTM Container
- Go to Google Tag Manager
- Create a new container or select existing
- Copy your Container ID (GTM-XXXXXXX)
Step 2: Add GTM to Wix Header
- Wix Dashboard → Settings → Custom Code
- Click + Add Custom Code
- Name: "Google Tag Manager - Head"
- Paste the following code:
<!-- 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 -->
Configure:
- Load code on: All pages
- Place code in: Head
- Load code once: ✅ Checked
Click Apply
Step 3: Add GTM to Wix Body (Optional but Recommended)
GTM recommends a <noscript> fallback in the <body>. However, Wix does not support body code injection in the Custom Code interface.
Workaround:
Add this to a site-wide footer code area or embed in a custom element:
<!-- 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) -->
Note: This is less critical for Wix since JavaScript is generally required for Wix sites to function.
Step 4: Publish Your Wix Site
GTM will not load until you publish changes.
Step 5: Verify Installation
Visit your live Wix site
Open GTM Preview Mode:
- In GTM, click Preview
- Enter your Wix site URL
- Click Connect
Verify GTM loads:
- You should see "Connected" in GTM debugger
- Check Tag Assistant tab for firing tags
Installation Method 2: Marketing Integrations (Limited)
Wix occasionally offers GTM through Marketing Integrations, but availability varies.
Check: Dashboard → Marketing & SEO → Marketing Integrations
If available, follow on-screen instructions. However, this method provides less flexibility than custom code installation.
Wix-Specific GTM Configuration
Handling Wix's SPA Navigation
Wix uses AJAX for smooth page transitions, which means:
- Traditional pageviews may not fire on navigation
- GTM's default triggers may miss route changes
Solution: Implement history change detection.
Step 1: Create Custom HTML Tag in GTM
Tag name: "History Change Listener"
Tag type: Custom HTML
Code:
<script>
(function() {
// Store original pushState and replaceState
var originalPushState = history.pushState;
var originalReplaceState = history.replaceState;
// Override pushState
history.pushState = function() {
originalPushState.apply(history, arguments);
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'event': 'wix.page.navigation'
});
};
// Override replaceState
history.replaceState = function() {
originalReplaceState.apply(history, arguments);
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'event': 'wix.page.navigation'
});
};
// Also listen for popstate (back/forward buttons)
window.addEventListener('popstate', function() {
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'event': 'wix.page.navigation'
});
});
})();
</script>
Trigger: All Pages (Page View)
Step 2: Create Custom Event Trigger
Trigger name: "Wix Page Navigation"
Trigger type: Custom Event
Event name: wix.page.navigation
This trigger fires on: All Custom Events
Step 3: Configure GA4 Tag for Virtual Pageviews
If using GA4 through GTM:
Tag name: "GA4 - Virtual Pageview"
Tag type: GA4 Event
Configuration Tag: Your GA4 Configuration tag
Event Name: page_view
Trigger: Wix Page Navigation (created above)
Important: Set your main GA4 config tag to trigger ONLY on Page View (not on All Pages), or you'll get duplicate pageviews.
Setting Up Variables for Wix
Create these User-Defined Variables in GTM for easier tracking:
Page Path Variable
Variable name: "Page Path - Clean"
Variable type: JavaScript Variable
Code:
function() {
return window.location.pathname;
}
Page Title Variable
Variable name: "Page Title"
Variable type: JavaScript Variable
Code:
function() {
return document.title;
}
Site Language Variable
Variable name: "Site Language"
Variable type: JavaScript Variable
Code:
function() {
return document.documentElement.lang || 'en';
}
Consent Mode Configuration
For GDPR compliance, configure Google Consent Mode:
Step 1: Create Consent Initialization Tag
Tag name: "Consent Mode - Default State"
Tag type: Custom HTML
Code:
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('consent', 'default', {
'analytics_storage': 'denied',
'ad_storage': 'denied',
'ad_user_data': 'denied',
'ad_personalization': 'denied',
'wait_for_update': 500
});
</script>
Trigger: Consent Initialization - All Pages
Tag firing priority: 100 (fires before other tags)
Step 2: Create Consent Update Tag
Tag name: "Consent Mode - Update on Accept"
Tag type: Custom HTML
Code:
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('consent', 'update', {
'analytics_storage': 'granted',
'ad_storage': 'granted',
'ad_user_data': 'granted',
'ad_personalization': 'granted'
});
</script>
Trigger: Custom Event - consent.granted
Fire this trigger when user accepts cookies (see GTM Data Layer guide).
Common Tags to Deploy via GTM
1. Google Analytics 4
Tag type: Google Analytics: GA4 Configuration
Measurement ID: G-XXXXXXXXXX
Configuration:
- Send
page_viewevent: ✅ (if not handling with custom trigger) - Configure tag settings as needed
Trigger:
- Page View (for initial pageview)
- Wix Page Navigation (for virtual pageviews)
2. Meta Pixel (Facebook Pixel)
Tag type: Custom HTML
Code:
<script>
!function(f,b,e,v,n,t,s)
{if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};
if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];
s.parentNode.insertBefore(t,s)}(window, document,'script',
'https://connect.facebook.net/en_US/fbevents.js');
fbq('init', 'YOUR_PIXEL_ID');
fbq('track', 'PageView');
</script>
Trigger: All Pages + Wix Page Navigation
3. Google Ads Conversion Tracking
Tag type: Google Ads Conversion Tracking
Conversion ID: AW-XXXXXXXXXX
Conversion Label: Your conversion label
Trigger: Custom event (e.g., form submission, purchase)
Debugging GTM on Wix
Use GTM Preview Mode
- In GTM, click Preview
- Enter your Wix site URL
- Click Connect
- New tab opens with debugger attached
- Navigate your site and check which tags fire
Common Debug Checks
- Tags firing on pageview: Check Summary tab
- Variables populating correctly: Check Variables tab
- Triggers activating: Check Triggers tab
- Data layer events: Check Data Layer tab
Browser Console Debugging
Check data layer manually:
console.log(window.dataLayer);
Manually push test events:
dataLayer.push({
'event': 'test_event',
'customParam': 'test value'
});
Testing Before Publishing GTM Changes
1. Preview Mode (Required)
Always test in Preview mode before publishing GTM changes.
2. QA Checklist
- GTM container loads on all pages
- Page views track correctly (including SPA navigation)
- Custom events fire as expected
- Variables populate with correct data
- No JavaScript errors in console
- No duplicate tracking (check network tab)
- Tags respect consent mode
- Mobile testing (responsive behavior)
3. Publish with Version Notes
When publishing:
- Add descriptive version name: "Added GA4 ecommerce tracking"
- Add version description: List all changes
- This creates version history for rollbacks
Common Wix + GTM Issues
| Issue | Cause | Solution |
|---|---|---|
| GTM not loading | Custom code not published | Publish Wix site after adding GTM code |
| Duplicate pageviews | Multiple pageview tags | Use ONLY Page View OR custom SPA trigger, not both |
| Tags not firing on navigation | SPA not detected | Implement history change listener (see above) |
Variables return undefined |
Timing issue - DOM not ready | Use GTM's built-in variables or add delay |
| Preview mode won't connect | Browser blocking cookies | Disable ad blockers, use incognito mode |
| Tags fire twice | GTM installed multiple times | Check Custom Code and Marketing Integrations |
Performance Considerations
Minimize Tag Load Impact
- Use async tags when possible
- Consolidate tags through GTM instead of multiple direct implementations
- Set firing priorities for tags that must load in order
- Monitor Core Web Vitals after adding tags (see LCP troubleshooting)
Wix Turbo Compatibility
GTM works with Wix Turbo (Wix's performance optimization). However:
- Test thoroughly after enabling Turbo
- Verify all tags still fire correctly
- Check for timing issues with custom HTML tags
GTM Workspace Best Practices
- Use separate workspaces for major changes
- Name tags clearly: "GA4 - Pageview", "Meta Pixel - Add to Cart"
- Document triggers: Add notes explaining custom triggers
- Test before publishing: Always use Preview mode
- Regular container exports: Backup your GTM config
- Limit container access: Only give access to trained team members
Wix Plan Requirements
| Feature | Wix Plan Required |
|---|---|
| Custom Code (for GTM) | Premium plans or higher |
| Full GTM functionality | Any premium plan |
| Velo (for data layer) | Premium + Velo enabled |
| Wix Studio (advanced) | Wix Studio plan |