DataLayer Spec Generator

Copy-paste-ready dataLayer events for the most common site types — eComm, lead-gen, SaaS — wired up so GA4, Meta CAPI, and Google Ads Enhanced Conversions all work from the same push.

Site type

view_item
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({ ecommerce: null });
window.dataLayer.push({
  event: "view_item",
  ecommerce: {
    currency: "USD",
    value: 79.00,
    items: [{
      item_id: "SKU_12345",
      item_name: "Merino Crew Sweater",
      item_brand: "Northwind",
      item_category: "Apparel",
      item_variant: "Black",
      price: 79.00,
      quantity: 1
    }]
  }
});
add_to_cart
window.dataLayer.push({ ecommerce: null });
window.dataLayer.push({
  event: "add_to_cart",
  ecommerce: {
    currency: "USD",
    value: 79.00,
    items: [{
      item_id: "SKU_12345",
      item_name: "Merino Crew Sweater",
      price: 79.00,
      quantity: 1
    }]
  }
});
begin_checkout
window.dataLayer.push({ ecommerce: null });
window.dataLayer.push({
  event: "begin_checkout",
  ecommerce: {
    currency: "USD",
    value: 158.00,
    items: [/* same items array */]
  }
});
purchase (with user data for CAPI / EC)
window.dataLayer.push({ ecommerce: null });
window.dataLayer.push({
  event: "purchase",
  user_data: {
    email: "ada@example.com",        // hash server-side before sending to platforms
    phone: "+12025550100",
    first_name: "Ada",
    last_name: "Lovelace",
    address: { city: "London", postal_code: "SW1A 1AA", country: "GB" }
  },
  ecommerce: {
    transaction_id: "ORD_98765",     // critical for de-dup
    currency: "USD",
    value: 158.00,
    tax: 12.00,
    shipping: 5.00,
    coupon: "SPRING10",
    items: [/* full items array */]
  }
});

Why ecommerce: null first? GA4's ecommerce object persists across pushes. Resetting it prevents stale items from leaking into the next event.

The user_data block lives at the dataLayer level (not inside ecommerce) so a single GTM tag can pick it up for both Meta CAPI and Google Enhanced Conversions.

Want this implemented?

From spec to working tracking — in one engagement.

We translate this spec into platform-specific tags, server-side endpoints, and a deduplication scheme that survives consent rejection and iOS 14.5.

INTERACTIVE DEMO Want to test how this tool works?
Save these results as a PDF report A clean, branded copy to share with your team or client.
Free PDF report

Where should we put your name on the report?

Your PDF downloads straight away. Your tool data never leaves your browser.

Jobair Mahmud, Web Analytics & Tracking Architect
Tool Creator

Jobair Mahmud

Founder & Tracking Architect

100% Top Rated
5.0 / 5.0

Want the spec implemented for you?

I write the data layer spec, work with your developer (or implement it myself) and set up GA4, Google Ads and Meta tags on top of it.

Get my data layer built →

How to use the DataLayer Spec Generator

A data layer spec is the document your developer follows so that every important action on your site pushes the same, complete information to Google Tag Manager. Getting it right once means GA4, Google Ads, Meta and other platforms all receive consistent data.

Step by step

  1. Choose your business type (ecommerce, lead generation or SaaS) to start from the right event list.
  2. Remove events you don't need and add any custom ones, using GA4's recommended event names where possible.
  3. Copy the generated dataLayer.push code and hand it to your developer with the page where each event should fire.
  4. Test each event in GTM Preview: the event name and every parameter should appear exactly as specified.

How to read your result

Every event tested in GTM Preview

You can now map tags for GA4, Google Ads and Meta from one clean source.

Events fire but values are missing

The push happens before the data is available (for example before the order total loads). Move the push to after the data exists.

Purchases fire twice

The push runs again on page reloads. Fire it once per order and always include a unique transaction_id.

Common mistakes

  • Inventing custom event names when GA4 already has a recommended one (purchase, add_to_cart, generate_lead).
  • Not clearing the previous ecommerce object before pushing a new one.
  • Sending prices as text with currency symbols instead of numbers.

Questions

Do I need a data layer if I use a Shopify or WooCommerce app?

Apps cover the basics, but a custom data layer gives you control over parameters, deduplication and events the app doesn't send.

Who implements the spec?

Usually your developer adds the pushes, and the GTM tags are configured on top. I can do both or work alongside your developer.

Want the spec implemented for you?

I write the data layer spec, work with your developer (or implement it myself) and set up GA4, Google Ads and Meta tags on top of it.