For modern e-commerce stores, having a basic Google Analytics 4 page view configuration is not enough. To run successful Performance Max, search, and social ad campaigns, you need precise transaction details, product-level analytics, and revenue metrics sent back to your analytics tags. B2B and e-commerce tracking requires implementing an **advanced GA4 ecommerce tracking setup** using structured Data Layers and Google Tag Manager (GTM).
Understanding the GA4 Data Layer Schema
GA4 relies on a specific object structure in the browser (the Data Layer) to capture e-commerce actions like product views, cart additions, checkout steps, and purchases. The Data Layer must be populated by your website backend (Shopify, WooCommerce, or custom code) before GTM tags fire.
Core E-commerce Event Flow
The standard user path requires tracking these events:
view_item_list: User views a product category catalog.select_item: User clicks on a product from the list.view_item: User views the product details page.add_to_cart: User adds the item to the cart.view_cart: User views the shopping cart.begin_checkout: User initiates checkout.purchase: User completes the order (thank-you page).
Step-by-Step Developer Implementation Guide
Step 1: Configure the Purchase Data Layer on the Thank-You Page
Ensure your server pushes this exact JSON schema to the Data Layer when a purchase is completed. Replace placeholder values with active order variables:
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
event: "purchase",
ecommerce: {
transaction_id: "T_12345",
value: 2500.00,
tax: 150.00,
shipping: 100.00,
currency: "INR",
coupon: "SUMMER_20",
items: [
{
item_id: "SKU_99",
item_name: "Premium Marketing Consulting Program",
affiliation: "Piyush Marketing Store",
coupon: "SUMMER_20",
discount: 500.00,
index: 0,
item_brand: "Piyush Marketing",
item_category: "Consulting",
price: 3000.00,
quantity: 1
}
]
}
});
Step 2: Set Up GTM Variables
- Log into Google Tag Manager, go to Variables, and click New under User-Defined Variables.
- Select **Data Layer Variable** as the type.
- Set the Data Layer Variable Name to
ecommerce.value(to capture total transaction value). Name the variable **dlv - ecommerce value**. - Repeat this setup for
ecommerce.items(variable name: **dlv - ecommerce items**) andecommerce.transaction_id(variable name: **dlv - ecommerce transaction_id**).
Step 3: Configure the GA4 Purchase Event Tag
- Go to Tags โ New in GTM. Select **Google Analytics: GA4 Event** as the tag type.
- Select your GA4 Configuration Tag. Set the Event Name to
purchase. - Under **More Settings**, check the **Send Ecommerce Data** box. Set the Data Source option to **Data Layer**. This instructs GTM to auto-map the items array to GA4 format.
- Set the trigger to fire on a custom event named
purchase. Save and publish.
Data Layer Parameter Mappings
| GA4 Parameter | Data Layer Key | GTM Variable Name | Purpose |
|---|---|---|---|
| transaction_id | ecommerce.transaction_id | dlv - ecommerce transaction_id | Deduplicates transactions in GA4 reports. |
| value | ecommerce.value | dlv - ecommerce value | Tracks total purchase value (revenue). |
| items | ecommerce.items | dlv - ecommerce items | Holds the array of product details. |
| coupon | ecommerce.coupon | dlv - ecommerce coupon | Tracks discounts applied at checkout. |
| shipping | ecommerce.shipping | dlv - ecommerce shipping | Tracks shipping costs separately from product revenue. |
Verifying Custom Events in Google Tag Manager
Never publish tracking updates blind. Audit your implementation:
- Launch Google Tag Manager in **Preview Mode** and navigate through your e-commerce purchase path.
- Check the GTM debug console on the thank-you page to verify that the **GA4 Purchase Event Tag** fired successfully.
- Open GA4 Admin โ **DebugView** and verify that the purchase event appears in the timeline with correct value and product listings.
Need support setting up reliable, clean analytics dashboards that match your business goals? Partner with analytics experts. Discover our custom GA4 tracking and event configuration services.