ECShop安装Piwik脚本进行跟踪功能测试

2016-09-07 22:02 来源:www.chinab4c.com 作者:ecshop专家

1、所有页面的pv跟踪
 
修改/ecshop/themes/default/library的page_footer.lbi ,在<meta>标签下面加入
 
<script type="text/javascript">  
   var _paq = _paq || [];  
    var a = document.getElementById("ECS_MEMBERZONE").getElementsByTagName("font");  
    var username="";  
    if(a.length>1)  
    {  
     if(window.navigator.userAgent.toLowerCase().indexOf("firefox")!=-1){  
      username=a[1].textContent;  
     } else{  
      username=a[1].innerText;  
      }  
      _paq.push(['setUserId',username]);  
    }  
    (function(){ var u=(("https:" == document.location.protocol) ? "https://xxxxx:8080/tracking/" : "http://xxxxx:8080/tracking/");  
    _paq.push(['setSiteId', "XXXXXX"]);  
    _paq.push(['trackPageView']);  
    _paq.push(['setTrackerUrl', u+'js']);  
    _paq.push(['enableLinkTracking']);  
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript'; g.defer=true; g.async=true; g.src=u+'piwik.js';  
    s.parentNode.insertBefore(g,s); })();  
</script>  
 
这样每个页面请求都能发送pv请求到piwik服务端
2、注册跟踪
修改ecshop/user.php,在注册成功事件后面(大概是240行下面)调用下面的脚本
 
echo "<script type='text/javascript'>  
 var _paq = _paq  || [];  
(function(){ var u=(('https:' == document.location.protocol) ? 'https://xxxxx:8080/tracking/': 'http://xxxxx:8080/tracking/');  
_paq.push(['setSiteId', 'XXXXX']);  
_paq.push(['trackPageView']);  
_paq.push(['setTrackerUrl', u+'js']);  
_paq.push(['enableLinkTracking']);  
_paq.push(['trackGoal', 1, 0.01,$username]);  
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript'; g.defer=true; g.async=true; g.src=u+'piwik.js';  
s.parentNode.insertBefore(g,s); })();  
        </script>";  
注册事件可以用目标转化跟踪实现,_paq.push(['trackGoal', 1, 0.01,$username]);第一个参数是事件的名称,第二个是目标id,需要在后端配置id对应的转化目标的含义,第三个参数是本次转化的价值,第四个是自定义参数,可以传递数字或是字符串,本场景用来传递用户名,usename变量即是注册用户的用户名。
3、产品目录页跟踪
 
在/ecshop/themes/default/category.dwt末尾加入如下脚本
 
 
<script type="text/javascript">  
var tags=document.getElementById("ur_here").getElementsByTagName("a");  
var category_name='';  
if(window.navigator.userAgent.toLowerCase().indexOf("firefox")!=-1){  
    category_name=tags[tags.length-1].textContent;  
} else{  
    category_name=tags[tags.length-1].innerText;  
}  
var _paq = _paq || [];  
(function(){ var u=(("https:" == document.location.protocol) ? "https://xxxxx:8080/tracking/" : "http://xxxxxx:8080/tracking/");  
_paq.push(['setSiteId', "X0000001"]);  
_paq.push(['setTrackerUrl', u+'js']);  
_paq.push(['enableLinkTracking']);  
//_paq.push(['trackEcommerceOrder',"C10000123", 35,30,5.5,4.5,false]);  
_paq.push(['setEcommerceView',productSku=false,productName =false,category=category_name]);//_paq.push(['setEcommerceView',false,false,category_name]);  
_paq.push(['trackPageView']);  
 var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript'; g.defer=true; g.async=true; g.src=u+'piwik.js';  
 s.parentNode.insertBefore(g,s); })();  
 </script>  
 
4、产品页跟踪
 
在加入/ecshop/themes/default/goods.dwt
 
 
<script type="text/javascript">  
var goods_sn="{$goods.goods_sn}";  
var goods_name="{$goods.goods_style_name}";  
var goods_price="{$goods.shop_price_formated}".replace("¥","").replace("元","");  
var tags=document.getElementById("ur_here").getElementsByTagName("a");  
var categorys=[];  
for(var i=0;i<tags.length;i++)  
{  
if(window.navigator.userAgent.toLowerCase().indexOf("firefox")!=-1){  
categorys[i]=tags[i].textContent;  
} else{  
categorys[i]=tags[i].innerText;  
}  
}  
var _paq = _paq || [];  
(function(){ var u=(("https:" == document.location.protocol) ? "https://xxxxx:8080/tracking/" : "http://xxxxx:8080/tracking/");  
_paq.push(['setSiteId', "X0000001"]);  
_paq.push(['setTrackerUrl', u+'js']);  
_paq.push(['enableLinkTracking']);  
_paq.push(['setEcommerceView',goods_sn,goods_name,categorys,goods_price]);  
_paq.push(['trackPageView']);  
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript'; g.defer=true; g.async=true; g.src=u+'piwik.js';  
s.parentNode.insertBefore(g,s); })();  
  
</script>  
 
 
5、购物车,订单详情和订单完成跟踪
 
在/ecshop/themes/default/flow.dwt末尾加入
 
 
<script type="text/javascript">  
var goods_list="{$goods_list}";  
var _paq = _paq || [];  
var total=0;  
if("{$step}"=="cart")//购物车  
{  
{foreach from=$goods_list item=goods}//遍历产品列表  
_paq.push(['addEcommerceItem',  
"{$goods.goods_id}", // (required) SKU: Product unique identifier  
"{$goods.goods_name}", // (optional) Product name  
false, // (optional) Product category, string or array of up to 5 categories  
"{$goods.goods_price}".replace("¥","").replace("元",""),  
"{$goods.goods_number}" // (optional, default to 1) Product quantity  
]);  
total+="{$goods.goods_price}".replace("¥","").replace("元","")*"{$goods.goods_number}";  
// Records the cart for this visit  
{/foreach}  
_paq.push(['trackEcommerceCartUpdate',total]);   
}  
else if("{$step}"=="checkout")//订单明细  
{  
{foreach from=$goods_list item=goods}  
_paq.push(['addEcommerceItem',  
"{$goods.goods_id}", // (required) SKU: Product unique identifier  
"{$goods.goods_name}", // (optional) Product name  
false, // (optional) Product category, string or array of up to 5 categories  
"{$goods.goods_price}".replace("¥","").replace("元",""),  
"{$goods.goods_number}" // (optional, default to 1) Product quantity  
]);  
{/foreach}  
}  
else if("{$step}"=="done")//下单完成  
{  
_paq.push(['trackEcommerceOrder',  
"{$order.order_sn}", // (required) Unique Order ID  
"{$total.amount_formated}".replace("¥","").replace("元",""), // (required) Order Revenue grand total (includes tax, shipping, and subtracted discount)  
false, // (optional) Order sub total (excludes shipping)  
false, // (optional) Tax amount  
false, // (optional) Shipping amount  
false // (optional) Discount offered (set to false for unspecified parameter)  
]);  
}  
  
(function(){ var u=(("https:" == document.location.protocol) ? "https://xxxxx:8080/tracking/" : "http://xxxxx:8080/tracking/");  
_paq.push(['setSiteId', "X0000001"]);  
_paq.push(['setTrackerUrl', u+'js']);  
_paq.push(['enableLinkTracking']);  
_paq.push(['trackPageView']);  
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript'; g.defer=true; g.async=true; g.src=u+'piwik.js';  
s.parentNode.insertBefore(g,s); })();  
</script>  
 
(责任编辑:chinab4c)