我有一个 angularjs SPA,想用 piwik 跟踪页面浏览量。我有以下设置:
索引.html:
<html>
...
<body>
<piwik site-id="{{settings.PiwikSiteId}}"></piwik>
...
<script type="text/javascript" src="//analytics.myserver.net/piwik.js"></script>
<script type="text/javascript" src="/scripts/dist/common.js"></script> <!-- includes app bootstrapping and directive -->
</body>
</html>
piwik 指令:
var _paq = _paq || [];
app.directive('piwik',
function() {
return {
restrict: 'E',
scope: {
siteId: '@'
},
controller: ['$scope', '$window', function($scope, $window) {
var piwikTrackingApiUrl = 'https://analytics.myserver.net/piwik.php';
_paq.push(['setTrackerUrl', piwikTrackingApiUrl]);
_paq.push(['setSiteId', $scope.siteId]);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
}]
}
});
应用程序.js
var app = angular.module('ncApp', ['infinite-scroll', 'ngRoute', ..., 'angulartics', 'angulartics.piwik', ...]);
在调试器中,我可以看到 _paq 被填充,但没有请求https://analytics.myserver.net/piwik.php