Layer error data resolution not defined

I created a Google Tag Manager data level variable and published a container. When I access the page, I get an error in the Chrome console

dataLayer is not defined

Pressing the datalayer script is in the HEAD element, and the GTM code snippet is in the Body tag.

+4
source share
1 answer

If you are trying to use dataLayer, you need to make sure that it is defined before using it:

window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
   'someKey': 'someValue'
})

// GTM Container here
+7
source

Source: https://habr.com/ru/post/1651300/


All Articles