On this page
In plain English
Think of the data layer as a noticeboard between your website and GTM. The website posts messages to it; GTM reads them and uses them in triggers and tags.
It's more reliable than scraping values off the page (like reading the text of a button), because it doesn't break when someone redesigns the site.
Developers add information with dataLayer.push(). If the message includes an event key, GTM can fire a custom event trigger at that moment.
Example
When someone submits the enquiry form, the website runs:
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
event: 'generate_lead',
form_name: 'contact'
});In GTM, a custom event trigger listens for generate_lead, and a data layer variable reads form_name.
Official documentation
- The data layer (opens in a new tab) Google for Developers
Last reviewed