I have created Google Tag Manager data layer variable and published the container. When I access the page I get the error in Chrome console
dataLayer is not defined
The datalayer push script is in the the HEAD element and the GTM code snippet is in the Body tag.
Data layer variables enable Tag Manager to read values from your data layer implementation and pass those values to tags, triggers, and other variables. A data layer object is made up of a list of key/value pairs. A key is a category of things – a book's category, title, or author. Each key could have different values.
It's just as easy. Just head on over to your console, type in “dataLayer,” navigate to your key:value pair, and follow the nested path to the key you want to identify.
dataLayer is a JavaScript Array, which holds data in key-value pairs. The key is a variable name in String format, and values can be any allowed JavaScript type.
If you are trying to use the dataLayer, you need to make sure it is defined before you use it:
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'someKey': 'someValue'
})
// GTM Container here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With