我必须通过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中的跟踪代码?
根据您在评论中的澄清,并假设您的访问者到达类似的网址: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>
编辑:
另一种选择是将此数据推送到dataLayer,并设置数据层变量以从那里读取它。例如。
<script>
var transactionId = //your code to get the variable
dataLayer.push({
event: 'transaction',
transactionId: transactionId
});
</script>
在这种情况下,您的变量设置如下所示:
请注意,您需要设置相关触发器来收听transaction
事件。此解决方案的好处是多个标签现在可以依赖此GTM变量。
然而,第三个选项可能是只使用一个自定义HTML,使用类似的东西,用JavaScript创建iframe,并将事务ID添加到src
属性中的URL:
<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>