Google analytics 坚持通过GTM添加GA标准电子商务交易
我们使用GTM将GA添加到我们的网站。GA中启用了标准电子商务跟踪。为了启动此项目,我正在使用相同GTM/GA帐户的开发环境中进行测试。GA中只显示来自实时站点的数据,因此会过滤掉DEV(我还不确定这是如何做到的)。我有两个问题Google analytics 坚持通过GTM添加GA标准电子商务交易,google-analytics,google-tag-manager,data-layers,Google Analytics,Google Tag Manager,Data Layers,我们使用GTM将GA添加到我们的网站。GA中启用了标准电子商务跟踪。为了启动此项目,我正在使用相同GTM/GA帐户的开发环境中进行测试。GA中只显示来自实时站点的数据,因此会过滤掉DEV(我还不确定这是如何做到的)。我有两个问题 我如何设置“transactionProducts”来循环购物车中的项目,并单独显示它们,而不是将所有项目放在一起 我该怎么做才能在开发站点的GA中看到结果?我不能现场测试,除非我在现场站点上创建一个带有虚假数据的noindex/nofollow静态页面,看看它是否会发
<script>
if(window.location.pathname == "/order/confirmorder"){
// capture values from the spans with the following classes
var GAtransactionId = jQuery(".lblOrderNumber").text();
var GAtransactionTotal = jQuery(".lblTotal").text();
var GAtransactionTax = jQuery(".lblTax").text();
var GAtransactionShipping = jQuery(".lblShippingHandling").text();
// transactionProducts data from the spans with the following classes
var GAsku = jQuery(".lblProductSKU").text();
var GAname = jQuery(".lblProductSKU").text();
var GAprice = jQuery(".lblYourPrice").text();
var GAquantity = jQuery(".lblOrderItemQty").text();
// Checking my variables before they go thru
alert("GAtransactionId: " + GAtransactionId + " GAtransactionTotal: " + GAtransactionTotal + " GAtransactionTax: " + GAtransactionTax + " GAtransactionShipping: " + GAtransactionShipping + " GAsku: " + GAsku + " GAname: " + GAname + " GAprice: " + GAprice + " GAquantity: " + GAquantity);
window.dataLayer = window.dataLayer || [];
dataLayer.push({
'transactionId': GAtransactionId,
'transactionTotal': GAtransactionTotal,
'transactionTax': GAtransactionTax,
'transactionShipping': GAtransactionShipping,
'transactionProducts': [{
'sku': GAsku, // returns each item - but smooshed together
'name': GAname, // returns each item - but smooshed together
'price': GAprice, // returns each item - but smooshed together
'quantity': GAquantity // returns each item - but smooshed together
}]
});
}
</script>
如何循环“transactionProducts”以分别显示购物车中的每个项目?我想for循环可以,但是我应该如何设置它,然后在哪里将它添加到数据层,这样它就不会破坏任何东西?另外,我是否需要从结果中删除“$”符号(我知道怎么做)
我在哪里可以找到一个过滤器来阻止来自开发人员站点的数据被发送-这样我可以在测试时暂时禁用它?我是否需要发布GTM标记/触发器以使其实际发送数据,或者我是否可以使用预览模式并期望在GA转换>电子商务>概述中看到数据层数据?您必须构建您的
项目
对象,通过购物车中的产品元素循环,而不是获取所有span
的组合文本值:
一些示例代码可能如下所示:
var items = []
$('.some-product-selector').each(function () {
items.push({
'sku': $(this).find('.lblProductSKU').text(),
'price': $(this).find('.lblYourPrice').text()
// the same pattern for other fields
})
})
// ...
dataLayer.push({
'transactionId': GAtransactionId,
'transactionTotal': GAtransactionTotal,
'transactionTax': GAtransactionTax,
'transactionShipping': GAtransactionShipping,
'transactionProducts': items // use your items here
});
有人因为我没有表现出研究的努力而责骂我。这就是一切开始的地方:。在那之后,谷歌搜索我的问题,把我带到了Simo Ahava的博客,优化智能博客,Analytics Mania和许多其他的帖子和StackOverflow文章,最终都没有解决这个问题。太棒了。您解决了问题一:如何循环购物车中的项目并发送数据。
var items = []
$('.some-product-selector').each(function () {
items.push({
'sku': $(this).find('.lblProductSKU').text(),
'price': $(this).find('.lblYourPrice').text()
// the same pattern for other fields
})
})
// ...
dataLayer.push({
'transactionId': GAtransactionId,
'transactionTotal': GAtransactionTotal,
'transactionTax': GAtransactionTax,
'transactionShipping': GAtransactionShipping,
'transactionProducts': items // use your items here
});