【发布时间】:2022-07-01 06:27:53
【问题描述】:
我最近在 Shopify 上进行了 GTM 设置,除了购买跟踪之外,一切都进展顺利。我发现在 GAUA、GA4 和 Google Ads(添加到购物车、启动结帐等)中可以完美跟踪所有其他事件,但是每当有人完成交易时,都没有记录。
我已经通过不同方式触发购买来测试自己:
- 使用和不使用 cookie
- 通过 GTM 调试器
- 关于移动数据
- 隐身
每次我自己的购买跟踪和 Datalayer 触发并完美填充。但是,似乎只要有真正的客户订单,它就不会跟踪。我可以看到 GTM 容器必须处于活动状态,因为在 GAUA 中我可以看到他们已经在旅程结束时登陆了订单确认页面,看起来好像数据层永远不会填满。
这是我在 Shopify 的附加结帐脚本(不是加号商店)中的 DataLayer 代码:
<script>
{% if first_time_accessed %}
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({ ecommerce: null });
window.dataLayer.push({
'event': 'EEPurchase',
'pagePath': '/checkout/thank_you',
'pageTitle': 'Purchase',
'ecommerce':{
'purchase':{
'actionField':{
'id': '{{order.name}}',
'revenue': {{ order.total_price | money_without_currency | replace: ",", "" }},
'tax': {{order.tax_price | money | money_without_currency | replace: ",", "" }},
'shipping': {{order.shipping_price | money_without_currency | replace: ",", "" }},
'coupon': [
{% for discount_application in order.cart_level_discount_applications %}
{
'{{ discount_application.title }}'
},
{% endfor %}
]
},
'products':[
{% for line_item in line_items %}
{
'name': '{{line_item.title}}',
'id': '{{line_item.product_id}}',
'price':{{line_item.original_price | money_without_currency | replace: ",", "" }},
'brand': '{{line_item.vendor}}',
'category': '{{line_item.product.type}}',
{% unless line_item.variant.title == 'Default Title' %}'variant': '{{line_item.variant.title}}', {% endunless%}
'quantity': {{line_item.quantity}}
},
{% endfor %}
]
}
}
})
{% endif %}
</script>
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-TRACKING-CODE');</script>
<!-- End Google Tag Manager -->
感谢任何见解,谢谢!
【问题讨论】:
-
您是否使用折扣码进行了测试购买?
coupon数组似乎包含一个非法对象,如果用户订购了折扣商品,这将导致错误(因此事件不会触发)。 -
@davidthorand 不,我没有使用优惠券进行测试,当它在我的测试中触发时,它会以优惠券的形式触发:[],它应该以优惠券的形式触发:[{}] 还是只是根本不火?还值得注意的是,真正的购买也没有使用优惠券
-
@Emma David 的意思是,如果有优惠券,该对象将无效,并且您之前会遇到 JS 错误,但如果您使用 [] 进行测试,那不是问题。 (但我仍然建议删除包装折扣标题的
{})。您能否确认您没有收到任何控制台错误并且 window.dataLayer 变量已正确更新? -
@FabioFilippi 谢谢你的澄清 - 我明白你现在的意思了,我已经为以后的任何问题解决了这个问题。我可以确认订单确认页面上没有控制台错误
-
@Emma 其他一切似乎都是正确的。我很确定这没有什么区别,但是您可以尝试将 TAG 脚本移到
dataLayer.push之前。除此之外,对不起,我没有想法。
标签: google-analytics shopify google-tag-manager google-analytics-4