Piwik简介 Piwik Doc
- Piwik 是一套基于 Php+MySQL 技术构建,能够与 Google Analytics 相媲美的开源网站访问统计系统。Piwik 可以给你详细的统计信息,比如网页浏览人数, 访问最多的页面, 搜索引擎关键词等等,并且采用了大量的AJAX/Flash技术,使得在操作上更加便易。
- Piwik 可以安装在你的服务器上面,数据就保存在你自己的服务器上 面。你可以非常容易的插入统计图表到你的博客或是网站后台的控制面板中。安装完成后,你只需将一小段代码放到将要统计的网页中即可。
- 此外,它还采用了插件扩展及开放API架构,拥有众多不同功能的插件,也可以让开发人员根据自已的实际需求创建更多的功能。
Piwik 安装
- PHP + Apache 配置安装 Window下配置PHP环境
- 直接下载PHP集成安装环境 wampserver
如果是电子商务网站可以开启电子商务网站分析配置
通过js追踪 tracking-javascript-guide
通用代码
1 | <!-- Piwik --> |
改变文档标题
1 | _paq.push(['setDocumentTitle', document.domain + "/" + document.title]); |
事件点击
trackEvent(category, action, [name], [value])
1
2_paq.push(['trackEvent', 'Documentary', 'Rating', 'Thrive', 9.5]);
<a href="#" onclick="javascript:_paq.push(['trackEvent', 'Menu', 'Freedom']);">Freedom page</a>
电子商务 ecommerce-analytics
产品/类别访问
setEcommerceView( productSKU, productName, categoryName, price )
产品1
2
3
4
5
6
7
8
9
10[...]
// all parameters are optional, but we recommend to set at minimum productSKU and productName
_paq.push(['setEcommerceView',
"9780786706211", // (required) SKU: Product unique identifier
"Endurance: Shackleton's Incredible Voyage", // (optional) Product name
"Adventure Books", // (optional) Product category, or array of up to 5 categories
20.11 // (optional) Product Price as displayed on the page
]);
_paq.push(['trackPageView']);
[...]
类别1
2
3
4
5
6
7
8
9[...]
// on a category page, productSKU and productName are not applicable and are set to false
_paq.push(['setEcommerceView',
productSku = false, // No product on Category page
productName = false, // No product on Category page
category = "Adventure Books" // Category Page, or array of up to 5 categories
]);
_paq.push(['trackPageView']);
[...]
订单
addEcommerceItem(productSKU, productName, productCategory, price, quantity)
如果订单有多个产品需要循环调用trackEcommerceOrder(orderId, grandTotal, subTotal, tax, shipping, discount)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23[...]
// add the first product to the order
_paq.push(['addEcommerceItem',
"9780786706211", // (required) SKU: Product unique identifier
"Endurance: Shackleton's Incredible Voyage", // (optional) Product name
"Adventure Books", // (optional) Product category. You can also specify an array of up to 5 categories eg. ["Books", "New releases", "Biography"]
8.8, // (recommended) Product price
1 // (optional, default to 1) Product quantity
]);
// Here you can add other products in the order
[...]
// Specifiy the order details to Piwik server & sends the data to Piwik server
_paq.push(['trackEcommerceOrder',
"A10000123", // (required) Unique Order ID
35, // (required) Order Revenue grand total (includes tax, shipping, and subtracted discount)
30, // (optional) Order sub total (excludes shipping)
5.5, // (optional) Tax amount
4.5, // (optional) Shipping amount
false // (optional) Discount offered (set to false for unspecified parameter)
]);
// we recommend to leave the call to trackPageView() on the Order confirmation page
_paq.push(['trackPageView']);
[...]
购物车
TODO
站内搜索
TODO
自定义变量 custom-variables
setCustomVariable(index, name, value, scope = "visit")
1
2
3
4
5
6
7
8
9
10
11
12_paq.push(['setCustomVariable',
// Index, the number from 1 to 5 where this custom variable name is stored
1,
// Name, the name of the variable, for example: Gender, VisitorType
"Gender",
// Value, for example: "Male", "Female" or "new", "engaged", "customer"
"Male",
// Scope of the custom variable, "visit" means the custom variable applies to the current visit
"visit"
]);
_paq.push(['trackPageView']);
setCustomVariable(index, name, value, scope = "page")
1
2
3
4
5
6
7
8
9
10// Track 2 custom variables with the same name, but in different slots.
// You will then access the statistics about your articles' categories in the 'Visitors > custom variables' report
_paq.push(['setCustomVariable', 1, 'Category', 'Sports', 'page']);
// Track the same name but in a different Index
_paq.push(['setCustomVariable', 2, 'Category', 'Europe', 'page']);
// Here you could track other custom variables with scope "page" in Index 3, 4 or 5
// The order is important: first setCustomVariable is called and then trackPageView records the request
_paq.push(['trackPageView']);
设置UserID
1 | _paq.push(['setUserId', 'USER_ID_HERE']); |
设置Cookie
1 | _paq.push(['setSiteId', 1]); |
可以用于统计 某个品牌下产品的浏览数
Download & Outlink tracking
TODO
通过Http call 追踪
http://developer.piwik.org/guides/tracking-api-clients
可以使用其他语言调用api添加对应的统计信息
java https://github.com/piwik/piwik-java-tracker
通过log追踪
http://piwik.org/log-analytics/
Report
- 导出对应的图片
- 通过后台导出对应格式的数据 获得APIURL
http://developer.piwik.org/guides/querying-the-reporting-api - 直接生成对应的html代码 iframe
其他
- 中国地图信息及城市坐标问题
- 性能优化
- 个性插件
- 数据量的时候需要关闭实时统计需要根据定时器统计
- 官方名词解释
http://glossary.piwik.org/?language=zh-cn
Link
http://piwik.org/
http://developer.piwik.org/
http://piwik.org/docs/
http://demo.piwik.org/
http://www.piwik.cn/
百度文库
优化设置