Skip to main content
Drupal is a registered trademark of Dries Buytaert
EOL Warning: Drupal 11.0 has reached end of life and no longer receives security updates. EOL Warning: Drupal 10.3 has reached end of life and no longer receives security updates. EOL Warning: Drupal 10.2 has reached end of life and no longer receives security updates. EOL Warning: Drupal 10.1 has reached end of life and no longer receives security updates. EOL Warning: Drupal 10.0 has reached end of life and no longer receives security updates. EOL Warning: Drupal 9.5 has reached end of life and no longer receives security updates. EOL Warning: Drupal 9.4 has reached end of life and no longer receives security updates. EOL Warning: Drupal 9.3 has reached end of life and no longer receives security updates. Release: Raven: Sentry Integration 7.5.2 Minor update available for module raven (7.5.2). Usage Milestone: jQuery UI Datepicker Module jquery_ui_datepicker crossed 1,000 active installs.

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.

Depends on

Dependencies of the latest stable release

  • commerce_cart Drupal core
  • commerce_checkout Drupal core
  • commerce_order Drupal core
  • commerce_product Drupal core
  • token Drupal core

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
2
Tracked since
Jul 2026
Latest release
1 month ago
Releases (12 mo)
2 ▲ from 0
Maintenance
Active

Releases

Version Type Core Release date
1.0.0 Stable 10–11 Jul 14, 2026
1.0.x-dev Dev 10–11 Jul 13, 2026