GTM & GA4 Ecommerce Tracking

Google Tag Manager (GTM) & GA4 Ecommerce Tracking

The WooCommerce Thank You Redirect plugin is fully compatible with Google Tag Manager (GTM) and Google Analytics 4 (GA4). It automatically resolves a common issue where custom thank-you page redirects prevent transaction and conversion data from being tracked correctly.


How It Works

Zero Configuration Required

When a customer completes an order, the plugin redirects them to your custom thank-you page and automatically appends a secure order_key parameter to the URL.

On the destination page, the plugin:

  • Detects the order_key parameter
  • Securely retrieves the associated WooCommerce order
  • Generates a GA4-compliant ecommerce purchase event
  • Pushes the event directly to the global window.dataLayer object from the page footer

This ensures that your analytics and advertising platforms receive accurate transaction data even when using custom thank-you page redirects.


Prerequisites

Before tracking can work correctly, ensure the following requirements are met:

1. Google Tag Manager Container Installed

The plugin generates and pushes ecommerce tracking data but does not load the GTM container script itself.

You must install your GTM container (GTM-XXXXXXX) using:

  • Your WordPress theme, or
  • A dedicated plugin such as GTM4WP – Google Tag Manager for WordPress

2. Redirect Page Must Be Hosted on WordPress

The custom thank-you page must be a page served by your WordPress website, including pages built with:

  • Gutenberg
  • Elementor
  • Divi
  • Beaver Builder
  • Other WordPress page builders

This allows the plugin to inject the tracking event into the page footer.


Data Layer Structure

The plugin pushes a standard GA4 Ecommerce Purchase Event into the Data Layer.

window.dataLayer =window.dataLayer || [];
window.dataLayer.push({
 event: 'purchase',
 ecommerce: {
 currency: 'USD',
 value: 120.00,
 tax: 10.00,
 shipping: 5.00,
 affiliation: 'Your Store Name',
 transaction_id: '12345',
 coupon: 'DISCOUNT10',
 items: [
 {
 item_name: 'Premium Leather Boots',
 item_id: 'SKU-BOOTS-01',
 price: 105.00,
 item_brand: 'BrandName',
 item_category: 'Apparel, Shoes',
 quantity: 1
 }
 ]
 }
});

The schema follows Google’s recommended GA4 ecommerce format and can be consumed directly by GTM, GA4, Google Ads, Meta Pixel, and other marketing platforms.


Google Tag Manager Setup

To capture the purchase event and forward it to Google Analytics 4 or other platforms, configure GTM as follows.

Step 1: Create a Custom Event Trigger

  1. Open your GTM workspace.
  2. Navigate to Triggers → New.
  3. Select Trigger Type → Custom Event.
  4. Set the Event Name to: purchase
  5. Save the trigger as: Custom – GA4 Purchase Event

Step 2: Create a GA4 Event Tag

  1. Navigate to Tags → New.
  2. Select Google Analytics → GA4 Event.
  3. Configure the tag with:
SettingValue
Event Namepurchase
Configuration TagYour GA4 Configuration Tag
Send Ecommerce DataEnabled
Data SourceData Layer
  1. Assign the trigger created in Step 1:Custom – GA4 Purchase Event
  2. Save and publish your GTM container.
Was this page helpful?