[关闭]
@dzhai 2015-11-10T12:42:45.000000Z 字数 5042 阅读 2545

Piwik

piwik


Piwik简介 Piwik Doc

  1. Piwik 是一套基于 Php+MySQL 技术构建,能够与 Google Analytics 相媲美的开源网站访问统计系统。Piwik 可以给你详细的统计信息,比如网页浏览人数, 访问最多的页面, 搜索引擎关键词等等,并且采用了大量的AJAX/Flash技术,使得在操作上更加便易。
  2. Piwik 可以安装在你的服务器上面,数据就保存在你自己的服务器上 面。你可以非常容易的插入统计图表到你的博客或是网站后台的控制面板中。安装完成后,你只需将一小段代码放到将要统计的网页中即可。
  3. 此外,它还采用了插件扩展及开放API架构,拥有众多不同功能的插件,也可以让开发人员根据自已的实际需求创建更多的功能。

Piwik 安装

  1. PHP + Apache 配置安装 Window下配置PHP环境
  2. 直接下载PHP集成安装环境 wampserver

如果是电子商务网站可以开启电子商务网站分析配置

通过js追踪 tracking-javascript-guide

通用代码

  1. <!-- Piwik -->
  2. <script type="text/javascript">
  3. var _paq = _paq || [];
  4. _paq.push(['trackPageView']);
  5. _paq.push(['enableLinkTracking']);
  6. (function() {
  7. var u="//piwik.maxtp.cn/";
  8. _paq.push(['setTrackerUrl', u+'piwik.php']);
  9. _paq.push(['setSiteId', 1]);
  10. var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
  11. g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
  12. })();
  13. </script>
  14. <noscript><p><img src="//piwik.maxtp.cn/piwik.php?idsite=1" style="border:0;" alt="" /></p></noscript>
  15. <!-- End Piwik Code -->

改变文档标题

  1. _paq.push(['setDocumentTitle', document.domain + "/" + document.title]);
  2. _paq.push(['trackPageView']);

事件点击

trackEvent(category, action, [name], [value])

  1. _paq.push(['trackEvent', 'Documentary', 'Rating', 'Thrive', 9.5]);
  2. <a href="#" onclick="javascript:_paq.push(['trackEvent', 'Menu', 'Freedom']);">Freedom page</a>

电子商务 ecommerce-analytics

产品/类别访问

setEcommerceView( productSKU, productName, categoryName, price )
产品

  1. [...]
  2. // all parameters are optional, but we recommend to set at minimum productSKU and productName
  3. _paq.push(['setEcommerceView',
  4. "9780786706211", // (required) SKU: Product unique identifier
  5. "Endurance: Shackleton's Incredible Voyage", // (optional) Product name
  6. "Adventure Books", // (optional) Product category, or array of up to 5 categories
  7. 20.11 // (optional) Product Price as displayed on the page
  8. ]);
  9. _paq.push(['trackPageView']);
  10. [...]

类别

  1. [...]
  2. // on a category page, productSKU and productName are not applicable and are set to false
  3. _paq.push(['setEcommerceView',
  4. productSku = false, // No product on Category page
  5. productName = false, // No product on Category page
  6. category = "Adventure Books" // Category Page, or array of up to 5 categories
  7. ]);
  8. _paq.push(['trackPageView']);
  9. [...]

订单

addEcommerceItem(productSKU, productName, productCategory, price, quantity)
如果订单有多个产品需要循环调用
trackEcommerceOrder(orderId, grandTotal, subTotal, tax, shipping, discount)

  1. [...]
  2. // add the first product to the order
  3. _paq.push(['addEcommerceItem',
  4. "9780786706211", // (required) SKU: Product unique identifier
  5. "Endurance: Shackleton's Incredible Voyage", // (optional) Product name
  6. "Adventure Books", // (optional) Product category. You can also specify an array of up to 5 categories eg. ["Books", "New releases", "Biography"]
  7. 8.8, // (recommended) Product price
  8. 1 // (optional, default to 1) Product quantity
  9. ]);
  10. // Here you can add other products in the order
  11. [...]
  12. // Specifiy the order details to Piwik server &amp; sends the data to Piwik server
  13. _paq.push(['trackEcommerceOrder',
  14. "A10000123", // (required) Unique Order ID
  15. 35, // (required) Order Revenue grand total (includes tax, shipping, and subtracted discount)
  16. 30, // (optional) Order sub total (excludes shipping)
  17. 5.5, // (optional) Tax amount
  18. 4.5, // (optional) Shipping amount
  19. false // (optional) Discount offered (set to false for unspecified parameter)
  20. ]);
  21. // we recommend to leave the call to trackPageView() on the Order confirmation page
  22. _paq.push(['trackPageView']);
  23. [...]

购物车

TODO

站内搜索

TODO

自定义变量 custom-variables

setCustomVariable(index, name, value, scope = "visit")

  1. _paq.push(['setCustomVariable',
  2. // Index, the number from 1 to 5 where this custom variable name is stored
  3. 1,
  4. // Name, the name of the variable, for example: Gender, VisitorType
  5. "Gender",
  6. // Value, for example: "Male", "Female" or "new", "engaged", "customer"
  7. "Male",
  8. // Scope of the custom variable, "visit" means the custom variable applies to the current visit
  9. "visit"
  10. ]);
  11. _paq.push(['trackPageView']);

setCustomVariable(index, name, value, scope = "page")

  1. // Track 2 custom variables with the same name, but in different slots.
  2. // You will then access the statistics about your articles' categories in the 'Visitors &gt; custom variables' report
  3. _paq.push(['setCustomVariable', 1, 'Category', 'Sports', 'page']);
  4. // Track the same name but in a different Index
  5. _paq.push(['setCustomVariable', 2, 'Category', 'Europe', 'page']);
  6. // Here you could track other custom variables with scope "page" in Index 3, 4 or 5
  7. // The order is important: first setCustomVariable is called and then trackPageView records the request
  8. _paq.push(['trackPageView']);

设置UserID

  1. _paq.push(['setUserId', 'USER_ID_HERE']);
  2. _paq.push(['trackPageView']);

设置Cookie

  1. _paq.push(['setSiteId', 1]);
  2. _paq.push(['setTrackerUrl', u+'piwik.php']);
  3. // Same cookie as: example.com, www.example.com, subdomain.example.com, ...
  4. _paq.push(['setCookieDomain', '*.example.com']);
  5. _paq.push(['setDomains', '*.example.com']); // Download & Click tracking alias domains
  6. _paq.push(['trackPageView']);

可以用于统计 某个品牌下产品的浏览数

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

  1. 导出对应的图片
  2. 通过后台导出对应格式的数据 获得APIURL
    http://developer.piwik.org/guides/querying-the-reporting-api
  3. 直接生成对应的html代码 iframe

其他

  1. 中国地图信息及城市坐标问题
  2. 性能优化
  3. 个性插件
  4. 数据量的时候需要关闭实时统计需要根据定时器统计
  5. 官方名词解释
    http://glossary.piwik.org/?language=zh-cn

http://piwik.org/
http://developer.piwik.org/
http://piwik.org/docs/
http://demo.piwik.org/
http://www.piwik.cn/
百度文库
优化设置

GitHub

piwik_demo

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注