Google Tag Manager
advanced
5 min read4 steps721 views

How to Track Custom Events via Data Layer in GTM

The Data Layer lets your website push custom events and data to GTM, enabling tracking of any user interaction. Your developer adds `dataLayer.push({'event': 'my_event', 'key': 'value'})` to the website code at the appropriate moment. In GTM, create a Custom Event trigger matching the event name, cr

Event Trackingcustom events data layer gtm

Quick Summary

The Data Layer lets your website push custom events and data to GTM, enabling tracking of any user interaction. Your developer adds dataLayer.push({'event': 'my_event', 'key': 'value'}) to the website code at the appropriate moment. In GTM, create a Custom Event trigger matching the event name, create Data Layer Variables for any parameters, and create a GA4 Event tag that fires on the trigger with those parameters.

Process Flow

Interactive diagram — drag to pan, scroll to zoom

Step-by-Step Guide

Follow these 4 steps to complete this guide

1

How It Works

The Data Layer is a JavaScript array that GTM listens to. When your website pushes an event, GTM detects it and can fire tags. This is the most flexible tracking method — any interaction that your code can detect can be pushed to GTM.
2

Website Code

Your developer adds Data Layer pushes at the relevant points. Example for a form submission: `dataLayer.push({'event': 'form_submit', 'form_name': 'Contact Form', 'form_location': 'footer'});`
3

GTM Configuration

Create Data Layer Variables: Variables > New > Data Layer Variable. Enter the key name (e.g., 'form_name'). Create a Custom Event trigger: Triggers > New > Custom Event. Event name: 'form_submit'. Create GA4 Event tag: event name 'form_submission', parameters: form_name ({{DLV - form_name}}), form_location ({{DLV - form_location}}).
4

Best Practices

Establish a naming convention for Data Layer events. Document all events and parameters. Validate Data Layer pushes in GTM Preview mode before publishing.

Was this guide helpful?

Your feedback helps us improve our guides