联系电话:0755-27515592
最新动态:

Magento教程

Magento添加Google转换代码

点击数:13582015-07-31 10:16:51 来源: 外贸网站建设,深圳外贸网站建设,深圳网站建设,外贸商城网站制作-亿恩科技

新闻摘要:Google analytics 转换 统计代码一般是加在订单成功页面.上面可以用Google Analytics进行转换率统计分析非常方便好使。 具体操作如下。下面有两种一种是商品统计,一种是订单金额统计 需要

Google analytics 转换 统计代码一般是加在订单成功页面.上面可以用Google Analytics进行转换率统计分析非常方便好使。

具体操作如下。下面有两种一种是商品统计,一种是订单金额统计

需要修改的文件为: app/design/frontend/default/你的模板/template/checkout/success.phtml

商品统计代码如下:

将UA-XXXXXXX-X替换成你的GA号码

<?php
$order1 = Mage::getModel(‘sales/order’)->load(Mage::getSingleton(‘checkout/session’)->getLastOrderId());

$subtotal = $order1->getSubtotal();
$order_id = $order1->getId(); //the id of the order
//$order->getIncrementId();//the increment id of the order
$gtotal = $order1->getGrandTotal();//grand total of the order

//print_r($order->getBillingAddress()->getData());
$address = $order1->getBillingAddress()->getData();
$city = $address['city'];
$state = $address['region'];
$country = $address['country_id'];
?>
<script type=”text/javascript”>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXX-X']);
_gaq.push(['_trackPageview']);
_gaq.push(['_addTrans',
'<?php echo $order_id; ?>', // order ID - required
'Aekk Website Store', // affiliation or store name
'<?php echo $gtotal;?>', // total - required
'0', // tax
'0', // shipping
'<?php echo $city;?>', // city
'<?php echo $state;?>', // state or province
'<?php echo $country;?>' // country
]);
<?php

function getCategoryName($cats){
$catlist=array();
foreach ($cats as $category_id) {
$_cat = Mage::getModel(‘catalog/category’)->load($category_id) ;
$catlist[]= $_cat->getName();
}
return end($catlist) ;
}

$order_items = $order1->getAllItems();
$itemcount=count($order_items);
$name=array();
$unitPrice=array();
$sku=array();
$ids=array();
$qty=array();
foreach ($order_items as $key => $item)
{
if($item->getPrice()>0){

$cat_ids=Mage::getModel(“catalog/product”)->load( $item->getProductId())->getCategoryIds();
$CategoryName=getCategoryName($cat_ids); //get 分类名称

?>
_gaq.push(['_addItem',
'<?php echo $order_id; ?>', // order ID - required
'<?php echo $item->getSku(); ?>', // SKU/code - required
'<?php echo $item->getName(); ?>', // product name
'<?php echo $CategoryName; ?>', // category or variation
'<?php echo $item->getPrice(); ?>', // unit price - required
'<?php echo $item->getQtyToInvoice(); ?>', // quantity - required
'currencyCode': '<?php echo $order1->getOrderCurrencyCode();?>' // Order Currency Code

]);
<?php
}
}
?>
_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 Code for &#19979;&#21333; Conversion Page –>
<script type=”text/javascript”>
/* <![CDATA[ */
var google_conversion_id = 0000000; //转换ID
var google_conversion_language = "en";
var google_conversion_format = "2";
var google_conversion_color = "ffffff";
var google_conversion_label = "m_CBCOeOnwUQgbio1wM";//转换标签
var google_conversion_value = 100;//金额
/* ]]> */
</script>
<script type=”text/javascript” src=”https://www.googleadservices.com/pagead/conversion.js”>
</script>
<noscript>
<div style=”display:inline;”>
<img height=”1″ width=”1″ style=”border-style:none;” alt=”” src=”https://www.googleadservices.com/pagead/conversion/转换ID/?value=金额 &amp;label=转换标签&amp;guid=ON&amp;script=0″/>
</div>
</noscript>

【责任编辑:(Top) 返回页面顶端
贴心
全国7×24小时客服热线
安全
病毒杀除率高于99%
稳定
网站可用性高于99.9%
实力
服务68家上市企业及集团公司
亿恩科技手机站
关注亿恩科技微信

亿恩科技—企业信息化一站式服务专家


Copyright © 2008- 深圳市亿恩科技有限公司版权所有 粤ICP备15056041号

联系我们 | 常见问题 | 在线留言 | 支付方式 | 软件开发 | 我的观点 | 资质荣誉 | 服务流程