首页 > 解决方案 > 谷歌分析标签管理器电子商务数据层未发送

问题描述

我正在尝试使用 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

  1. 调用 GTM
  2. 调用分析
  3. 发送基本跟踪数据

我的电子商务数据似乎没有发送,我在对分析服务器的网络调用中看不到它们,而且我在 Google Analytics 上没有数据

标签: google-analyticsgoogle-tag-manager

解决方案


我能说的:

  • 默认情况下dataLayer.push不会在任何地方发送数据,它只是提供数据层。您需要 GTM 触发器和标签来发送数据,这将我带到了下一点
  • 您的某些呼叫中缺少eventdataLayer.push(例如):我知道您正在遵循GTM ecom 规范purchase中给出的示例,但 IMO 令人困惑:其中一些显示基于事件的集合(带有键集),其他基于浏览量的集合(没有密钥集)。为了简化您的设置,您应该: eventevent
  • 完整设置:一旦您event在所有 dataLayer 调用上都有一个属性,您就可以使用类似于下面显示的设置来一般地跟踪它们(您应该将触发器更改为匹配所有电子商务事件的正则表达式,也不要忘记在 GA 设置中启用增强型电子商务)。

    在此处输入图像描述

  • 如果问题仍然存在,您应该启用GTM 预览/调试,它会告诉您为什么某些标签没有触发,并会显示它包含的 dataLayer 值的调试

  • 如果 GTM 确认标签正在触发,但您没有在网络上看到 GA 跟踪,则您需要使用Chrome GA 调试器,它会详细显示正在发生的事情以及未发送命中的可能原因。

  • 完成所有故障排除并正常工作后,不要忘记发布 GTM


推荐阅读