Free tool

GA4 dataLayer Generator for Ecommerce & Lead Events

Pick an event, fill in the values, and copy dataLayer code that follows the GA4 ecommerce format. Give it to your developer or paste it yourself.

Paste on your site, or give it to your developer
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({ ecommerce: null }); // clear the previous ecommerce object
window.dataLayer.push({
  "event": "purchase",
  "ecommerce": {
    "transaction_id": "T-10045",
    "currency": "USD",
    "value": 129,
    "tax": 0,
    "shipping": 10,
    "items": [
      {
        "item_id": "SKU_123",
        "item_name": "Running Shoes",
        "price": 119,
        "quantity": 1
      }
    ]
  },
  "user_data": {
    "email": "customer@example.com",
    "phone_number": "+15551234567"
  }
});
  • In GTM, create a Custom Event trigger for "purchase" and enable "Send ecommerce data" in the GA4 event tag.
  • Push this only once per order, on the confirmation page or after the payment succeeds. transaction_id lets GA4 drop duplicates.
  • Use user_data for Google Ads enhanced conversions and Meta advanced matching. Fill it with the real customer values on your site.

What the dataLayer does

The dataLayer is a JavaScript array that your website uses to pass information to Google Tag Manager. When your site pushes an event such as purchase with the order details, GTM can send the same data to GA4, Google Ads, Meta and TikTok without scraping the page.

The rules that prevent bad data

Clear the previous ecommerce object before each ecommerce push, use the exact GA4 event and parameter names, send value as a number and currency as a three-letter code, and fire purchase only once per order with a unique transaction_id. For leads, push only after a successful form submission.

FAQ

Frequently asked questions

Where do I put this code?

On the page or in the code that runs when the action happens: the order confirmation step for purchase, the add-to-cart handler for add_to_cart, or the form success callback for generate_lead. On Shopify, use Customer Events instead of theme code.

Why push ecommerce: null first?

GTM merges dataLayer objects. Without clearing it, items from an earlier event can leak into the next one and show up in the wrong GA4 report.

Can I use the same push for Meta and Google Ads?

Yes. One clean dataLayer event can feed GA4, Google Ads conversions, the Meta Pixel and the Conversions API through GTM, which keeps values consistent across platforms.

Ready to fix your tracking and scale your ads?

Get a free audit of your tracking and ad account. Usually replies within 1–2 hours.