GTM - Ecommerce Purchase Campaign

Seamlessly track ecommerce purchases with GA4 and data layer integration for accurate, real-time sales insights.

Ceyhun Enki Aksan
Ceyhun Enki Aksan Entrepreneur, Maker

Google Tag Manager set up our container, added our Google Analytics account, and enabled the Enable Enhanced Ecommerce Features option.

As a result of these basic actions, we can now send data to Google Analytics > E-commerce reports via data layers.

warning

As of July 2023, Universal Analytics (UA) is being replaced by Google Analytics 4 (GA4) property format. After this date, UA properties will no longer be able to process new data. They are expected to become inaccessible by year-end as well. For details on differences between property formats and other related actions, please refer to our article titled Universal Analytics (UA) to Google Analytics 4 (GA4). You may also request technical support at (https://calendly.com/dnomia/15min).

Enhanced Ecommerce “purchase” Event

We presented our products to visitors with various promotions and attributes (see promoView and Impressions), visitors evaluated promotions that matched their interests (see promoClick and productClick), and began viewing product details in order to make purchase decisions (see detail).

The addition of a product to the cart (see addToCart) and proceeding to the payment steps (see checkout) does not necessarily mean the process is complete. The approval of the order, successful payment, and potential product/monetary refund in subsequent stages are also key evaluation points for product and sales performance. Therefore, proper implementation of these steps is essential.

Google Analytics
Google Analytics

Upon examining the details of the purchase data layer:

window.dataLayer = window.dataLayer || [];

// UA
dataLayer.push({
  'ecommerce': {
    'purchase': {
      'actionField': {
        'id': '[unique-transaction-id]', // Unique Transaction ID (Transaction ID) / Type: string (required)
        'affiliation': '[store-or-seller-name]', // Store or Seller Name / Type: string (optional)
        'revenue': '[total-revenue]', // Total Revenue (including taxes and shipping) / Type: numeric (required)
        'tax': '[total-tax]', // Total Tax (including taxes and shipping) / Type: numeric (required)
        'shipping': '[shipping-amount]', // Shipping Amount / Type: numeric (optional)
        'coupon': '[coupon-code]' // Discount Coupon / Type: string (optional)
      },
      'products': [{
        // Details of the purchased products
        // ...
       }]
    }
  }
});

// GA4
dataLayer.push({
  'event': 'purchase',
  'ecommerce': {
    'purchase': {
      'transaction_id': '[unique-transaction-id]', // Unique Transaction ID (Transaction ID) / Type: string (required)
      'affiliation': '[store-or-seller-name]', // Store or Seller Name / Type: string (optional)
      'value': '[total-sale-amount]', // Total Sale Amount (including taxes and shipping) / Type: numeric (required)
      'tax': '[total-sale-amount]', // Total Sale Amount (including taxes and shipping) / Type: numeric (required)
      'shipping': '[shipping-amount]', // Shipping Amount / Type: numeric (optional)
      'currency': '[currency-code]', // Currency Code / Type: string (optional)
      'coupon': '[coupon-code]' // Discount Coupon / Type: string (optional)
      'items': [{
        // Details of the purchased products
        //...
      }]
    }
  }
});

Let’s create a real-world example of the Purchase (buying) event. Additionally, we can certainly link the relevant data layer to the event (for example, ‘purchase’).

// UA
dataLayer.push({
  'event': 'purchase', // or transactionComplete
  'ecommerce': {
    'purchase': {
      'actionField': {
        'id': 'T12345',
        'affiliation': 'Online Store',
        'revenue': '59.89',
        'tax': '4.90',
        'shipping': '5.99',
        'coupon': 'SUMMER2018'
      },
      'products': [{
        'name': 'Triblend Android T-Shirt',
        'id': '12345',
        'price': '15.25',
        'brand': 'Google',
        'category': 'Apparel',
        'variant': 'Gray',
        'quantity': 1,
        'coupon': 'APPARELSALE',
        'dimension1': 'L',  // For example; Product Size
        'dimension2': 'pre-order',  // For example; Product Stock Status
        'dimension3': 'guest',  // For example; Visitor Status
        'metric1': '10'  // For example; Product Cost
       },
       {
        'name': 'Donut Friday Scented T-Shirt',
        'id': '67890',
        'price': '33.75',
        'brand': 'Google',
        'category': 'Apparel',
        'variant': 'Black',
        'quantity': 1,
        'coupon': '',
        'dimension1': 'M',
        'dimension2': 'in-stock',
        'dimension3': 'guest',
        'metric1': '20'
       }]
    }
  }
});

// GA4
dataLayer.push({
  'event': 'purchase',
  'ecommerce': {
    'purchase': {
      'transaction_id': 'T12345',
      'affiliation': 'Online Store',
      'value': '35.43',
      'tax': '4.90',
      'shipping': '5.99',
      'currency': 'EUR',
      'coupon': 'SUMMER_SALE',
      'items': [{
        'item_name': 'Triblend Android T-Shirt',
        'item_id': '12345',
        'item_price': '15.25',
        'item_brand': 'Google',
        'item_category': 'Apparel',
        'item_variant': 'Gray',
        'quantity': 1,
        'item_coupon': ''
      }, {
        'item_name': 'Donut Friday Scented T-Shirt',
        'item_id': '67890',
        'item_price': '33.75',
        'item_brand': 'Google',
        'item_category': 'Apparel',
        'item_variant': 'Black',
        'quantity': 1
      }]
    }
  }
});

After the transaction is completed, you can access product and sales details in the Sales Performance section, view which steps visitors dropped off in the funnel, and conduct digital advertising campaigns to complete pending e-commerce processes. In the performance reports you’ll view (sales, products, payments, etc.), additional columns for taxes, shipping, and refund amounts will also be included. Therefore, it’s essential to ensure that all stages of the e-commerce setup—from page loading to clicks, from product-to-cart actions to checkout and return processes—are properly configured and accurately reflected in the reports. The Google Tag Assistant extension I mentioned earlier can be used for these control checks.

Other details and related events concerning enhanced e-commerce should be reviewed in Enhanced Ecommerce, Google Analytics Goals and Funnel Operations, Google Tag Manager dataLayer and E-Commerce Events, Google Analytics E-Commerce Reports and Event Setups, and the Google Analytics / GTM UA1 and GA42 help pages.

*[GTM]: Google Tag Manager
*[UA]: Universal Analytics
*[GA4]: Google Analytics 4

Footnotes

  1. Enhanced Ecommerce (UA) Developer Guide
  2. Ecommerce (GA4) Developer Guide