我已在Magento网站的订单确认页面中添加了以下脚本,但仍然无法跟踪电子商务数据。请帮助我在Google Analytics(分析)中跟踪电子商务数据。
<script async src="https://www.googletagmanager.com/gtag/js?id=UA 000000000-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
dataLayer.push({
'thansactionId' : '<?php echo $orderId; ?>',
'currency': 'GBP',
'event' : 'conversion',
'Grandtotal': '<?php echo $grandtotal; ?>',
'status': '<?php echo "$status";?>',
'storename': '<?php echo "$storename";?>',
'shippingmethod': '<?php echo "$shipping";?>',
'shippinamount': '<?php echo "$shippingamount";?>'
});
</script>
我没有使用Google跟踪代码管理器,因此我只希望该解决方案适用于Google Analytics(分析)。
答案 0 :(得分:0)
您没有使用Google跟踪代码管理器(GTM),但正在使用GTM的数据格式。根据{{3}},gtag()的(标准电子商务)交易跟踪代码如下:
gtag('event', 'purchase', {
"transaction_id": "24.031608523954162",
"affiliation": "Google online store",
"value": 23.07,
"currency": "USD",
"tax": 1.24,
"shipping": 0,
"items": [
{
"id": "P12345",
"name": "Android Warhol T-Shirt",
"list_name": "Search Results",
"brand": "Google",
"category": "Apparel/T-Shirts",
"variant": "Black",
"list_position": 1,
"quantity": 2,
"price": '2.0'
},
{
"id": "P67890",
"name": "Flame challenge TShirt",
"list_name": "Search Results",
"brand": "MyBrand",
"category": "Apparel/T-Shirts",
"variant": "Red",
"list_position": 2,
"quantity": 1,
"price": '3.0'
}
]
});
您可以从PHP代码中填写变量,还可以选择包括产品数据。
增强的电子商务格式可用GTAG documentation。
答案 1 :(得分:0)
经过数小时的研究,我发现以下脚本适用于我的案例,因为我在网站上使用analytics.js。让我知道它是否正确?
<script type="text/javascript">
(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-35506203-1', 'auto');
ga('require', 'displayfeatures');
ga('send', 'pageview');
ga('require', 'ecommerce');
ga('ecommerce:addTransaction', {
'id': '1234', // Transaction ID. Required.
'affiliation': 'Acme Clothing', // Affiliation or store name.
'revenue': '11.99', // Grand Total.
'shipping': '5', // Shipping.
'tax': '1.29' // Tax.
'currency': 'GBP' // local currency code.
});
ga('ecommerce:addItem', {
'id': '1234', // Transaction ID. Required.
'name': 'Fluffy Pink Bunnies', // Product name. Required.
'sku': 'DD23444', // SKU/code.
'price': '11.99', // Unit price.
'quantity': '1' // Quantity.
});
ga('ecommerce:send');
</script>