我在网站布局中加入了Google Analytics跟踪功能,因此可以跟踪每个网页。
<script>
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date(); a = s.createElement(o),
m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-XXXXX-YY', 'none');
ga('send', 'pageview');
</script>
我想在购买完成后的最后一个感谢页面中包含电子商务跟踪脚本。
<script>
ga('ecommerce:addTransaction', {
'id': '<%:order.DocumentNo%>', // Transaction ID. Required.
'revenue': '<%:order.TotalOrderPriceWithVat%>', // Grand Total.
'shipping': '<%:order.TotalTransportPrice %>', // Shipping.
'tax': '0' // Tax.
});
<
ga('ecommerce:addItem', {
'id': '<%:order.DocumentNo %>', // Transaction ID. Required.
'name': '<%:item.ProductDescription %>' +' '+ '<%:item.BrandName%>', // Product name. Required.
'sku': '<%:item.Item_Id %>', //Item ID
'category': '<%:item.CustomData %>', // Category or variation.
'price': '<%:item.OrderPriceWithVat %>', // Unit price.
'quantity': '<%:item.Quantity %>' // Quantity.
});
</script>
问题是在最后一页我得到错误 ga未定义
答案 0 :(得分:2)
跟踪综合浏览量
<script>
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date(); a = s.createElement(o),
m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-XXXXXXX-YYY', 'none');
ga('send', 'pageview');
跟踪交易
<script>
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date(); a = s.createElement(o),
m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-XXXXXXX-YYY', 'none');
ga('require', 'ecommerce'); // load ecommerce plugin
ga('send', 'pageview');
ga('ecommerce:addTransaction', {
'id': '<%:order.DocumentNo%>', // Transaction ID. Required.
'revenue': '<%:order.TotalOrderPriceWithVat%>', // Grand Total.
'shipping': '<%:order.TotalTransportPrice %>', // Shipping.
'tax': '0' // Tax.
});
ga('ecommerce:addItem', {
'id': '<%:order.DocumentNo %>', // Transaction ID. Required.
'name': '<%:item.ProductDescription %>' +' '+ '<%:item.BrandName%>', // Product name. Required.
'sku': '<%:item.Item_Id %>', //Item ID
'category': '<%:item.CustomData %>', // Category or variation.
'price': '<%:item.OrderPriceWithVat %>', // Unit price.
'quantity': <%:item.Quantity %> // Quantity.
});
ga('ecommerce:send'); // track transaction
https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce