我刚刚将Google Analytics升级到Google Universal Analytics。
我的电子商务跟踪是否应该发生变化?
脚本在下面 - 省略了一些插入数据的专有代码,但我确定你得到了要点。
<!-- google receipt begin -->
<script language="JavaScript" type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-1']);
_gaq.push(['_trackPageview']);
_gaq.push(['_addTrans',
"", // order ID - required
"", // affiliation or store name
"", // total - required
"", // tax
"", // shipping
"", // city
"", // state or province
"" // country
]);
// add item might be called for every item in the shopping cart
// where your ecommerce engine loops through each item in the cart and
// prints out _addItem for each
_gaq.push(['_addItem',
"", // order ID - necessary to associate item with transaction
"", // SKU/code - required
"", // product name
"", // category or variation
"", // unit price - required
"" // quantity - required
]);
_gaq.push(['_trackTrans']); //submits transaction to the analytics servers
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<!-- google receipt end -->
答案 0 :(得分:2)
Google的文档是 Ecommerce Tracking - Web Tracking (analytics.js)
代码应如下所示:
// Create the tracker
ga('create', 'UA-XXXXX-Y');
// Fire off a pageview
ga('send', 'pageview');
// Include the ecommerce plugin
ga('require', 'ecommerce', 'ecommerce.js');
// Initialize the transaction
ga('ecommerce:addTransaction', {
id: '1234abc', // Transaction ID*
affiliation: 'Tech Shirts', // Store Name
revenue: '52.19', // Total
shipping: '10', // Shipping
tax: '3.22' // Tax
});
// Add a few items
ga('ecommerce:addItem', {
id: '1234abc', // Transaction ID*
sku: 'TSHIRT-12A', // Product SKU
name: 'Analytics Wizard', // Product Name*
category: 'Men\'s Shirts', // Product Category
price: '12.99', // Price
quantity: '1' // Quantity
});
ga('ecommerce:addItem', {
id: '1234abc', // Transaction ID*
sku: 'TSHIRT-36B', // Product SKU
name: 'Best Developer', // Product Name*
category: 'Women\'s Shirts', // Product Category
price: '12.99', // Price
quantity: '2' // Quantity
});
// Send off the transaction
ga('ecommerce:send');
@MisterPhilip有nice blog post将您的电子商务跟踪从Google Analytics迁移到Universal Analytics。