Analytics & Tracking
Jitendra's Blog
COMPLETE DEVELOPER GUIDE 2026

GA4 & Tealium Implementation for Salesforce B2C Commerce

Master ecommerce analytics from beginner to expert with visual diagrams, code examples, and best practices for tracking customer journeys

In This Guide
12
In-Depth Sections
GA4 Feature
15+
Ecommerce Events
In This Guide
5
FAQs Answered
Tealium Feature
1300+
Integrations Available

1 Understanding GA4 & Tealium

What is Google Analytics 4 (GA4)?

Google Analytics 4 represents a fundamental shift in how web analytics works. According to Google's official GA4 documentation, the platform uses an event-based data model where every interaction is tracked as an event with parameters, replacing the session-based model of Universal Analytics.

Key characteristics of GA4 include:

What is Tealium?

Tealium is an enterprise-grade Customer Data Platform (CDP) and tag management solution. According to Tealium's official documentation, the platform consists of three main components:

Client-Side

Tealium iQ

Tag management for deploying marketing and analytics tags

GA4, Meta Pixel, Floodlight
Server-Side

EventStream

Server-side data collection and distribution platform

Measurement Protocol API
CDP

AudienceStream

Real-time CDP for identity resolution and audience segmentation

Personalization & targeting

How GA4 and Tealium Work Together

Tealium acts as the data orchestration layer between your Salesforce B2C Commerce storefront and GA4. This architecture provides flexibility, governance, and enhanced capabilities.

Data Flow: Browser → Tealium → GA4
Browser
Tealium
GA4
Collects user interactions
Transforms & routes data
Analytics & reporting
Data Collection utag.js collects user interactions via the data layer
Data Transformation Extensions transform raw data into GA4 format
Tag Delivery Tealium fires GA4 tags with formatted events
Server-Side Backup EventStream sends data via Measurement Protocol

2 Salesforce B2C Commerce Architecture Quick Reference

Understanding the B2C Commerce architecture is essential for implementing analytics correctly. For a comprehensive deep-dive into the platform's history, evolution, and architecture, see my detailed guide: Salesforce B2C Commerce Cloud Complete Guide.

Related Reading: The B2C Commerce Complete Guide covers SFRA architecture, cartridge system, headless commerce with PWA Kit, APIs (OCAPI/SCAPI), and Einstein AI capabilities in detail.

Key Architecture Points for Analytics

For GA4 and Tealium implementation, focus on these critical integration points:

SFRA Cartridge Override Priority (Left Wins)
Cartridges on the left override those on the right
HIGHEST PRIORITY
custom_cartridge
Your customizations
overrides
ANALYTICS
plugin_tealium
GA4 & Tealium integration
overrides
DO NOT MODIFY
app_storefront_base
Salesforce base (keep intact)
Integration Point Analytics Use Case
ISML Templates Render utag_data object with page/product context
Controller Extensions Add analytics data to ViewModels via module.superModule
Client-Side Scripts Track dynamic events (add-to-cart, wishlist, AJAX actions)
PWA Kit / Composable React components for data layer, virtual page views on route changes
Golden Rule: According to Salesforce's official SFRA customization guide, never modify app_storefront_base. The documentation states: "You can customize SFRA without editing the app_storefront_base cartridge" - use server.extend and server.append to preserve upgrade compatibility and easily adopt security updates.

3 Why Use Tealium with GA4?

While you can implement GA4 directly on your B2C Commerce storefront, using Tealium as an intermediary provides significant advantages for enterprise ecommerce operations.

Tag Management vs Direct Implementation

Aspect Direct GA4 Implementation Tealium + GA4
Developer Dependency Every change requires code deployment Marketing can deploy tags independently
Version Control Manual code versioning Built-in version control with rollback
Testing Requires staging environment Preview mode for real-time testing
Multi-Vendor Separate implementation per vendor Single data layer, multiple outputs
Consent Management Custom implementation needed Built-in consent orchestration
Server-Side Tracking Custom Measurement Protocol setup EventStream connectors available

Tealium-Specific Advantages

Enterprise-Grade Governance

Superior compliance management for GDPR, CCPA, and other privacy regulations

Vendor Agnostic Platform

Works equally well with Adobe, Google, Meta, Salesforce ecosystems - not tied to any vendor

Real-Time CDP Capabilities

AudienceStream provides identity resolution and audience activation across channels

Server-Side Capability

EventStream reduces client-side load and improves data accuracy by bypassing ad blockers

Pro Tip: According to Tealium's feature documentation, the platform offers 1,300+ turnkey integrations, making it easy to add new marketing vendors without code changes.

4 Implementation Approaches

There are multiple ways to implement Tealium with GA4 on Salesforce B2C Commerce. The best approach depends on your storefront architecture and customization requirements.

Approach 1: Tealium Cartridge for SFRA

The official Tealium integration for Salesforce Commerce Cloud provides a pre-built cartridge that handles most common scenarios.

Installation Steps

1
Download Cartridge Get the cartridge from Salesforce XChange (not the GitHub reference repo)
2
Update Cartridge Path Add int_tealium to cartridge path before app_storefront_base
3
Configure Business Manager Set account, profile, and environment in Site Preferences
4
Include Template Add tealium.isml include in your page.isml template

Cartridge Structure

plugin_tealium/
├── cartridge/
│   ├── scripts/
│   │   └── datalayer.js        # Data layer configuration
│   └── templates/
│       └── default/
│           └── common/
│               ├── tealium.isml
│               └── datalayer.isml

Approach 2: Custom Plugin Cartridge

For more control, create a custom plugin_tealium cartridge that extends the base functionality.

// plugin_tealium/cartridge/scripts/datalayer.js
var CONTEXT = {
    GLOBAL: 'global',
    PLP: 'plp',
    PDP: 'pdp',
    CART: 'cart',
    CHECKOUT: 'checkout',
    ORDER_CONFIRMATION: 'orderconfirmation'
};

function getDataLayer(context, data) {
    var dataLayer = getGlobalData();

    switch(context) {
        case CONTEXT.PDP:
            dataLayer = Object.assign(dataLayer, getProductData(data));
            break;
        case CONTEXT.CART:
            dataLayer = Object.assign(dataLayer, getCartData(data));
            break;
        case CONTEXT.ORDER_CONFIRMATION:
            dataLayer = Object.assign(dataLayer, getOrderData(data));
            break;
    }

    return dataLayer;
}

function getGlobalData() {
    return {
        page_type: '',
        site_currency: session.currency.currencyCode,
        customer_logged_in: customer.authenticated ? '1' : '0',
        customer_id: customer.authenticated ? customer.ID : ''
    };
}

module.exports = {
    CONTEXT: CONTEXT,
    getDataLayer: getDataLayer
};

Approach 3: ISML Template Integration

The data layer is rendered in ISML templates. Here's a typical implementation for the product detail page:

<!-- templates/default/product/productDetails.isml -->
<script>
var utag_data = {
    page_type: "product",
    page_name: "${pdict.product.productName}",
    product_id: ["${pdict.product.id}"],
    product_name: ["${pdict.product.productName}"],
    product_brand: ["${pdict.product.brand}"],
    product_category: ["${pdict.product.primaryCategory.displayName}"],
    product_price: ["${pdict.product.price.sales.value}"],
    product_sku: ["${pdict.product.id}"],
    site_currency: "${session.currency.currencyCode}"
};
</script>
Security Note: Always escape user-generated content in the data layer to prevent XSS vulnerabilities. Use ISML's built-in encoding functions like StringUtils.encodeJavascript().

5 Data Layer Structure

The data layer is the foundation of your analytics implementation. According to Tealium's data layer best practices, using a well-structured Universal Data Object (UDO) ensures consistent data across all vendors.

Tealium Universal Data Object (UDO)

The utag_data object should contain all relevant information for the current page context:

// Base utag_data structure for ecommerce
var utag_data = {
    // Page-level data
    page_type: "product",
    page_name: "Product Detail Page",
    site_section: "products",
    site_currency: "USD",

    // User data
    customer_logged_in: "1",
    customer_id: "12345",
    customer_type: "returning",
    customer_email_hash: "a1b2c3d4...",

    // Product data (arrays for multiple products)
    product_id: ["SKU123"],
    product_name: ["Blue T-Shirt"],
    product_category: ["Apparel/Shirts/T-Shirts"],
    product_brand: ["BrandName"],
    product_price: ["29.99"],
    product_quantity: ["1"],
    product_variant: ["Large/Blue"],

    // Transaction data (for purchase events)
    order_id: "ORD-12345",
    order_total: "89.99",
    order_subtotal: "79.99",
    order_tax: "5.00",
    order_shipping: "5.00",
    order_discount: "0.00",
    order_coupon: ""
};

GA4 Ecommerce Event Structure

GA4 expects ecommerce data in a specific format. According to Google's ecommerce documentation, the items array is central to all ecommerce events:

// GA4 purchase event structure
dataLayer.push({
    event: "purchase",
    ecommerce: {
        transaction_id: "T_12345",
        value: 89.99,
        tax: 5.00,
        shipping: 5.00,
        currency: "USD",
        coupon: "SUMMER20",
        items: [{
            item_id: "SKU123",
            item_name: "Blue T-Shirt",
            item_brand: "BrandName",
            item_category: "Apparel",
            item_category2: "Shirts",
            item_category3: "T-Shirts",
            item_variant: "Large/Blue",
            price: 29.99,
            quantity: 1,
            coupon: "",
            discount: 0,
            index: 0,
            item_list_id: "related_products",
            item_list_name: "Related Products"
        }]
    }
});

Required Events by Page Type

Based on GA4's recommended events reference, here are the required events for each page type:

Page Type GA4 Events Required Parameters
Product Listing (PLP) view_item_list, select_item items array with item_list_id
Product Detail (PDP) view_item items array (item_id OR item_name required)
Cart add_to_cart, remove_from_cart, view_cart items array with quantity
Checkout begin_checkout, add_shipping_info, add_payment_info items array, value, currency
Order Confirmation purchase transaction_id, value, currency, items
Promotions view_promotion, select_promotion promotion_id, promotion_name
Best Practice: Use arrays for all product-related fields (product_id, product_name, etc.) even for single products. This ensures consistency across pages with multiple products like cart and order confirmation.

6 Tealium iQ Tag Manager Setup

Configuring Tealium iQ properly is essential for accurate GA4 tracking. According to Tealium's GA4 tag documentation, here's how to set up the integration.

GA4 Tag Configuration

1
Add GA4 Tag Tags → Add Tag → Search "Google Analytics 4"
2
Configure Measurement ID Enter G-XXXXXXXXXX from GA4 Admin → Data Streams
3
Set Global Object Keep default "gtag" unless you have conflicts
4
Configure Page View Toggle based on implementation needs

Load Rules Configuration

Load rules determine when tags fire. According to Tealium's load rules documentation, use these patterns:

// Example load rules
- Load on All Pages: page_type EXISTS
- Product Pages Only: page_type EQUALS "product"
- Checkout Pages: page_type CONTAINS "checkout"
- Exclude Internal Traffic: user_ip NOT IN ["192.168.1.1", "10.0.0.1"]
- Consent Granted: consent_analytics EQUALS "granted"

Key Extensions

According to Tealium's extensions documentation, extensions process data before tags fire:

Extension Purpose Scope
E-Commerce Extension Maps standard ecommerce variables (_corder, _csubtotal) Before Load Rules
Set Data Values Transform or create variables without code Before Load Rules
JavaScript Code Custom logic using the 'b' object Tag Scope
Google Consent Mode Handle consent signals for Google services Pre Loader

Extension Execution Order

Understanding the execution order is critical for proper data transformation:

utag.sync
Before anything else
Pre Loader
Before data layer processing
Before Load Rules
Affects all tags
Tag Scope
Specific to individual tags

Data Sources in Tealium

Tealium can pull data from multiple sources:

7 GA4 Event Mapping

Mapping your data layer events to GA4's expected format is critical for accurate ecommerce reporting. According to Google's official GA4 ecommerce documentation, these are the recommended events for tracking the customer journey.

Tealium Event Trigger Mapping

The tealium_event variable triggers specific GA4 events. Based on Tealium's GA4 tag documentation, here's how to map common ecommerce actions:

Product Listing view_item_list
Product Click select_item
Product Detail view_item
Add to Cart add_to_cart
View Cart view_cart
Begin Checkout begin_checkout
Shipping Info add_shipping_info
Payment Info add_payment_info
Purchase Complete purchase

Triggering Events in Code

Use utag.link() to fire events dynamically (e.g., add to cart button click):

// Add to Cart button click handler
document.querySelector('.add-to-cart').addEventListener('click', function() {
    utag.link({
        tealium_event: "add_to_cart",
        product_id: ["SKU123"],
        product_name: ["Blue T-Shirt"],
        product_price: ["29.99"],
        product_quantity: ["1"],
        product_category: ["Apparel/Shirts"],
        product_brand: ["BrandName"]
    });
});

// Remove from Cart
function removeFromCart(productId) {
    utag.link({
        tealium_event: "remove_from_cart",
        product_id: [productId],
        product_quantity: ["1"]
    });
}

Items Array Transformation

According to GA4's event reference, all ecommerce events require an items array. Tealium's E-Commerce Extension automatically transforms your data layer arrays into GA4's items format:

Data Transformation: Tealium → GA4
Tealium UDO
E-Commerce Ext
GA4 Parameter
GA4 Items
product_id[]
_cprod_id[]
item_id
items[].item_id
product_name[]
_cprod_name[]
item_name
items[].item_name
product_price[]
_cprod_price[]
price
items[].price
product_quantity[]
_cprod_quantity[]
quantity
items[].quantity
Pro Tip: Enable the E-Commerce Extension in Tealium iQ to automatically map standard ecommerce variables. This reduces manual mapping work and ensures consistency.

8 Server-Side Tracking with EventStream

Server-side tracking via Tealium EventStream improves data accuracy by bypassing client-side limitations like ad blockers and browser restrictions.

Why Server-Side Tracking?

According to Tealium's EventStream documentation, server-side tracking offers several advantages:

GA4 Measurement Protocol Setup

According to Tealium's GA4 Measurement Protocol connector documentation, configure these settings:

1
Generate API Secret GA4 Admin → Data Streams → Measurement Protocol API secrets
2
Configure Connector Add GA4 Measurement Protocol connector with credentials
3
Map Client ID Extract client_id from the _ga cookie value
4
Event Mapping Map tealium_event to GA4 event names

Measurement Protocol Endpoints

# Production endpoint
POST https://www.google-analytics.com/mp/collect?api_secret=XXX&measurement_id=G-XXX

# Validation/Debug endpoint (returns validation messages)
POST https://www.google-analytics.com/debug/mp/collect?api_secret=XXX&measurement_id=G-XXX

Hybrid Implementation (Recommended)

The best approach combines client-side and server-side tracking:

Hybrid Tracking Architecture
Client-Side Tracking
Browser-based via Tealium iQ
Real-time
Page Views
User Sessions
Scroll Tracking
Click Events
Server-Side Tracking
EventStream via Measurement Protocol
Reliable
Purchase Events
Conversion Tracking
Offline Events
Refunds
Both feed into
Google Analytics 4
Unified analytics & reporting
Important Limitation: According to Google's Measurement Protocol reference, server-side tracking alone cannot generate session_start or first_visit events, and cannot provide automatic session/user data. Always maintain client-side tracking for complete analytics.

9 Consent Management

Privacy regulations like GDPR and CCPA require proper consent management before tracking users. Tealium provides built-in tools to handle consent orchestration across all your tags.

Google Consent Mode v2

As of March 2024, Google requires Consent Mode v2 for compliance with EU regulations. According to Tealium's Google Consent Mode documentation, these signals must be implemented:

Consent Signal Purpose Default State
ad_storage Cookie storage for advertising denied
analytics_storage Cookie storage for analytics denied
ad_user_data User data sent to Google for advertising denied
ad_personalization Personalized advertising denied

Implementation Options

Basic Mode

Block all tags until consent is granted. Simple but may lose GA4's data modeling capabilities for non-consented users.

Tealium Consent Manager Setup

According to Tealium's consent management documentation, configure consent in Tealium iQ:

// Default consent state (before user interaction)
gtag('consent', 'default', {
    ad_storage: 'denied',
    analytics_storage: 'denied',
    ad_user_data: 'denied',
    ad_personalization: 'denied',
    wait_for_update: 500  // Wait 500ms for consent update
});

// Update consent when user accepts
function updateConsent(analyticsConsent, adsConsent) {
    gtag('consent', 'update', {
        ad_storage: adsConsent ? 'granted' : 'denied',
        analytics_storage: analyticsConsent ? 'granted' : 'denied',
        ad_user_data: adsConsent ? 'granted' : 'denied',
        ad_personalization: adsConsent ? 'granted' : 'denied'
    });
}

Compliance by Regulation

Regulation Requirement Implementation
GDPR (EU) Explicit opt-in consent required Basic or Advanced consent mode, block until granted
CCPA (California) Right to opt-out, honor GPC signal Opt-out mechanism, check navigator.globalPrivacyControl
DMA (EU) Transparency, fair practices Consent Mode v2 mandatory for EU users
Important: Google Consent Mode does NOT make your site GDPR-compliant on its own. You still need a full Consent Management Platform (CMP) implementation with proper cookie banners and privacy policies.

10 Debugging & Validation

Proper debugging ensures your implementation is accurate before going live. Use these tools to validate your GA4 and Tealium setup.

Client-Side Debugging Tools

1. GA4 DebugView

According to Google's DebugView documentation, this real-time tool shows events as they arrive:

2. Chrome Extensions

Extension Purpose Best For
Tealium Tools Inspect utag_data, events, tag firing Tealium-specific debugging
Google Analytics Debugger Loads debug version of GA code Console logging
Omnibug Multi-vendor tag debugger Comparing multiple analytics
Tag Assistant Google's official validation tool GA4/GTM validation

3. Tealium Preview Mode

Test changes before publishing:

Enable Preview Click "Preview" in toolbar
Copy URL Add params to site URL
View Trace Open Tealium Tools

Server-Side Validation

Use the Measurement Protocol validation endpoint:

# Send test event to validation endpoint
curl -X POST 
  'https://www.google-analytics.com/debug/mp/collect?api_secret=YOUR_SECRET&measurement_id=G-XXXXX' 
  -H 'Content-Type: application/json' 
  -d '{
    "client_id": "123456.7890123456",
    "events": [{
      "name": "purchase",
      "params": {
        "transaction_id": "TEST-001",
        "value": 99.99,
        "currency": "USD"
      }
    }]
  }'

# Response shows validation messages without storing data

Debugging Workflow

Enable Debug
Add debug_mode or use extension
Perform Actions
Browse, add to cart, checkout
Verify in Tealium
Check Tealium Tools trace
Confirm in GA4
Validate in DebugView
Pro Tip: Create a debugging checklist for your QA team that covers each page type and user action. Include expected events and parameters to validate against.

11 Best Practices & Common Pitfalls

Following these best practices will help you avoid common implementation mistakes and ensure accurate analytics data.

Data Layer Best Practices

According to Tealium's official best practices:

Common GA4 Implementation Pitfalls

Pitfall Impact Solution
Missing transaction_id Purchase not recorded properly Always include unique transaction ID
Missing currency Revenue not calculated Set currency on all monetary events
Duplicate events Inflated metrics Use single tracking method, avoid double-tagging
Wrong event names Events not recognized by GA4 Use exact GA4 event names (case-sensitive)
Timing issues Missing data on fast interactions Fire tag after dataLayer is populated
No referral exclusions Broken attribution from payment gateways Exclude PayPal, Stripe, auth providers

SFRA-Specific Best Practices

Do:
  • Use module.superModule to chain functionality across cartridges
  • Create overlay cartridges rather than modifying base
  • Use server.append for middleware additions
  • Test cartridge path order (left-to-right precedence)
Don't:
  • Modify app_storefront_base directly
  • Hardcode values that should come from Business Manager
  • Skip input validation in data layer rendering
  • Deploy without testing in staging environment

Performance Optimization

According to Tealium iQ best practices:

12 Abbreviations & Glossary

Abbreviations & Glossary

Reference guide for technical terms and abbreviations used throughout this article.

API - Application Programming Interface
CCPA - California Consumer Privacy Act
CDP - Customer Data Platform
CMP - Consent Management Platform
DOM - Document Object Model
GA4 - Google Analytics 4
GDPR - General Data Protection Regulation
iQ - Tealium's Tag Management System
ISML - Internet Store Markup Language
MVC - Model-View-Controller
OCAPI - Open Commerce API
PDP - Product Detail Page
PLP - Product Listing Page
PWA - Progressive Web Application
SCAPI - Shopper Commerce API
SFCC - Salesforce Commerce Cloud
SFRA - Storefront Reference Architecture
TMS - Tag Management System
UDO - Universal Data Object
XSS - Cross-Site Scripting

? Frequently Asked Questions

GA4 uses an event-based data model where every interaction is tracked as an event with parameters, while Universal Analytics used a session-based model with pageviews and hits. GA4 offers cross-platform tracking, machine learning insights, and is designed for a cookieless future with better privacy controls.

Tealium provides vendor-agnostic tag management, allowing marketing teams to deploy tags without code deployments. It offers superior consent management for GDPR/CCPA compliance, server-side tracking capabilities via EventStream, and a single data layer that can feed multiple analytics vendors simultaneously.

The recommended structure uses Tealium's Universal Data Object (UDO) format with utag_data containing page-level data (page_type, site_currency), user data (customer_id, customer_logged_in), product arrays (product_id, product_name, product_price), and transaction data (order_id, order_total) for purchase events.

Configure Tealium EventStream with the GA4 Measurement Protocol connector. You'll need an API Secret from GA4 Admin, the Measurement ID, and the client_id extracted from the _ga cookie. Server-side tracking improves data accuracy by bypassing ad blockers but cannot replace client-side tracking entirely.

Required events include: view_item_list and select_item for product listings, view_item for product detail pages, add_to_cart and remove_from_cart for cart actions, begin_checkout/add_shipping_info/add_payment_info for checkout steps, and purchase for order confirmation. Each event requires an items array with product details.

Link copied to clipboard!
Previous Post
Salesforce Mobile Offline Complete Guide 2026 | Briefcase Builder, LWC Offline & Best Practices
Next Post
Claude Code Complete Guide 2026: From Basics to Advanced MCP, Agents & Git Workflows
Archives by Year
2026 7 2025 16 2024 2 2023 9 2022 8 2021 4 2020 18 2019 16 2018 21 2017 34 2016 44 2015 54 2014 30 2013 31 2012 46 2011 114 2010 162
Search Blog

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Jitendra Zaa

Subscribe now to keep reading and get access to the full archive.

Continue Reading