Google Analytics 谷歌分析的电子商务功能很强大,可以跟踪出每个订单的金额,转换,转换来源,交易数量,交易金额,可以帮助网站管理者对于订单交易等有更多维度的理解和进一步作优化。
对于ecshop 如何实施这段analytics的电子商务代码呢?
其实谷歌分析的帮助中心给出了很详细的解释:http://code.google.com/apis/analytics/docs/tracking/gaTrackingEcommerce.html
然而在ecshop中添加还需要对于ecshop的代码有所了解。
添加有2种方式,
我使用的是第一种。修改themes下面的flow.dwt 文件在判断是否提交订单成功 <!– {if $step eq “done”} –> 的后面加上下面的代码。
下面的代码只需要把UA-xxxxxx-x 换成你自己的Analytics 数字即可。
<script type=”text/javascript”>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxx-x']);
_gaq.push(['_trackPageview']);
_gaq.push(['_addTrans',
'<!--{$order.order_sn}-->', // order ID - required
'<!--{$order.parent_id}', // affiliation or store name
'<!--{$order.goods_amount}-->', // total - required
'0', // tax
'<!--{$order.shipping_fee}-->', // shipping
'<!--{$order.city}|{$order.district}-->', // city
'<!--{$order.province}-->', // state or province
'<!--{$order.country}-->' // 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
<!–{foreach from=$goods_list item=goods}–>
_gaq.push(['_addItem',
'<!--{$order.order_sn}-->', // order ID - required
'<!--{$goods.goods_sn}-->', // SKU/code - required
'<!--{$goods.goods_name}-->', // product name
'<!--{$goods.goods_id}-->', // category or variation
'<!--{$goods.goods_pric}-->', // unit price - required
'<!--{$goods.goods_number}-->' // quantity - required
]);
<!–{/foreach}–>
_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’;
(document.getElementsByTagName(‘head’)[0] || document.getElementsByTagName(‘body’)[0]).appendChild(ga);
})();
</script>
-茉莉有香原创 转载请注明
RSS Feed
Twitter
Posted in
Tags: