1

In Google Tag Manager a pre-defined variable type of "Data Layer Variable" exists with an input for the variable name. In a standard single level of key/value pairs this is easy.

var dataLayer = [{"mykey":"myvalue"}];

Given that data layer you'd just use mykey as your variable to input into GTM. However, if you use the CEDDL spec (http://www.w3.org/2013/12/ceddl-201312.pdf) structure you end up with a deeply nested array:

dataLayer = [
  {
    "product": [
      {
        "category": {
          "primaryCategory": "Auto Loans"
        },
        "productInfo": {
          "productID": "1",
          "productName": "PurchaseLoan",
          "description": "Auto finance loan"
        },
        "security": [
          "Analytics",
          "Personalization",
          "Recommendations"
        ]
      }
    ]
  }
]

So the real question is: how do I access the value of "productName" in the above example?

In standard Javascript you might access it like so: dataLayer[1].product[0].productInfo.productName or dataLayer.1.product.1.productInfo.productName

... but neither of these options work (with or without dataLayer.1 as the first node).

This is the UI to enter the variable name: enter image description here

4

1 回答 1

2

在 GTM 中定义 DataLayer 变量时,不需要在变量名中指定“dataLayer”,即。它应该是:

product.0.productInfo.productName
于 2015-11-12T00:47:29.983 回答