This project is not covered by Drupal’s security advisory policy.

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.

Supporting organizations: 

Project information

Releases