h5ai/src/_h5ai/js/inc/ext/piwik-analytics.js
2012-09-14 15:32:33 +02:00

33 lines
805 B
JavaScript
Executable file

modulejs.define('ext/piwik-analytics', ['_', '$', 'core/settings'], function (_, $, allsettings) {
var defaults = {
enabled: false,
baseURL: 'not-set',
idSite: 0
},
settings = _.extend({}, defaults, allsettings['piwik-analytics']),
init = function () {
if (!settings.enabled) {
return;
}
// reference: http://piwik.org/docs/javascript-tracking/
var pkBaseURL = (("https:" === document.location.protocol) ? "https://" : "http://") + settings.baseURL + '/';
$('<script/>').attr('src', pkBaseURL + 'piwik.js').appendTo('body');
$(window).load(function () {
/*global Piwik */
var piwikTracker = Piwik.getTracker(pkBaseURL + 'piwik.php', settings.idSite);
piwikTracker.trackPageView();
piwikTracker.enableLinkTracking();
});
};
init();
});