google第三方代码跟踪ecshop订单

2010-08-06 14:42 来源:www.chinab4c.com 作者:admin

      ecshop订单的流程里面,可以考虑加入一些第三方的订单跟踪代码,多ecshop的流程进行追踪和统计,有利于ecshop网店的运营和销售。下面将结合google第三方跟踪代码来实际的和大家分享如何让代码和ecshop完美整合.   

  1:index.dwt
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', '帐户id']);
  _gaq.push(['_setDomainName', '域名']);
  _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>


2:flow.dwt
     <!--------------------google监视------------------>
  {if $order_goods_list}
  <script type="text/javascript">
 
  var _gaq = _gaq || [];

  _gaq.push(['_setAccount', 'UA-17817658-1']);
  _gaq.push(['_trackPageview']);
 /*
  _gaq.push(['_addItem',
    '1234',           // order ID - required
    'DD44',           // SKU/code - required
    'T-Shirt',        // product name
    'Green Medium',   // category or variation
    '11.99',          // unit price - required
    '1'               // quantity - required
  ]); */
  {foreach from = $order_goods_list item = item_google}
 
  _gaq.push(['_addItem',
    '{$order.order_sn}',           // order ID - required
    '件',           // SKU/code - required
    '{$item_google.goods_name}',        // product name
    '{$item_google.cat_name}',   // category or variation
    '{$item_google.goods_price}',          // unit price - required
    '{$item_google.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';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
 
</script>
   {/if}

  <!--------------------goodle监视------------------>


3:flow.php
/* 提供给google */
 $order_goods_list = $db -> getAll("select goods_id ,goods_name ,goods_number ,goods_price from  ".$ecs->table('order_goods')." where order_id = '".$order['order_id']."'");
 if($order_goods_list){
  
  foreach($order_goods_list as $k => $v){
   $order_goods_list[$k]['cat_name'] = $db -> getOne("select c.cat_name from ".$ecs->table('category')."c  , ".$ecs->table('goods')." g where g.cat_id = c.cat_id and g.goods_id = '".$v['goods_id']."'");
  }
  $smarty -> assign('order_goods_list', $order_goods_list);

 }

来源:http://www.chinab4c.com