如何使用交易 ID 数据在 Google 标签管理器中设置 HTML 跟踪代码
How to set up HTML tracking code in Google tag manager with transaction ID data
我必须通过 google 标签管理器在感谢页面上实施跟踪像素代码。像素代码中有一个交易 ID 变量来跟踪交易。下面是跟踪像素代码。
<iframe src="https://t1.example.com/p.ashx?a=284&e=302&t=TRANSACTION_ID" height="1" width="1" frameborder="0"></iframe>
如何设置可以将交易 ID 从感谢页面传递到 GTM 中的跟踪代码的跟踪代码?
根据您在评论中的澄清,并假设您的访问者到达类似 URL:https://www.example.com/thankyou.html?transactionId=1234
你应该设置一个变量,从URL中读取ID。需要是URL类型的变量,设置类似:
您现在可以在您的代码和脚本中使用此变量,将其称为 {{Transaction ID}}
,或通过您选择的任何 GTM 变量并作为 GTM 中的变量名称提供。
在您的具体情况下,根据我在图像上的变量名称,您可以创建自定义 HTML 类型标签:
<iframe src="https://t1.example.com/p.ashx?a=284&e=302&t={{Transaction ID}}" height="1" width="1" frameborder="0"></iframe>
编辑:
另一种选择是将此数据推送到数据层,并设置一个数据层变量以从那里读取它。例如
<script>
var transactionId = //your code to get the variable
dataLayer.push({
event: 'transaction',
transactionId: transactionId
});
</script>
在这种情况下,您的变量设置如下所示:
请注意,您需要设置相关的触发器来监听transaction
事件。这个解决方案的好处是多个标签现在可以依赖这个 GTM 变量。
尽管如此,第三种选择可能是仅使用一个自定义 HTML,像这样,您可以在其中使用 JavaScript 创建 iframe,并将交易 ID 添加到 URL 在 src
属性中:
<script>
var transactionId = //your code to get the variable
var iframe = document.createElement('iframe');
iframe.style.height = "1px";
iframe.style.width = "1px";
iframe.style.border = "none";
iframe.src = "https://t1.example.com/p.ashx?a=284&e=302&t=" + transactionId;
document.body.appendChild(iframe);
</script>
我必须通过 google 标签管理器在感谢页面上实施跟踪像素代码。像素代码中有一个交易 ID 变量来跟踪交易。下面是跟踪像素代码。
<iframe src="https://t1.example.com/p.ashx?a=284&e=302&t=TRANSACTION_ID" height="1" width="1" frameborder="0"></iframe>
如何设置可以将交易 ID 从感谢页面传递到 GTM 中的跟踪代码的跟踪代码?
根据您在评论中的澄清,并假设您的访问者到达类似 URL:https://www.example.com/thankyou.html?transactionId=1234
你应该设置一个变量,从URL中读取ID。需要是URL类型的变量,设置类似:
您现在可以在您的代码和脚本中使用此变量,将其称为 {{Transaction ID}}
,或通过您选择的任何 GTM 变量并作为 GTM 中的变量名称提供。
在您的具体情况下,根据我在图像上的变量名称,您可以创建自定义 HTML 类型标签:
<iframe src="https://t1.example.com/p.ashx?a=284&e=302&t={{Transaction ID}}" height="1" width="1" frameborder="0"></iframe>
编辑:
另一种选择是将此数据推送到数据层,并设置一个数据层变量以从那里读取它。例如
<script>
var transactionId = //your code to get the variable
dataLayer.push({
event: 'transaction',
transactionId: transactionId
});
</script>
在这种情况下,您的变量设置如下所示:
请注意,您需要设置相关的触发器来监听transaction
事件。这个解决方案的好处是多个标签现在可以依赖这个 GTM 变量。
尽管如此,第三种选择可能是仅使用一个自定义 HTML,像这样,您可以在其中使用 JavaScript 创建 iframe,并将交易 ID 添加到 URL 在 src
属性中:
<script>
var transactionId = //your code to get the variable
var iframe = document.createElement('iframe');
iframe.style.height = "1px";
iframe.style.width = "1px";
iframe.style.border = "none";
iframe.src = "https://t1.example.com/p.ashx?a=284&e=302&t=" + transactionId;
document.body.appendChild(iframe);
</script>