Drupal is a registered trademark of Dries Buytaert
Drupal 11.4.2 Update released for Drupal core (11.4.2)! Drupal 11.4.1 Update released for Drupal core (11.4.1)! Drupal 11.4.0 Update released for Drupal core (11.4.0)! Drupal 10.6.12 Update released for Drupal core (10.6.12)! Drupal 11.3.13 Update released for Drupal core (11.3.13)! Drupal 10.6.11 Update released for Drupal core (10.6.11)! Drupal 11.3.12 Update released for Drupal core (11.3.12)! Drupal 11.2.14 Update released for Drupal core (11.2.14)! Drupal 10.5.12 Update released for Drupal core (10.5.12)! Cms 2.1.3 Update released for Drupal core (2.1.3)! Drupal 10.5.11 Update released for Drupal core (10.5.11)! Drupal 11.3.11 Update released for Drupal core (11.3.11)! Drupal 11.2.13 Update released for Drupal core (11.2.13)! Drupal 10.6.10 Update released for Drupal core (10.6.10)! Cms 2.1.2 Update released for Drupal core (2.1.2)! Drupal 11.1.10 Update released for Drupal core (11.1.10)! Drupal 10.5.10 Update released for Drupal core (10.5.10)! Drupal 10.4.10 Update released for Drupal core (10.4.10)! Drupal 11.2.12 Update released for Drupal core (11.2.12)! Drupal 11.3.10 Update released for Drupal core (11.3.10)!

This module automatically sends standard Google Analytics 4 (GA4) e-commerce events to your website's data layer, making them available for Google Tag Manager or other tag management solutions. It supports a wide range of e-commerce events and allows for flexible mapping of product data.

Commerce GA4 Datalayer pushes standard GA4 ecommerce events to window.dataLayer, ready to consume with Google Tag Manager, gtag.js, or any tag management solution. If you run Drupal Commerce and need GA4 Enhanced Ecommerce reporting without hand-writing dataLayer pushes in every template, this module builds and queues the correct event payloads for you.

Features

  • Fires view_item, add_to_cart, remove_from_cart, view_cart, begin_checkout, add_shipping_info, add_payment_info, purchase, add_to_wishlist, login, and sign_up events, each toggleable independently.
  • Configurable item parameter mapping using the Token module, map item_brand, item_variant, item_size, or any custom parameter name to product/variation fields, no fixed slots.
  • Hierarchical taxonomy support: walk up to 3 parent levels of a term reference (e.g. category tree) into item_category, item_category2, item_category3.
  • Core Commerce fields (SKU, title, price, quantity, affiliation, promotions, coupons) are mapped automatically.
  • Session-based event queue decouples event generation (add to cart, checkout, order placement) from page render, flushing to window.dataLayer via drupalSettings on next page load: correct timing with GTM container init.
  • Automatic promotion resolution on add_to_cart via Commerce's order refresh, giving accurate discount, promotion_id, promotion_name without an extra save.
  • Duplicate event prevention for AJAX-heavy flows (variation switches, repeat cart views).
  • Checkout step detection via route + Referer comparison, so AJAX refreshes don't refire begin_checkout/add_shipping_info/add_payment_info.
  • Role-based exclusion: skip tracking entirely for selected roles (e.g. staff, admins).
  • Public builder service and hook for other modules to add custom GA4 events (e.g. select_item, custom search events) or alter item payloads.

Use this module if you're running Drupal Commerce and need GA4 Enhanced Ecommerce data without maintaining custom dataLayer JavaScript across every commerce template.

Post-Installation

After enabling, go to Commerce > Configuration > GA4 DataLayer (/admin/commerce/config/ga4-datalayer) to:

  • Toggle which events are active
  • Define item parameter → Token mappings (with a built-in token browser)
  • Exclude specific roles from tracking

No content type or text format changes are needed. You still need a tag management solution (GTM, gtag.js) configured separately to actually read from window.dataLayer, this module only populates it.

Additional Requirements

  • Drupal 10.3+ or 11
  • Drupal Commerce 2.36+ (commerce_order, commerce_cart, commerce_product, commerce_checkout)
  • Token module
  • A tag management solution reading window.dataLayer (Google Tag Manager, gtag.js, etc.) not provided by this module

Optional:

Community Documentation

See the project README for full configuration examples, token mapping tables, and code samples for extending the module with custom event subscribers.

Activity

Total releases
1
First release
Jul 2026
Latest release
2 hours ago
Release cadence
Stability
0% stable

Releases

Version Type Release date
1.0.x-dev Dev Jul 13, 2026