I'm trying to make sure our developer set up Google Tag Manager (GTM) DataLayers on our website correctly, as I'm having trouble validating.
Here's the situation: I asked our developer to set up DataLayers on our website's product page using the window.dataLayer.push method. They said they did this.
I set up all the proper Variables in our GTM account to match the datalayer names collected on the website. Then I went into GTM's Preview debug mode to ensure that the Variables were populating on any product page. However, each time I checked this, the Variables came up as "undefined". Hmmm.
My developer said everything looked ok on their end and provided a screenshot of a Google Tag Assistant Chrome extension that indicated product variables were being picked up, and I saw the same thing:
GoogleTagAssistantScreenshotProductPage
I checked the source code for this product page and found this:
<script type="text/javascript">
(function e(){var e=document.createElement("script");e.type="text/javascript",e.async=true,e.src="//staticw2.yotpo.com/vznvXB90INUtUFVnU1036xQfL3T6LgDlAYStvsoA/widget.js";var t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(e,t)})();
</script>
<script>
var toPushToDatalayer = ({"event":"productDetail","ecommerce":{"detail":{"products":[{"name":"Business Basics for Law Students","id":"10040","price":"80.9500","category":null,"magento_id":"36"}]}}}); dataLayer.push(toPushToDatalayer);
</script>
<script type="text/javascript">
//<![CDATA[
var Translator = new Translate([]);
//]]>
</script>
<meta name="msvalidate.01" content="DC61177F62A1EFB53CB064D74B1BB401" />
<meta name="google-site-verification" content="75YqkgTbUbVcW7fqgA9EmUo6lrULtbTDW8urj8TJMo0" />
I'm not a developer and so was concerned that not seeing the term window.dataLayer.push
anywhere on the page source code might mean that this method was not used to implement DataLayers on the website. Especially since, although the variables are appearing in the Tag Assistant window, they are still coming up as "undefined" in the GTM Preview Debug window under "Variables" (although they DO appear under "Data Layer" tab), as in screenshot below for the same page:
So, I guess my question is: If my datalayer variables are populating on my product page (per TagAssistant screenshot and Data Layer tab in GTM Preview Debug screenshot (top half), why are my Variables appearing as undefined
under the Variables tab in GTM Preview Debug mode (as in the GTM Preview Debug Screenshot (bottom half))?
Just to cover all my bases, here are a couple of examples of how I set up Variables in Google Tag Manager for these product page variables, in case the problem lies here:
Sorry for the long post, I wanted to give all relevant info. Thanks in advance for any help!