GTM Data Layer Generator
Generate dataLayer.push() code for any GTM event
How It Works
Enter your event name
Type the GTM event name you want to push to the data layer.
Add key-value pairs
Add as many custom properties as your tag configuration requires.
Copy the snippet
Copy the generated dataLayer.push() code and paste it into your website.
GTM Data Layer Generator
What Is the GTM Data Layer and Why Does It Matter?
The Google Tag Manager data layer is a JavaScript array — window.dataLayer — that acts as the communication channel between your website and GTM. Instead of hardcoding values directly into tags, you push them into the data layer once, and every GTM tag can read those values. This separation of data from tag logic is what makes scalable, maintainable tracking possible.
The Anatomy of a dataLayer.push() Call
Every data layer push follows the same structure: window.dataLayer.push({ event: 'event_name', key: 'value', ... }). The event key is the trigger name that GTM listens for. All other key-value pairs become Data Layer Variables in GTM that your tags can read.
Data Layer Best Practices for GTM Implementations
- Document your schema first. Document every event name, every key, and every expected value type.
- Use snake_case consistently. All data layer keys should use lowercase with underscores.
- Keep ecommerce data in the ecommerce object. GA4 expects an ecommerce key with currency, value, and items array.
- Clear ecommerce before each push. Push
{ ecommerce: null }before each new ecommerce event. - Test with GTM Preview mode. Use GTM Preview to inspect every push in the event stream.