Technical reference for implementing Google Analytics 4 (GA4) on Wix sites, covering the native Wix Analytics app, custom code injection, Velo (formerly Corvid) event tracking, and Wix Stores ecommerce data layer behavior.
How GA4 Works on Wix
Wix is a closed-platform SPA (single-page application) that renders pages client-side. This architecture has specific implications for GA4:
- Native app integration: The Wix Analytics app (installed via the App Market) injects
gtag.jsinto the site header automatically. Wix manages the script lifecycle, including firing virtualpage_viewevents on SPA route transitions. The app stores your Measurement ID server-side and handles script injection at build time. - Custom code injection: On premium plans, you can add raw
<script>tags via Settings > Custom Code. Scripts are injected into the<head>at publish time. Custom code does NOT execute in the Wix Editor preview -- only on the published site. - Velo (developer mode): Wix Velo provides a JavaScript runtime that executes in a sandboxed environment. Velo code runs after page load and can interact with Wix APIs (
wix-stores,wix-members,wix-bookings) to construct GA4 events. However, Velo code cannot directly inject<script>tags into the DOM -- it relies on the gtag global already being present from the App Market integration or custom code.
Because Wix uses client-side routing, standard gtag('config', ...) calls only fire on initial page load. For subsequent navigations, you must listen to wixLocation.onChange() (in Velo) or rely on the native app, which handles SPA page views automatically. Wix Stores does not expose a window.dataLayer -- ecommerce events require manual construction via the Wix Stores API or the native app's built-in enhanced ecommerce.
Plan Requirements
- GA4 Integration: Available on all Wix plans
- Custom Code: Available on premium plans
- Ecommerce Tracking: Requires Wix Stores/Business & Ecommerce plan
- Advanced Features: Velo dev mode available on premium plans
Installation Methods
Method 1: Wix Analytics App (Recommended)
Use the official Wix app for easiest setup.
Step 1: Install Wix Analytics App
- Log in to your Wix dashboard
- Go to Settings > Integrations & Apps
- Search for "Google Analytics" in the Wix App Market
- Click Add to Site on the Google Analytics app
- Follow the installation prompts
Step 2: Connect Your GA4 Account
- Open the Google Analytics app in your dashboard
- Click Connect to Google Analytics
- Sign in to your Google account
- Grant permissions to Wix
- Select your GA4 property
- Click Connect
Step 3: Configure Settings
- Enable Page View Tracking
- For Wix Stores, enable Enhanced Ecommerce
- Configure event tracking options
- Click Save
Method 2: Manual Tracking Code Installation
For custom implementations or specific requirements.
Step 1: Get Your GA4 Measurement ID
- Sign in to Google Analytics
- Navigate to Admin > Data Streams
- Select your web data stream
- Copy your Measurement ID (G-XXXXXXXXXX)
Step 2: Add Tracking Code to Wix
- In Wix Editor, go to Settings > Custom Code
- Click + Add Custom Code
- Paste the following in the code box:
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXXXXX', {
'send_page_view': true,
'cookie_flags': 'SameSite=None;Secure'
});
</script>
- Name it "GA4 Tracking"
- Select All pages for placement
- Choose Head as load location
- Click Apply
Method 3: Wix Velo (For Developers)
Use Velo for advanced custom tracking.
Enable Velo Dev Mode
- Open Wix Editor
- Click Dev Mode in top menu
- Enable Velo development environment
- Access code files in the code panel
Add GA4 in Site Code
Create or edit masterPage.js:
import { session } from 'wix-storage';
$w.onReady(function () {
// Initialize GA4
if (typeof gtag !== 'undefined') {
gtag('config', 'G-XXXXXXXXXX', {
'page_path': $w('#currentPage').name
});
}
});
Ecommerce Tracking Configuration
Wix Stores Integration
Automatic ecommerce tracking for Wix Stores.
Enable Enhanced Ecommerce
- Install Google Analytics app from Wix App Market
- Go to app settings
- Enable Enhanced Ecommerce toggle
- Select events to track:
- Product views
- Add to cart
- Checkout initiation
- Purchases
- Save settings
Custom Ecommerce Events
Add custom tracking using Velo.
Track Product Views
Add to product page code:
import wixData from 'wix-data';
$w.onReady(function () {
// Get product data
$w('#productPage').getProduct().then(product => {
gtag('event', 'view_item', {
'currency': product.currency,
'value': product.price,
'items': [{
'item_id': product.sku,
'item_name': product.name,
'price': product.price
}]
});
});
});
Track Add to Cart
$w('#addToCartButton').onClick(() => {
$w('#productPage').getProduct().then(product => {
gtag('event', 'add_to_cart', {
'currency': product.currency,
'value': product.price,
'items': [{
'item_id': product.sku,
'item_name': product.name,
'price': product.price,
'quantity': 1
}]
});
});
});
Track Purchases
Add to thank you page:
import wixStoresBackend from 'wix-stores-backend';
import { currentMember } from 'wix-members';
$w.onReady(function () {
currentMember.getOrders().then(orders => {
const lastOrder = orders[0];
gtag('event', 'purchase', {
'transaction_id': lastOrder.number,
'value': lastOrder.totals.total,
'currency': lastOrder.currency,
'tax': lastOrder.totals.tax,
'shipping': lastOrder.totals.shipping,
'items': lastOrder.lineItems.map(item => ({
'item_id': item.sku,
'item_name': item.name,
'price': item.price,
'quantity': item.quantity
}))
});
});
});
Advanced Event Tracking
Form Submission Tracking
Track Wix Forms submissions:
$w('#contactForm').onWixFormSubmit((event) => {
gtag('event', 'form_submit', {
'form_name': 'Contact Form',
'form_id': event.formName
});
});
Button Click Tracking
Track button interactions:
$w('#ctaButton').onClick(() => {
gtag('event', 'cta_click', {
'button_text': $w('#ctaButton').label,
'page_name': $w('#currentPage').name
});
});
Member Login Tracking
Track member authentication:
import { authentication } from 'wix-members';
authentication.onLogin((user) => {
gtag('event', 'login', {
'method': 'Wix Members'
});
gtag('set', 'user_properties', {
'member_status': 'logged_in'
});
});
Scroll Tracking
Monitor page engagement:
let scrolled = false;
$w.onReady(function () {
$w(window).onScroll(() => {
const scrollPercentage = ($w(window).scrollY / ($w('Document').height - $w(window).viewportHeight)) * 100;
if (scrollPercentage > 75 && !scrolled) {
gtag('event', 'scroll', {
'percent_scrolled': 75,
'page_name': $w('#currentPage').name
});
scrolled = true;
}
});
});
Video Tracking
Track video interactions:
$w('#videoPlayer').onPlay(() => {
gtag('event', 'video_start', {
'video_title': $w('#videoPlayer').title
});
});
$w('#videoPlayer').onEnded(() => {
gtag('event', 'video_complete', {
'video_title': $w('#videoPlayer').title
});
});
Wix Bookings Tracking
Track Appointment Bookings
import wixBookings from 'wix-bookings';
wixBookings.onCheckout((event) => {
gtag('event', 'appointment_booked', {
'service_name': event.service.name,
'service_price': event.service.payment.price,
'appointment_date': event.booking.startTime
});
});
Wix Events Tracking
Track Event Registrations
import wixEvents from 'wix-events-backend';
$w('#registerButton').onClick(() => {
gtag('event', 'event_registration', {
'event_name': $w('#eventTitle').text,
'event_date': $w('#eventDate').text
});
});
Privacy and GDPR Compliance
Cookie Consent Integration
Implement consent management:
import { local } from 'wix-storage';
$w.onReady(function () {
// Check if consent given
const consent = local.getItem('cookie_consent');
if (consent === 'granted') {
gtag('consent', 'update', {
'analytics_storage': 'granted'
});
} else {
gtag('consent', 'default', {
'analytics_storage': 'denied'
});
}
});
// When user accepts cookies
export function acceptCookies() {
gtag('consent', 'update', {
'analytics_storage': 'granted'
});
local.setItem('cookie_consent', 'granted');
}
Troubleshooting
Tracking Not Working
Issue: No data in GA4 reports
Solutions:
- Verify Measurement ID is correct (starts with G-)
- Check if Wix Analytics app is properly connected
- Ensure custom code is set to load on all pages
- Publish site after making changes (tracking won't work in preview)
- Test in incognito mode to avoid ad blockers
- Check browser console for JavaScript errors
Duplicate Tracking
Issue: Events tracked multiple times
Solutions:
- Don't use both Wix Analytics app AND custom code
- Check for duplicate code in custom code sections
- Verify Velo code isn't duplicating tracking
- Remove redundant event handlers
- Check third-party apps for conflicts
Ecommerce Events Missing
Issue: Purchase events not appearing
Solutions:
- Verify Enhanced Ecommerce is enabled in app settings
- Ensure you're on Wix Business & Ecommerce plan
- Test with actual purchases (not preview mode)
- Check thank you page code is correct
- Verify GA4 property has ecommerce enabled
Custom Code Not Loading
Issue: Tracking code doesn't execute
Solutions:
- Verify you're on a premium Wix plan
- Check code is set to load in Head section
- Ensure code is applied to all pages
- Publish site (custom code doesn't work in preview)
- Check for JavaScript syntax errors
- Verify gtag.js script loads before custom events
Velo Code Errors
Issue: Velo tracking code not working
Solutions:
- Enable Dev Mode properly
- Check imports are correct
- Verify API permissions are granted
- Test code in Velo console
- Check for async/promise handling issues
- Review Wix API documentation for updates
App Connection Failed
Issue: Can't connect Google Analytics app
Solutions:
- Ensure you're logged into correct Google account
- Clear browser cache and cookies
- Try in incognito mode
- Verify Google account has GA4 property access
- Disconnect and reconnect app
- Contact Wix support if issue persists
Testing and Verification
Enable Debug Mode
Add to custom code:
<script>
gtag('config', 'G-XXXXXXXXXX', {
'debug_mode': true
});
</script>
Testing Checklist
- Publish Site: Always test on published site, not preview
- Page Views: Navigate between pages
- Ecommerce: Complete test purchase
- Forms: Submit test forms
- Custom Events: Trigger all tracked interactions
- Mobile: Test on mobile devices
Browser Console Testing
// Check if gtag exists
console.log(typeof gtag);
// View dataLayer
console.log(window.dataLayer);
// Fire test event
gtag('event', 'test_event', {'test': 'value'});
GA4 DebugView
- Enable debug mode
- Open GA4: Admin > DebugView
- Browse your Wix site
- Verify events appear in real-time
- Check event parameters
Velo Console Testing
For Velo implementations:
- Open Velo sidebar
- Go to Console tab
- Add console.log statements
- Test code execution
- Check for errors
Best Practices
Use Native App When Possible
For most users, the Wix Analytics app provides sufficient functionality without code.
Organize Velo Code
Keep tracking code organized in separate files:
/public
/analytics
ga4-config.js
ecommerce-tracking.js
event-tracking.js
Test Before Publishing
Always test thoroughly in Wix's preview before publishing changes.
Avoid Tracking in Preview
Prevent development activity from polluting analytics:
if (!$w('#page').preview) {
// Only track on live site
gtag('event', 'page_view');
}
Event Naming Consistency
Use clear, consistent event names:
// Good
gtag('event', 'product_click');
// Bad
gtag('event', 'click_prod');
Wix-Specific Considerations
Single Page Application Behavior
Wix uses SPA architecture, so implement virtual page views:
import wixLocation from 'wix-location';
wixLocation.onChange(() => {
gtag('config', 'G-XXXXXXXXXX', {
'page_path': wixLocation.path
});
});
Dynamic Content Loading
Account for Wix's dynamic content:
$w.onReady(function () {
// Wait for content to load
setTimeout(() => {
// Track after content loads
gtag('event', 'content_loaded');
}, 1000);
});