Fixes piwik-analytics extension.

This commit is contained in:
Lars Jung 2012-09-14 15:32:33 +02:00
parent 9d8552a272
commit 1aec23008e
3 changed files with 36 additions and 41 deletions

View file

@ -53,8 +53,7 @@ Run `makejs -t` to list all possible targets.
* localization now in separate files
* updates translations
* adds `he` translation by [Tomer Cohen](https://github.com/tomer)
* updates [jQuery](http://jquery.com) to 1.8.0
* updates [HTML5 ★ Boilerplate](http://html5boilerplate.com) to 4.0.0
* updates 3rd party libs
### v0.21 - *2012-08-06*

View file

@ -195,10 +195,11 @@ var H5AI_CONFIG = {
/* [all]
Adds Piwik tracker javascript code.
baseURL without protocol
*/
"piwik-analytics": {
"enabled": false,
"baseURL": "mydomain.tld/piwik", /* no protocol */
"baseURL": "mydomain.tld/piwik",
"idSite": 1
},

View file

@ -1,38 +1,33 @@
modulejs.define('ext/piwik-analytics', ['_', 'core/settings'], function (_, allsettings) {
var defaults = {
enabled: false,
"baseURL": "not-set",
"idSite": 0
},
template = function(baseURL, idSite) {
return '<script type="text/javascript">
var pkBaseURL = (("https:" == document.location.protocol) ? "https://'+baseURL+'" : "http://'+baseURL+'");
document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
</script><script type="text/javascript">
try {
var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", '+idSite+');
piwikTracker.trackPageView();
piwikTracker.enableLinkTracking();
} catch( err ) {}
</script><noscript><p><img src="http://analytics.bluepyth.fr/piwik.php?idsite='+idSite+'" style="border:0" alt="" /></p></noscript>'
}
settings = _.extend({}, defaults, allsettings['piwik-analytics']),
init = function () {
if (!settings.enabled) {
return;
}
var $body = $('body');
$body.append(template(settings.baseURL, settings.idSite));
};
init();
});
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();
});