Metadata
- Author: Google for Developers
- Full Title:: The data layer
- Category:: 🗞️Articles
- Document Tags:: google analytics,
- URL:: https://developers.google.com/tag-platform/tag-manager/datalayer
- Finished date:: 2023-10-29
Highlights
If a
gtag()
ordataLayer.push()
call is made by code on a page, in a Custom Template, or in a Custom HTML tag, the associated message is queued and processed after all other pending messages are evaluated. This means that any updated data layer values are not guaranteed to be available for the next event. To handle these cases, you should add an event name to a message as it is pushed to the data layer, and then listen for that event name with a Custom Event trigger. (View Highlight)
You could use variables in triggers, or as event params…
You can push data layer variables to the data layer dynamically to capture information such as values entered or selected in a form, metadata associated with a video that the visitor is playing, the color of a product (e.g. a car) customized by the visitor, the destination URLs of clicked links, etc. (View Highlight)
dataLayer.push({‘variable_name’: ‘variable_value’}); (View Highlight)
Each variable declared within the data layer object will persist only as long as the visitor remains on the current page. Data layer variables that are relevant across pages (e.g.
visitorType
) must be declared in the data layer on each page of your website (View Highlight)