Free – no sign-up

GTM Data Layer Generator

Generate correct dataLayer.push snippets for Google Tag Manager – from form and click events to GA4 ecommerce with an items array.

  1. Step 1

    Choose event type

    From custom event to purchase – matching your use case.

  2. Step 2

    Fill in the fields

    Only relevant fields show; values are freely editable.

  3. Step 3

    Copy the code

    Take the valid JavaScript directly and implement it.

dataLayer.push code
dataLayer.push code
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
  event: "generate_lead",
  lead_type: "consultation",
  value: 50,
  currency: "EUR"
});

Implement the code & use it in GTM

Add the dataLayer.push code where the event occurs on your website – for example in a form's onsubmit handler. Then create a custom event trigger in Google Tag Manager with exactly this event name and link it to your GA4 event tag. Test the event in GTM preview mode and GA4 DebugView.

Important

A generated code snippet is not a finished implementation on your website. The code must be added correctly and fired through a matching trigger.

What does the GTM Data Layer Generator do?

It generates valid dataLayer.push snippets for typical tracking events. Strings are escaped correctly, numbers are treated as numbers and ecommerce data is serialized with a nested items array. For GA4 ecommerce it also pushes ecommerce: null before the event to clear values between events.

When should you use it?

When you want to pass events to Google Tag Manager via the data layer instead of hard-wiring values into tags. The data layer is the clean interface between your website and GTM and makes your tracking more maintainable.

Which mistakes does it prevent?

Broken escaping, values passed as strings instead of numbers, invalid JavaScript and malformed items arrays. The event key here is the name of your GTM custom event trigger – not necessarily the event name sent to GA4.

Technical limitations

The generator produces sample code. It installs nothing on your website and fires no events. You have to add the code in the right place and create a matching trigger in GTM.

Official Google documentation: developers.google.com/tag-platform/tag-manager/datalayer

Next step

Turn the data layer into GTM tags automatically

Want to turn this into matching GTM tags and triggers automatically? The GTM Builder prepares tags, triggers and dataLayer variables in a separate workspace – you approve them.

FAQ

What is the data layer in GTM?

The data layer is a JavaScript array (window.dataLayer) your website uses to pass structured data to Google Tag Manager. Tags read these values via variables – keeping data and tag logic separate.

Is the event value the GA4 event name?

Not necessarily. The event key in the data layer is the name of the GTM custom event trigger. Which GA4 event name is sent is defined in your GA4 tag.

Why push ecommerce: null before purchase?

To clear ecommerce values from a previous event. Otherwise old items or values can leak into subsequent events.

Can I pass multiple items?

Yes. For add_to_cart, begin_checkout and purchase you can add any number of items with item_id, item_name, price and quantity.

Does the tool create my GTM tags automatically?

No. It only generates the data layer code. You create tags and triggers in GTM yourself – or automated with the GTM Builder.

More free tools

View all free tools

These free tracking tools are built by Data Flakes – specialists for conversion tracking, GA4, Google Tag Manager and automation. For custom implementations, audits and consulting we help you directly.