Google Analytics 4 E-commerce Setup Guide: Complete Tutorial (2025)
Published: June 25, 2025 | 18 min read | Updated for Enhanced E-commerce and Google Tag Manager
Google Analytics 4 (GA4) e-commerce tracking is essential for understanding your customer journey and optimizing your online store. Yet 67% of e-commerce stores have incomplete or broken GA4 setup, missing crucial revenue attribution and customer insights.
This comprehensive guide shows you exactly how to set up GA4 e-commerce tracking properly, from basic installation to advanced enhanced e-commerce configuration with Google Tag Manager.
What you'll master in this guide:
- Complete GA4 e-commerce setup with enhanced tracking
- Google Tag Manager integration for professional management
- Advanced attribution modeling and customer journey analysis
- Custom events for deeper insights into user behavior
- Troubleshooting common GA4 e-commerce issues
Who this guide serves:
- E-commerce store owners wanting complete analytics visibility
- Digital marketers managing multiple online stores
- Business analysts needing accurate conversion data
- Anyone frustrated with incomplete GA4 tracking
Expert validation: Our team at TagifyPro has configured GA4 for 500+ e-commerce stores, tracking over $50M in revenue. This guide contains our proven methodology for enterprise-level accuracy.
Table of Contents
- What is GA4 E-commerce Tracking?
- GA4 vs Universal Analytics: Key Differences
- Prerequisites and Account Setup
- Basic GA4 E-commerce Setup
- Enhanced E-commerce Configuration
- Google Tag Manager Implementation
- E-commerce Events Setup
- Custom Dimensions and Metrics
- Attribution Modeling Configuration
- Testing and Validation
- Platform-Specific Implementation
- Advanced Reporting Setup
- Common Issues and Troubleshooting
- FAQ
What is GA4 E-commerce Tracking? {#what-is-ga4-ecommerce}
Google Analytics 4 e-commerce tracking is a comprehensive system that monitors customer interactions throughout their entire shopping journey, from first website visit to post-purchase behavior.
Core GA4 E-commerce Capabilities
Revenue Tracking: Monitor total sales, average order value, and transaction details Product Performance: Analyze which products drive the most revenue and engagement Customer Journey: Track the complete path from discovery to purchase Attribution Analysis: Understand which marketing channels drive conversions Audience Insights: Build segments based on purchase behavior and lifetime value
GA4 E-commerce Event Framework
GA4 uses an event-based tracking model with these essential e-commerce events:
- view_item: Product page views
- add_to_cart: Items added to shopping cart
- begin_checkout: Checkout process initiated
- purchase: Completed transactions
- add_payment_info: Payment information added
- add_shipping_info: Shipping information provided
Why GA4 E-commerce Tracking Matters
Business Impact from Our Clients:
Case Study: TechGadgets Store
- Before GA4: Only tracking basic page views and goals
- After Enhanced Setup: Discovered 35% of revenue came from mobile users aged 25-34
- Result: Shifted ad spend, increased mobile conversion rate by 28%
Case Study: FashionHub
- Before: Couldn't identify profitable product categories
- After: Detailed product performance tracking revealed handbags generated 40% higher margin
- Result: Optimized inventory and increased profit margin by 22%
GA4 vs Universal Analytics: Key Differences {#ga4-vs-ua}
Understanding these differences is crucial for proper GA4 e-commerce implementation.
Tracking Model Changes
| Universal Analytics | Google Analytics 4 | |------------------------|-------------------------| | Session-based tracking | Event-based tracking | | Page views as primary metric | Events as primary metric | | Limited cross-device tracking | Advanced cross-device tracking | | Third-party cookie dependent | First-party data focused | | Manual goal configuration | Automatic conversion detection |
E-commerce Specific Changes
Enhanced Measurement: GA4 automatically tracks many interactions without additional code Improved Attribution: Multi-touch attribution models available out-of-the-box Better Customer Lifetime Value: Built-in LTV calculations and predictions Advanced Audiences: AI-powered audience creation based on behavior patterns Privacy-First: Designed for cookieless future with consent mode integration
Data Collection Differences
Universal Analytics E-commerce:
ga('ec:addProduct', {
'id': 'SKU123',
'name': 'Product Name',
'category': 'Category',
'quantity': 1,
'price': 29.99
});
GA4 E-commerce:
gtag('event', 'purchase', {
'transaction_id': 'T12345',
'value': 29.99,
'currency': 'USD',
'items': [{
'item_id': 'SKU123',
'item_name': 'Product Name',
'category': 'Category',
'quantity': 1,
'price': 29.99
}]
});
Key Improvement: GA4's structure is more flexible and provides richer product data for analysis.
Prerequisites and Account Setup {#prerequisites}
Before implementing GA4 e-commerce tracking, ensure you have the necessary access and tools.
Required Access and Accounts
- ✅ Google Analytics account with admin access
- ✅ Website admin access or developer support
- ✅ Google Tag Manager account (highly recommended)
- ✅ E-commerce platform admin access (Shopify, WooCommerce, etc.)
Recommended Tools and Extensions
- ✅ Google Analytics Debugger Chrome extension
- ✅ GA4 Debug View for real-time testing
- ✅ Google Tag Assistant for validation
- ✅ Enhanced E-commerce Data Layer Inspector
Initial GA4 Property Setup
-
Create GA4 Property
- Go to analytics.google.com
- Click "Admin" → "Create Property"
- Choose "GA4 Property"
- Enter your website details
-
Configure Basic Settings
- Set correct timezone and currency
- Enable enhanced measurement
- Configure data retention settings (14 months maximum)
-
Install Base Tracking Code
- Get your Measurement ID (starts with G-XXXXXXXX)
- Install via GTM or direct implementation
E-commerce Settings Configuration
-
Enable E-commerce
- Go to Admin → Events → Enhanced measurement
- Toggle "E-commerce" on
- Configure purchase conversion event
-
Currency Settings
- Admin → Property Settings → Currency
- Set your primary currency
- Configure multiple currencies if needed
-
Data Streams Setup
- Admin → Data Streams → Web
- Add your website URL
- Configure enhanced measurement options
Basic GA4 E-commerce Setup {#basic-setup}
Start with basic e-commerce tracking before moving to advanced configurations.
Method 1: Direct gtag.js Implementation
Add the GA4 tracking code to your website's header:
<!-- 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', {
// Enable e-commerce
send_page_view: true,
// Configure enhanced e-commerce
custom_parameter: 'value'
});
</script>
Method 2: Google Tag Manager (Recommended)
GTM provides better control and doesn't require code changes:
-
Install GTM Container
- Create GTM account and container
- Add GTM code to your website
- Configure GA4 Configuration tag
-
GA4 Configuration Tag Setup
Tag Type: Google Analytics: GA4 Configuration Measurement ID: G-XXXXXXXXXX Trigger: All Pages
-
Enhanced E-commerce Settings
- Enable "Send e-commerce events"
- Configure "Enhanced conversions" if needed
- Set up custom parameters
Basic E-commerce Event Implementation
Implement these essential events for basic e-commerce tracking:
Purchase Event (Most Critical)
// When purchase is completed
gtag('event', 'purchase', {
'transaction_id': 'T12345',
'value': 79.99,
'currency': 'USD',
'items': [{
'item_id': 'SKU123',
'item_name': 'Blue Running Shoes',
'category': 'Footwear',
'quantity': 1,
'price': 39.99
}, {
'item_id': 'SKU456',
'item_name': 'Athletic Socks',
'category': 'Accessories',
'quantity': 2,
'price': 19.99
}]
});
Add to Cart Event
// When user adds item to cart
gtag('event', 'add_to_cart', {
'currency': 'USD',
'value': 39.99,
'items': [{
'item_id': 'SKU123',
'item_name': 'Blue Running Shoes',
'category': 'Footwear',
'quantity': 1,
'price': 39.99
}]
});
View Item Event
// When user views product page
gtag('event', 'view_item', {
'currency': 'USD',
'value': 39.99,
'items': [{
'item_id': 'SKU123',
'item_name': 'Blue Running Shoes',
'category': 'Footwear',
'price': 39.99
}]
});
Enhanced E-commerce Configuration {#enhanced-ecommerce}
Enhanced e-commerce provides deeper insights into customer behavior and product performance.
Complete E-commerce Event Set
Implement all e-commerce events for comprehensive tracking:
1. View Item List (Category/Search Pages)
gtag('event', 'view_item_list', {
'item_list_id': 'category_footwear',
'item_list_name': 'Footwear',
'items': [{
'item_id': 'SKU123',
'item_name': 'Blue Running Shoes',
'category': 'Footwear',
'price': 39.99,
'index': 1
}, {
'item_id': 'SKU124',
'item_name': 'Red Running Shoes',
'category': 'Footwear',
'price': 44.99,
'index': 2
}]
});
2. Select Item (Product Clicks)
gtag('event', 'select_item', {
'item_list_id': 'category_footwear',
'item_list_name': 'Footwear',
'items': [{
'item_id': 'SKU123',
'item_name': 'Blue Running Shoes',
'category': 'Footwear',
'price': 39.99,
'index': 1
}]
});
3. Begin Checkout
gtag('event', 'begin_checkout', {
'currency': 'USD',
'value': 79.99,
'items': [{
'item_id': 'SKU123',
'item_name': 'Blue Running Shoes',
'category': 'Footwear',
'quantity': 1,
'price': 39.99
}, {
'item_id': 'SKU456',
'item_name': 'Athletic Socks',
'category': 'Accessories',
'quantity': 2,
'price': 19.99
}]
});
4. Add Shipping Info
gtag('event', 'add_shipping_info', {
'currency': 'USD',
'value': 79.99,
'shipping_tier': 'Express',
'items': [/* item array */]
});
5. Add Payment Info
gtag('event', 'add_payment_info', {
'currency': 'USD',
'value': 79.99,
'payment_type': 'Credit Card',
'items': [/* item array */]
});
Advanced Item Parameters
Include detailed product information for better analysis:
{
'item_id': 'SKU123',
'item_name': 'Blue Running Shoes',
'affiliation': 'Online Store',
'coupon': 'SUMMER10',
'currency': 'USD',
'discount': 4.00,
'index': 1,
'item_brand': 'Nike',
'item_category': 'Footwear',
'item_category2': 'Running',
'item_category3': 'Men',
'item_category4': 'Shoes',
'item_category5': 'Athletic',
'item_list_id': 'category_running',
'item_list_name': 'Running Shoes',
'item_variant': 'Blue',
'location_id': 'SKU123',
'price': 39.99,
'quantity': 1
}
Custom E-commerce Events
Create custom events for specific business needs:
Wishlist Addition
gtag('event', 'add_to_wishlist', {
'currency': 'USD',
'value': 39.99,
'items': [{
'item_id': 'SKU123',
'item_name': 'Blue Running Shoes',
'category': 'Footwear',
'price': 39.99
}]
});
Product Share
gtag('event', 'share', {
'method': 'Facebook',
'content_type': 'product',
'content_id': 'SKU123'
});
Refund Processing
gtag('event', 'refund', {
'transaction_id': 'T12345',
'value': 39.99,
'currency': 'USD',
'items': [{
'item_id': 'SKU123',
'quantity': 1,
'price': 39.99
}]
});
Google Tag Manager Implementation {#gtm-implementation}
GTM provides the most flexible and maintainable approach to GA4 e-commerce tracking.
GTM Container Setup for GA4 E-commerce
1. GA4 Configuration Tag
Tag Type: Google Analytics: GA4 Configuration
Tag Name: GA4 - Configuration
Measurement ID: G-XXXXXXXXXX
Configuration Settings:
☑ Send a page view event when this configuration loads
☑ Include Google signals in the configuration
Trigger: All Pages
2. Enhanced E-commerce Settings
In your GA4 Configuration tag:
Fields to Set:
- custom_map.user_id: {{User ID}}
- custom_map.customer_type: {{Customer Type}}
- linker.domains: ['yourdomain.com', 'subdomain.yourdomain.com']
Data Layer Implementation
Set up proper data layer structure for e-commerce events:
Product Page Data Layer
window.dataLayer = window.dataLayer || [];
dataLayer.push({
'event': 'view_item',
'ecommerce': {
'currency': 'USD',
'value': 39.99,
'items': [{
'item_id': 'SKU123',
'item_name': 'Blue Running Shoes',
'category': 'Footwear',
'price': 39.99,
'item_brand': 'Nike',
'item_variant': 'Blue'
}]
}
});
Purchase Confirmation Data Layer
dataLayer.push({
'event': 'purchase',
'ecommerce': {
'transaction_id': 'T12345',
'value': 79.99,
'currency': 'USD',
'tax': 6.40,
'shipping': 5.99,
'coupon': 'SUMMER10',
'items': [{
'item_id': 'SKU123',
'item_name': 'Blue Running Shoes',
'category': 'Footwear',
'quantity': 1,
'price': 39.99
}, {
'item_id': 'SKU456',
'item_name': 'Athletic Socks',
'category': 'Accessories',
'quantity': 2,
'price': 19.99
}]
}
});
GTM Variables Setup
Create these variables for dynamic e-commerce tracking:
Built-in Variables to Enable
- Page URL
- Page Title
- Referrer
- Container ID
- Random Number
Custom Variables
1. E-commerce Data - Items
Variable Type: Data Layer Variable
Data Layer Variable Name: ecommerce.items
2. E-commerce Data - Value
Variable Type: Data Layer Variable
Data Layer Variable Name: ecommerce.value
3. E-commerce Data - Currency
Variable Type: Data Layer Variable
Data Layer Variable Name: ecommerce.currency
4. Transaction ID
Variable Type: Data Layer Variable
Data Layer Variable Name: ecommerce.transaction_id
GTM Triggers Configuration
1. Purchase Trigger
Trigger Type: Custom Event
Event Name: purchase
Use regex matching: False
2. Add to Cart Trigger
Trigger Type: Custom Event
Event Name: add_to_cart
Use regex matching: False
3. Begin Checkout Trigger
Trigger Type: Custom Event
Event Name: begin_checkout
Use regex matching: False
GTM Tags for E-commerce Events
Purchase Event Tag
Tag Type: Google Analytics: GA4 Event
Configuration Tag: {{GA4 Configuration}}
Event Name: purchase
Event Parameters:
- transaction_id: {{Transaction ID}}
- value: {{Ecommerce Value}}
- currency: {{Ecommerce Currency}}
- items: {{Ecommerce Items}}
Trigger: Purchase Event
Add to Cart Event Tag
Tag Type: Google Analytics: GA4 Event
Configuration Tag: {{GA4 Configuration}}
Event Name: add_to_cart
Event Parameters:
- currency: {{Ecommerce Currency}}
- value: {{Ecommerce Value}}
- items: {{Ecommerce Items}}
Trigger: Add to Cart Event
Advanced GTM Configuration
Cross-Domain Tracking Setup
// In GA4 Configuration tag - Fields to Set
linker: {
domains: ['yourdomain.com', 'checkout.yourdomain.com']
}
User ID Configuration
// Data layer push with user ID
dataLayer.push({
'user_id': 'customer_12345',
'customer_type': 'returning',
'customer_ltv': 450.00
});
Custom Dimensions in GTM
Tag Type: Google Analytics: GA4 Configuration
Custom Definitions:
- customer_type: {{Customer Type}}
- user_id: {{User ID}}
- product_brand: {{Product Brand}}
E-commerce Events Setup {#ecommerce-events}
Comprehensive guide to implementing all GA4 e-commerce events for maximum insight.
Event Implementation Priority
Phase 1 (Essential):
- Purchase
- View_item
- Add_to_cart
- Begin_checkout
Phase 2 (Important): 5. View_item_list 6. Select_item 7. Add_payment_info 8. Add_shipping_info
Phase 3 (Advanced): 9. Remove_from_cart 10. Add_to_wishlist 11. View_promotion 12. Select_promotion
Detailed Event Implementation
1. Purchase Event (Critical)
When to fire: On order confirmation/thank you page
gtag('event', 'purchase', {
'transaction_id': 'T_12345_67890',
'value': 129.99,
'currency': 'USD',
'tax': 10.40,
'shipping': 8.99,
'coupon': 'WELCOME10',
'items': [{
'item_id': 'SKU_123',
'item_name': 'Wireless Bluetooth Headphones',
'affiliation': 'Online Store',
'coupon': 'WELCOME10',
'discount': 13.00,
'item_brand': 'AudioTech',
'item_category': 'Electronics',
'item_category2': 'Audio',
'item_category3': 'Headphones',
'item_variant': 'Black',
'price': 99.99,
'quantity': 1
}, {
'item_id': 'SKU_456',
'item_name': 'Headphone Case',
'affiliation': 'Online Store',
'item_brand': 'AudioTech',
'item_category': 'Electronics',
'item_category2': 'Accessories',
'item_variant': 'Black',
'price': 29.99,
'quantity': 1
}]
});
2. View Item (Product Pages)
When to fire: When user views product detail page
gtag('event', 'view_item', {
'currency': 'USD',
'value': 99.99,
'items': [{
'item_id': 'SKU_123',
'item_name': 'Wireless Bluetooth Headphones',
'item_brand': 'AudioTech',
'item_category': 'Electronics',
'item_category2': 'Audio',
'item_category3': 'Headphones',
'item_variant': 'Black',
'price': 99.99
}]
});
3. Add to Cart
When to fire: When user adds product to shopping cart
gtag('event', 'add_to_cart', {
'currency': 'USD',
'value': 99.99,
'items': [{
'item_id': 'SKU_123',
'item_name': 'Wireless Bluetooth Headphones',
'item_brand': 'AudioTech',
'item_category': 'Electronics',
'quantity': 1,
'price': 99.99
}]
});
4. Begin Checkout
When to fire: When user starts checkout process
gtag('event', 'begin_checkout', {
'currency': 'USD',
'value': 129.99,
'coupon': 'WELCOME10',
'items': [{
'item_id': 'SKU_123',
'item_name': 'Wireless Bluetooth Headphones',
'quantity': 1,
'price': 99.99
}, {
'item_id': 'SKU_456',
'item_name': 'Headphone Case',
'quantity': 1,
'price': 29.99
}]
});
5. View Item List (Category/Search Pages)
When to fire: On category pages, search results, or product listings
gtag('event', 'view_item_list', {
'item_list_id': 'category_electronics_audio',
'item_list_name': 'Electronics - Audio',
'items': [{
'item_id': 'SKU_123',
'item_name': 'Wireless Bluetooth Headphones',
'item_brand': 'AudioTech',
'item_category': 'Electronics',
'index': 1,
'price': 99.99
}, {
'item_id': 'SKU_789',
'item_name': 'Wired Gaming Headset',
'item_brand': 'GameTech',
'item_category': 'Electronics',
'index': 2,
'price': 79.99
}]
});
6. Select Item (Product Clicks from Lists)
When to fire: When user clicks product from category/search results
gtag('event', 'select_item', {
'item_list_id': 'category_electronics_audio',
'item_list_name': 'Electronics - Audio',
'items': [{
'item_id': 'SKU_123',
'item_name': 'Wireless Bluetooth Headphones',
'item_brand': 'AudioTech',
'item_category': 'Electronics',
'index': 1,
'price': 99.99
}]
});
Platform-Specific Event Firing
Shopify Implementation
For Shopify stores, use theme code or apps:
Theme.liquid modification:
{% if template contains 'product' %}
<script>
gtag('event', 'view_item', {
'currency': '{{ cart.currency.iso_code }}',
'value': {{ product.price | divided_by: 100.0 }},
'items': [{
'item_id': '{{ product.id }}',
'item_name': '{{ product.title | escape }}',
'item_category': '{{ product.type | escape }}',
'price': {{ product.price | divided_by: 100.0 }}
}]
});
</script>
{% endif %}
WooCommerce Implementation
Use hooks in functions.php or a plugin:
function track_woocommerce_purchase() {
if (is_order_received_page()) {
global $wp;
$order_id = absint($wp->query_vars['order-received']);
$order = wc_get_order($order_id);
if ($order) {
$items = array();
foreach ($order->get_items() as $item) {
$product = $item->get_product();
$items[] = array(
'item_id' => $product->get_id(),
'item_name' => $product->get_name(),
'category' => wp_get_post_terms($product->get_id(), 'product_cat', array('fields' => 'names'))[0],
'quantity' => $item->get_quantity(),
'price' => $product->get_price()
);
}
echo '<script>';
echo 'gtag("event", "purchase", {';
echo '"transaction_id": "' . $order->get_order_number() . '",';
echo '"value": ' . $order->get_total() . ',';
echo '"currency": "' . $order->get_currency() . '",';
echo '"items": ' . json_encode($items);
echo '});';
echo '</script>';
}
}
}
add_action('wp_footer', 'track_woocommerce_purchase');
Testing and Validation {#testing}
Thorough testing ensures your GA4 e-commerce tracking works correctly before launching campaigns.
GA4 Debug View Testing
-
Enable Debug Mode
gtag('config', 'G-XXXXXXXXXX', { debug_mode: true });
-
Access Debug View
- Go to GA4 → Configure → DebugView
- Perform actions on your website
- Watch events appear in real-time
-
Verify Event Parameters
- Check all required parameters are present
- Ensure item arrays are properly formatted
- Verify currency and value fields
Real-Time Reports Validation
-
Navigate to Real-time Reports
- GA4 → Reports → Real-time
- Monitor "Events by event name"
- Check "Conversions by event name"
-
Test E-commerce Events
- Perform complete purchase flow
- Verify each event fires correctly
- Check parameter values
E-commerce Reports Verification
-
Monetization Overview
- GA4 → Reports → Monetization → Overview
- Check revenue data appears
- Verify transaction counts
-
Item Revenue Report
- Monetization → E-commerce purchases → Item revenue
- Confirm product-level data
- Check item categories and brands
-
Purchase Journey Report
- Monetization → E-commerce purchases → Purchase journey
- Verify funnel data
- Check conversion rates
Testing Checklist
Page-Level Events:
- [ ] View_item fires on product pages with correct parameters
- [ ] View_item_list fires on category/search pages
- [ ] Select_item fires when clicking products from lists
Cart Events:
- [ ] Add_to_cart fires with correct item and value data
- [ ] Remove_from_cart fires when items removed
- [ ] View_cart fires on cart page
Checkout Events:
- [ ] Begin_checkout fires at checkout start
- [ ] Add_shipping_info fires when shipping selected
- [ ] Add_payment_info fires when payment method chosen
Purchase Events:
- [ ] Purchase fires on confirmation page
- [ ] Transaction ID is unique and correctly formatted
- [ ] Revenue amounts match order totals
- [ ] Item arrays include all purchased products
Data Quality Checks:
- [ ] No duplicate events firing
- [ ] Currency codes are consistent
- [ ] Item IDs match your product catalog
- [ ] Category hierarchies are logical
- [ ] Brand names are standardized
Advanced Testing with Google Analytics Debugger
-
Install GA Debugger Extension
- Chrome Web Store → Google Analytics Debugger
- Enable extension and refresh your site
-
Check Console Output
- Open browser console (F12)
- Look for GA tracking logs
- Verify hit construction
-
Validate Hit Data
- Check parameter formatting
- Ensure proper encoding
- Verify measurement protocol compliance
Platform-Specific Implementation {#platform-specific}
Detailed implementation guides for major e-commerce platforms.
Shopify GA4 E-commerce Setup
Method 1: Native Google Analytics Integration
-
Install Google & YouTube App
- Shopify Admin → Apps → App Store
- Search "Google & YouTube" (official app)
- Install and connect accounts
-
Configure GA4 Settings
- Open Google & YouTube app
- Go to Settings → Analytics
- Enter GA4 Measurement ID
- Enable enhanced e-commerce
-
Verify Automatic Tracking
- Purchase events: Automatic
- View_item events: Automatic
- Add_to_cart events: Automatic
- Enhanced data: Product IDs, categories, values
Method 2: Custom Implementation
Add to theme.liquid header:
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id={{ settings.ga4_measurement_id }}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '{{ settings.ga4_measurement_id }}');
</script>
Product page tracking (product.liquid):
<script>
gtag('event', 'view_item', {
'currency': '{{ cart.currency.iso_code }}',
'value': {{ product.price | divided_by: 100.0 }},
'items': [{
'item_id': '{{ product.id }}',
'item_name': '{{ product.title | escape }}',
'item_brand': '{{ product.vendor | escape }}',
'item_category': '{{ product.type | escape }}',
'price': {{ product.price | divided_by: 100.0 }}
}]
});
</script>
WooCommerce GA4 Setup
Method 1: Google Analytics for WooCommerce Plugin
-
Install Plugin
- WordPress Admin → Plugins → Add New
- Search "Google Analytics for WooCommerce"
- Install MonsterInsights or similar
-
Configure Settings
- Enter GA4 Measurement ID
- Enable enhanced e-commerce
- Configure tracking options
Method 2: Manual Implementation
Add to functions.php:
// Enqueue GA4 tracking
function add_ga4_tracking() {
if (!is_admin()) {
$measurement_id = 'G-XXXXXXXXXX';
?>
<script async src="https://www.googletagmanager.com/gtag/js?id=<?php echo $measurement_id; ?>"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '<?php echo $measurement_id; ?>');
</script>
<?php
}
}
add_action('wp_head', 'add_ga4_tracking');
// Track purchase events
function track_wc_purchase() {
if (is_wc_endpoint_url('order-received')) {
global $wp;
$order_id = absint($wp->query_vars['order-received']);
$order = wc_get_order($order_id);
if ($order && !$order->get_meta('_ga4_tracked')) {
$items = array();
foreach ($order->get_items() as $item) {
$product = $item->get_product();
$categories = get_the_terms($product->get_id(), 'product_cat');
$category = !empty($categories) ? $categories[0]->name : '';
$items[] = array(
'item_id' => $product->get_id(),
'item_name' => $product->get_name(),
'item_category' => $category,
'item_brand' => $product->get_attribute('brand'),
'quantity' => $item->get_quantity(),
'price' => $product->get_price()
);
}
?>
<script>
gtag('event', 'purchase', {
'transaction_id': '<?php echo $order->get_order_number(); ?>',
'value': <?php echo $order->get_total(); ?>,
'currency': '<?php echo $order->get_currency(); ?>',
'tax': <?php echo $order->get_total_tax(); ?>,
'shipping': <?php echo $order->get_shipping_total(); ?>,
'items': <?php echo json_encode($items); ?>
});
</script>
<?php
$order->update_meta_data('_ga4_tracked', true);
$order->save();
}
}
}
add_action('wp_footer', 'track_wc_purchase');
BigCommerce GA4 Setup
Method 1: App Installation
- BigCommerce App Store
- Search "Google Analytics"
- Install official Google Analytics app
- Configure with GA4 Measurement ID
Method 2: Script Manager
-
Add Tracking Scripts
- BigCommerce Admin → Storefront → Script Manager
- Create new script for GA4 base code
- Set location: "Header" and pages: "All pages"
-
Add E-commerce Tracking
- Create separate scripts for checkout events
- Use BigCommerce's checkout object for data
Magento 2 GA4 Implementation
Using Google Analytics Module
-
Install GA4 Extension
- Use Magento Marketplace
- Install via Composer:
composer require magento/module-google-analytics
-
Configure Settings
- Admin → Stores → Configuration → Sales → Google API
- Enter GA4 Measurement ID
- Enable enhanced e-commerce
Custom Implementation
Add to head.phtml:
<script async src="https://www.googletagmanager.com/gtag/js?id=<?= $measurementId ?>"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '<?= $measurementId ?>');
</script>
Common Issues and Troubleshooting {#troubleshooting}
Solutions for frequently encountered GA4 e-commerce tracking problems.
Issue 1: Purchase Events Not Firing
Symptoms:
- No revenue data in GA4 reports
- Purchase events missing from DebugView
- E-commerce reports show zero transactions
Common Causes & Solutions:
-
Tracking Code on Wrong Page
- Problem: Purchase code on checkout page instead of confirmation page
- Solution: Move tracking to order confirmation/thank you page
- Test: Complete a purchase and verify confirmation page URL
-
Incorrect Transaction ID Format
- Problem: Duplicate or missing transaction IDs
- Solution: Ensure unique IDs for each transaction
// Correct format 'transaction_id': 'ORDER_12345_' + Date.now()
-
Missing Required Parameters
- Problem: Events lack required currency or value parameters
- Solution: Always include currency and value for monetary events
// Minimum required gtag('event', 'purchase', { 'transaction_id': 'T12345', 'value': 79.99, 'currency': 'USD' });
Issue 2: Duplicate Events
Symptoms:
- Double-counted transactions in reports
- Events firing multiple times in DebugView
- Inflated conversion numbers
Solutions:
-
Remove Duplicate Implementations
- Check for multiple GA4 tags
- Ensure only one tracking method active
- Remove redundant platform integrations
-
Implement Event Deduplication
// Use session storage to prevent duplicates if (!sessionStorage.getItem('purchase_tracked_' + transactionId)) { gtag('event', 'purchase', purchaseData); sessionStorage.setItem('purchase_tracked_' + transactionId, 'true'); }
-
Check Page Reloads
- Prevent tracking on page refresh
- Use server-side tracking for critical events
- Implement proper redirect flow
Issue 3: Incorrect Revenue Values
Symptoms:
- Revenue doesn't match actual order totals
- Currency conversion issues
- Missing tax or shipping values
Solutions:
-
Verify Value Calculation
// Include all order components const orderTotal = subtotal + tax + shipping - discount; gtag('event', 'purchase', { 'value': orderTotal, // Total order value 'tax': tax, 'shipping': shipping, 'currency': 'USD' });
-
Check Currency Formatting
- Ensure consistent currency codes (USD, EUR, GBP)
- Use proper decimal formatting
- Don't include currency symbols in value field
-
Platform-Specific Fixes
- Shopify: Use
{{ order.total_price | divided_by: 100.0 }}
- WooCommerce: Use
$order->get_total()
- Custom: Ensure server-side calculation accuracy
- Shopify: Use
Issue 4: Missing Product Data
Symptoms:
- Items array empty or incomplete
- Product reports show "not set"
- Missing category or brand information
Solutions:
-
Complete Item Object Structure
'items': [{ 'item_id': 'SKU123', // Required 'item_name': 'Product Name', // Required 'item_category': 'Category', // Recommended 'item_brand': 'Brand', // Recommended 'price': 29.99, // Required for monetary events 'quantity': 1 // Required for cart events }]
-
Data Layer Validation
- Check data layer structure in browser console
- Ensure dynamic values populate correctly
- Test with static values first
-
Platform Data Mapping
- Verify product catalog integration
- Check category hierarchy mapping
- Ensure brand data is available
Issue 5: Events Not Appearing in Reports
Symptoms:
- DebugView shows events but reports don't
- Long delay in data processing
- Events marked as "not counted"
Solutions:
-
Check Event Configuration
- Verify events are marked as conversions
- Admin → Events → Mark as conversion
- Ensure proper event naming
-
Data Processing Time
- Standard events: 24-48 hours
- Custom events: Up to 24 hours
- Real-time data available in DebugView
-
Sampling and Thresholds
- Low-traffic sites may see sampling
- Ensure minimum event thresholds met
- Use unsampled reports for accurate data
Issue 6: Cross-Domain Tracking Problems
Symptoms:
- Users counted as new on checkout domain
- Broken conversion attribution
- Session discontinuity
Solutions:
-
Configure Linker
gtag('config', 'G-XXXXXXXXXX', { linker: { domains: ['example.com', 'checkout.example.com'] } });
-
Verify Domain Settings
- Check GA4 data stream configuration
- Ensure all domains listed
- Test cross-domain navigation
Diagnostic Tools
-
Google Analytics Debugger
- Chrome extension for hit validation
- Shows detailed tracking information
- Identifies parameter issues
-
GA4 DebugView
- Real-time event monitoring
- Parameter inspection
- Event validation
-
Browser Console
- Check for JavaScript errors
- Verify data layer structure
- Monitor gtag function calls
FAQ {#faq}
Q: How long does it take for GA4 e-commerce data to appear in reports?
A: Real-time data appears immediately in DebugView. Standard reports typically show data within 24-48 hours. E-commerce reports may take up to 72 hours to fully populate with all dimensions and metrics.
Q: What's the difference between GA4 and Universal Analytics e-commerce tracking?
A: GA4 uses an event-based model (vs. session-based), provides better cross-device tracking, includes automatic enhanced measurement, and offers more flexible attribution models. The data structure is also more product-centric with improved item-level tracking.
Q: Can I track both GA4 and Universal Analytics simultaneously?
A: Yes, but it's recommended to transition fully to GA4. Running both can cause confusion in reporting and may slow page load times. Universal Analytics stopped processing data on July 1, 2023.
Q: How do I handle refunds in GA4 e-commerce tracking?
A: Use the 'refund' event with the original transaction_id and items being refunded:
gtag('event', 'refund', {
'transaction_id': 'T12345',
'value': 29.99,
'currency': 'USD',
'items': [{
'item_id': 'SKU123',
'quantity': 1,
'price': 29.99
}]
});
Q: Should I use Google Tag Manager or direct gtag.js implementation?
A: Google Tag Manager is recommended for most businesses because it provides better control, easier maintenance, doesn't require code changes, and supports complex tracking scenarios. Direct implementation is only better for very simple setups.
Q: How accurate is GA4 e-commerce attribution?
A: GA4 attribution is generally more accurate than Universal Analytics due to improved cross-device tracking and machine learning. However, iOS privacy changes and ad blockers can still impact accuracy by 10-20%. Use multiple attribution models for comprehensive analysis.
Q: Can I import historical e-commerce data into GA4?
A: No, GA4 doesn't support importing historical data. You can only track new data from the implementation date forward. Keep Universal Analytics data for historical analysis and use GA4 for ongoing tracking.
Q: How do I track subscription or recurring payments in GA4?
A: Track the initial subscription as a 'purchase' event, then use custom events for renewals. You can also use the Measurement Protocol to send server-side events for recurring charges.
Q: What's the maximum number of items I can include in an e-commerce event?
A: GA4 supports up to 200 items per event. If you have more items in a single transaction, send multiple events or focus on the most important items for tracking.
Q: How do I track different currencies in GA4?
A: GA4 automatically converts currencies to your property's default currency using current exchange rates. Always specify the original currency in your events, and GA4 handles the conversion for reporting.
Conclusion
You now have a comprehensive understanding of GA4 e-commerce tracking implementation. Remember: Start with basic setup and gradually add advanced features as you become comfortable with the platform.
Your Implementation Roadmap:
Week 1:
- ✅ Set up basic GA4 property and tracking
- ✅ Implement purchase and view_item events
- ✅ Test basic e-commerce functionality
Week 2: 4. ✅ Add complete e-commerce event set 5. ✅ Configure Google Tag Manager (if not already) 6. ✅ Set up enhanced e-commerce parameters
Week 3: 7. ✅ Implement custom dimensions and metrics 8. ✅ Configure attribution models 9. ✅ Set up advanced reporting and audiences
Ongoing: 10. ✅ Monitor data quality and accuracy 11. ✅ Optimize based on customer journey insights 12. ✅ Expand tracking for new business needs
Key Success Factors:
- Test thoroughly before launching to avoid data gaps
- Use Google Tag Manager for flexibility and maintainability
- Implement gradually to ensure each component works correctly
- Monitor data quality regularly and fix issues promptly
- Train your team on GA4 reporting differences from Universal Analytics
Ready for professional implementation? TagifyPro automatically generates perfectly configured GA4 e-commerce setups for any platform. Get enterprise-level tracking accuracy in minutes with our proven configurations.
About the Author
This comprehensive guide was created by Sarah Rodriguez, Senior Analytics Specialist at TagifyPro. With 7+ years implementing analytics for e-commerce brands generating $100M+ in tracked revenue, Sarah specializes in GA4 migrations and advanced e-commerce measurement.
Sarah's expertise:
- Google Analytics Certified Professional (GA4)
- Google Tag Manager Certified Specialist
- 100+ successful GA4 e-commerce implementations
- Featured speaker at analytics conferences including Superweek and MeasureFest
Connect with Sarah: LinkedIn | Twitter
Related Resources:
- Facebook Pixel Setup Guide
- TikTok Pixel Installation Tutorial
- Google Tag Manager Complete Guide
- Cross-Platform Attribution Analysis
Last updated: June 25, 2025 | Next review: September 2025