如何在自定义 HTML 中获取 google 标签管理器变量值

How to get google tag manger variable value in custom HTML

我的数据层中有动态值,我想从 Google 跟踪代码管理器

中的自定义 HTML 访问这些值

标签中的自定义 HTML:{用于跟踪订单的像素图像}

<img src="https://httpool-secure.net/p.ashx?o=59&e=51&f=img&t={{transactionId}}&etc={{transactionTotal}}" width="1" height="1" border="0"

我的数据层对象:

[{
    "event": "ordersuccess",
    "transactionId": 86886,
    "transactionAffiliation": "Powai",
    "transactionTotal": 158,
    "transactionTax": 17.5,
    "transactionProducts": [{
        "sku": "2395",
        "name": "Masala Calzone ",
        "category": "OTHERS",
        "price": "70",
        "quantity": "2"
    }]
}, {
    "gtm.start": 1454584525056,
    "event": "gtm.js"
}, {
    "event": "gtm.dom"
}, {
    "event": "gtm.load"
}]

Data Layer Variable transactionId

Data Layer Variable transactionTotal

现在,当我发布标签时出现错误:

Unknown variable 'transactionTotal' found in a tag. Edit the tag and remove the reference to the unknown variable.

Unknown variable 'transactionId' found in a tag. Edit the tag and remove the reference to the unknown variable.

如何将变量关联到我的标签???

我不相信这个可能的答案,因为它已经在评论中提到(@EikePierstorff 的支持),但作为一种形式,这里是:

您应该使用您定义的数据层变量的名称,而不是数据层参数本身的名称:

<img src="https://httpool-secure.net/p.ashx?o=59&e=51&f=img&t={{transaction_id}}&etc={{total transaction}}" ...

顶部字段设置GTM面板中的变量名称。 请使用该名称作为变量名。 您应该使用在此输入框中命名的数据层变量的名称,而不是数据层参数本身的名称

虽然已经给出了正确答案,但直到我看到这个存储库中的文档,我才真正理解它: https://github.com/BKWLD/data-layer-events

密钥是 README.md 文件 Setup 部分的一部分。

基本上,您需要使用您提供的参数名称设置 Data Layer Variable 类型的变量,在您的情况下为 transactionId,然后该变量在标签上可用,并且它将匹配您提供的 JS 参数。

正如一些人提到的,在 HTML 中引用它时需要使用变量的名称。例如:如果我设置了一个名为 'Order Total' 的变量,但数据层变量名称是 orderTotal,您需要在 HTML 中使用 'Order Total',如下所示。

警报({{订单总计}});