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>
|
最近更新
常用插件
- ecshop二次开发商品购买增
图片1香...
- ecshop最小购买数量控制插
ecshop最小购买数量控制插件,这个插件主要是为我们提供一个十分方便...
- ecshop2.7.1邮件发送插件
ecshop2.7.1邮件发送插件:该插件主要的开发思想是源于ecshop短信发送系统...
- ecshop没登陆情况下订单查
ecshop没登陆情况下订单查询插件,主要是针对ecshop在没有登陆的情况下...
- ecshop2.7.2生成虚拟订单2.
以前我们开发过ecshop下的虚拟订单,就是客户在访问的时候,会自动生...
ecshop热门问答
ecshop热门资料
ecshop免费网站
ecshop订单号
ecshop短信内容
ecshop商品销售数量
ecshop美国空间
ecshop电脑
ecshop切割
ecshop1000
ecshopseo
ecshop防盗
ecshop雪地
ecshop推荐管理
ecshop男士
红包插件
ecshop压缩包
ecshop更换
ecshopcolthing
ecshop产品评论
ecshop鉴定
ecshop禁止
ecshop缺货登记
ecshop团队合作
ecshop订单管理
ecshopMAI
ecshop大合唱
ecshop查看日志
ecshop显示价格
ecshopbad
ecshop对话
去ecshop版权