Skip to main content
AnalyticsLearner

Module 10

GA4 ecommerce purchase dataLayer (generic)

The complete GA4 purchase event dataLayer push. Production-correct schema with all required and recommended parameters.

ga4ecommercedatalayerpurchase

What this does

The GA4 purchase event is the most important measurement point in an ecommerce stack. This snippet shows the complete dataLayer push with all required parameters and the recommended additional parameters that improve GA4 reporting accuracy.

The schema

window.dataLayer = window.dataLayer || [];
window.dataLayer.push({ ecommerce: null }); // Clear previous ecommerce object
 
window.dataLayer.push({
  event: 'purchase',
  ecommerce: {
    transaction_id: 'T_12345', // Required. Must be unique per order.
    value: 99.0, // Required. Total revenue (after discounts, before tax).
    tax: 8.25, // Recommended.
    shipping: 5.0, // Recommended.
    currency: 'USD', // Required. ISO 4217.
    coupon: 'SUMMER10', // Optional.
    items: [
      {
        item_id: 'SKU_001', // Required. Your product ID.
        item_name: 'Product Name', // Required.
        item_brand: 'Brand Name', // Recommended.
        item_category: 'Category', // Recommended.
        item_variant: 'Blue / Large', // Recommended.
        price: 89.0, // Required. Unit price.
        quantity: 1, // Required.
        coupon: '', // Optional - per-item coupon.
        discount: 10.0, // Optional - per-item discount amount.
      },
      // Add more items as needed
    ],
  },
});

Important: clear the ecommerce object first

Always push { ecommerce: null } before the purchase push. If a previous ecommerce event (e.g. add_to_cart) is still in the dataLayer, GA4 may merge the item arrays, creating duplicate or incorrect data.

Matching value to platform revenue

The value field should match what your platform calls "subtotal" or "revenue": the sum of item prices minus discounts, before tax and shipping. Do not include tax or shipping in value unless your business requires it; add them as separate tax and shipping parameters instead.

Transaction ID uniqueness

transaction_id must be unique per order. Reusing a transaction ID causes GA4 to de-duplicate the purchase and the revenue will not appear. Use your order management system's order number or a UUID generated at checkout completion.

GTM configuration

In GTM, the purchase tag reads from the ecommerce object via Data Layer Variable. Configure the variable path as ecommerce with Data Layer Version 2.

For the GA4 event tag:

  • Event name: purchase
  • Ecommerce data: check "Send Ecommerce data" and set source to "Data Layer"
  • Trigger: Custom Event matching purchase

The free GA4 Ecommerce Container has the full GTM setup pre-built.

Free container for this module

GA4 Ecommerce Container

Production GA4 ecommerce implementation covering the full purchase funnel: view_item, add_to_cart, begin_checkout, purchase. Includes the data layer schema and a Shopify Customer Events variant for headless builds.

Get the container →