google-analytics - 谷歌分析标签管理器电子商务数据层未发送
问题描述
我正在尝试使用 gtm(谷歌分析:通用分析)将电子商务事件发送到谷歌分析,这是我的代码
const loadGa = (next, retry) => {
if (!retry) retry = 0;
if (typeof ga === 'function') {
return next(null);
}
if (retry > 10) return next(new Error('Can not load google analytics'));
retry++;
setTimeout(() => loadGa(next, retry), 500);
}
const addProductGa = product => {
loadGa((err) => {
if (err) return console.error(err);
dataLayer.push({
event: 'addToCart',
ecommerce: {
currencyCode: 'EUR',
add: {
products: [{
name: product.name,
id: product.id,
price: product.acquisitionAmount / 100,
quantity: 1
}]
}
}
});
})
}
const purchaseGa = (charge, product) => {
loadGa((err) => {
if (err) return console.error(err);
dataLayer.push({
ecommerce: {
currencyCode: 'EUR',
purchase: {
actionField: {
id: charge.id,
revenue: charge.amount
},
products: [{
name: product.name,
id: product.id,
price: product.acquisitionAmount / 100,
quantity: 1
}]
}
}
});
})
}
例如,如果我调用addProductGa
- 调用 GTM
- 调用分析
- 发送基本跟踪数据
我的电子商务数据似乎没有发送,我在对分析服务器的网络调用中看不到它们,而且我在 Google Analytics 上没有数据
解决方案
我能说的:
- 默认情况下
dataLayer.push
不会在任何地方发送数据,它只是提供数据层。您需要 GTM 触发器和标签来发送数据,这将我带到了下一点 - 您的某些呼叫中缺少
event
键dataLayer.push
(例如):我知道您正在遵循GTM ecom 规范purchase
中给出的示例,但 IMO 令人困惑:其中一些显示基于事件的集合(带有键集),其他基于浏览量的集合(没有密钥集)。为了简化您的设置,您应该:event
event
完整设置:一旦您
event
在所有 dataLayer 调用上都有一个属性,您就可以使用类似于下面显示的设置来一般地跟踪它们(您应该将触发器更改为匹配所有电子商务事件的正则表达式,也不要忘记在 GA 设置中启用增强型电子商务)。如果问题仍然存在,您应该启用GTM 预览/调试,它会告诉您为什么某些标签没有触发,并会显示它包含的 dataLayer 值的调试
如果 GTM 确认标签正在触发,但您没有在网络上看到 GA 跟踪,则您需要使用Chrome GA 调试器,它会详细显示正在发生的事情以及未发送命中的可能原因。
完成所有故障排除并正常工作后,不要忘记发布 GTM
推荐阅读
- shell - shell 处理和比较数组元素
- python-3.x - 如何在不实际写入队列的情况下测试写入队列
- google-analytics - 如何为支付推荐网站设置谷歌分析/谷歌标签管理器
- python - 尽管没有更改,JSON Web 令牌不再具有“解码”属性
- python - 如何在 Pyspark Dataframe 的特定索引中添加行或替换?
- javascript - 身份服务器:在 Angular 中登录和注销后重定向?
- database - Terraform for Digital Ocean 托管数据库防火墙
- actions-on-google - Google Action 让麦克风在没有提示的情况下为用户命令打开
- vba - 在 VBA 中使用“And _”避免嵌套 IF
- azure - 如何在 Azure Active Directory 中设置服务原则显示名称