EC-CUBEのカスタマイズ その1 Google Analytics
今、EC-CUBEで通販サイトを作っていますが、いろいろと触ったりしたことのカスタマイズの備忘録として記録しておきます。
Google Analyticsの設定
site_frame.phpを変更
</head> の前当たりに以下を入れました
<!-- Google Analytics E-Commerce -->
<!--{if $smarty.server.PHP_SELF == "`$smarty.const.ROOT_URLPATH`shopping/complete.php"}-->
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxxxxx-x']);
_gaq.push(['_trackPageview']);
_gaq.push(['_addTrans',
'<!--{$arrGAOrder.order_id}-->', // order ID - Required!!
'', // affiliation or store name
'<!--{$arrGAOrder.total}-->', // total - Required!!
'', // tax
'', // shipping
'<!--{$arrGAOrder.order_addr01}-->', // state or province
'<!--{$arrPref[$arrGAOrder.order_pref]}-->', // city
'', // 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
<!--{section name=cnt loop=$arrGAOrderDetail}-->
_gaq.push(['_addItem',
'<!--{$arrGAOrder.order_id}-->', // order ID - Required!!
'<!--{$arrGAOrderDetail[cnt].product_id}-->', // SKU/code - Required!!
'<!--{$arrGAOrderDetail[cnt].product_name}-->', // product name
'<!--{$arrGAOrderDetail[cnt].classcategory_name1}-->', // category or variation
'<!--{$arrGAOrderDetail[cnt].price}-->', // unit price - Required!!
'<!--{$arrGAOrderDetail[cnt].quantity}-->' // quantity - Required!!
]);
<!--{/section}-->
_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>
<!--{else}-->
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxxxx-x']);
_gaq.push(['_trackPageview']);
(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>
<!--{/if}-->
<!-- Google Analytics E-Commerce END -->