构建单页/胖客户端应用程序,我想知道使用http://piwik.org/包含和跟踪的最佳实践是什么
我想以一种架构合理的方式使用 Piwik,并且将来可以用不同的库替换。
使用 Piwik 进行跟踪似乎有两个基本选项:
- 用命令填充一个全局
_paq
数组,然后加载脚本(我不清楚如何记录未来的“页面”视图或更改变量) - 获取和使用
var myTracker = Piwik.getTracker()
_paq
方法:
myApp.loadAnalytics = function() { /* dynamically insert piwik.php script */ }
myApp.track = function(pageName) {
window._paq = window._paq || [];
_paq.push(['setDocumentTitle', pageName]);
_paq.push(["trackPageView"]);
}
myApp.loadAnalytics()
// Then, anywhere in the application, and as many times as I want (I hope :)
myApp.track('reports/eastWing') // Track a "page" change, lightbox event, or anything else
.getTracker()
方法:
myApp.loadAnalytics = function() { /* dynamically insert piwik.php script */ }
myApp.track = function(pageName) {
myApp.tracker = myApp.tracker || Piwik.getTracker('https://mysite.com', 1);
myApp.tracker.trackPageView(pageName);
}
myApp.loadAnalytics()
// Then, anywhere in the application, and as many times as I want (I hope :)
myApp.track('reports/eastWing') // Track a "page" change, lightbox event, or anything else
这些方法在功能上是否相同?对于单页应用程序,一个比另一个更受欢迎吗?