Ecommerce Data Layer Generator — GA4 & GTM Code | Adslytics | Adslytics

🏪

Ecommerce Data Layer Generator

Generate complete ecommerce data layer code for GA4 and GTM

How It Works

1

Choose your event type

Select from purchase, add_to_cart, view_item, begin_checkout, or view_item_list.

2

Fill in transaction & product details

Add currency, value, transaction ID, and one or more product objects.

3

Copy your data layer code

Get the complete window.dataLayer.push() snippet ready to add to your website.

Ecommerce Data Layer Generator


              
            

The Complete GA4 Ecommerce Data Layer: What You Need to Know

The GA4 ecommerce data layer is a standardised JavaScript object pushed to window.dataLayer before GTM fires any ecommerce tags. It tells GA4 what happened in the user\'s shopping journey — what products they viewed, added to cart, and purchased — along with all the financial and product metadata needed for accurate revenue attribution. This ecommerce data layer generator produces production-ready data layer code for any GA4 ecommerce event.

Critical Implementation Rules That Developers Frequently Miss

  • Always clear the ecommerce object first. Before every dataLayer.push() with an ecommerce event, push { ecommerce: null }. Without this reset, GTM may merge the previous ecommerce object with the new one.
  • Send value as a number, not a string. The value field must be a JavaScript number (49.99), not a string ("49.99").
  • Use ISO 4217 currency codes. currency must be a 3-letter ISO code (USD, EUR, GBP).
  • Make transaction_id unique per order. Duplicate transaction_id values cause GA4 to silently ignore the second transaction.

Frequently Asked Questions

GA4 standard ecommerce events: view_item_list, select_item, view_item, add_to_cart, remove_from_cart, view_cart, begin_checkout, add_payment_info, add_shipping_info, purchase, and refund.
No — implement the events relevant to your funnel. At minimum: view_item, add_to_cart, begin_checkout, and purchase.
Place it in the <head> or early in the <body>, before the GTM snippet fires.
Create a GA4 Event tag with event name matching your event. Add a parameter named "ecommerce" with value set to a Data Layer Variable reading from "ecommerce".
GA4 uses a flatter structure with a single "items" array instead of the nested "products" array in UA.