Move piwik code to a static JS asset

This commit is contained in:
Tom Hughes 2012-09-05 23:05:07 +01:00
parent 24453e7230
commit 7c0055b5d7
6 changed files with 30 additions and 15 deletions

View file

@ -6,6 +6,7 @@
//= require openlayers
//= require i18n/translations
//= require globals
//= require piwik
//= require browse
//= require export
//= require map

View file

@ -1,4 +1,8 @@
OSM = {
<% if defined?(PIWIK_LOCATION) and defined?(PIWIK_SITE) %>
PIWIK_LOCATION: <%= PIWIK_LOCATION.to_json %>,
PIWIK_SITE: <%= PIWIK_SITE.to_json %>,
<% end %>
MAX_REQUEST_AREA: <%= MAX_REQUEST_AREA.to_json %>,
SERVER_URL: <%= SERVER_URL.to_json %>,
API_VERSION: <%= API_VERSION.to_json %>

View file

@ -0,0 +1,21 @@
if (OSM.PIWIK_LOCATION && OSM.PIWIK_SITE) {
$(document).ready(function () {
var base = document.location.protocol + "//" + OSM.PIWIK_LOCATION + "/";
$.ajax({
url: base + "piwik.js",
dataType: "script",
cache: true,
success: function () {
var piwikTracker = Piwik.getTracker(base + "piwik.php", OSM.PIWIK_SITE);
piwikTracker.trackPageView();
piwikTracker.enableLinkTracking();
$("meta[name=piwik-goal]").each(function () {
piwikTracker.trackGoal($(this).attr("content"));
});
}
});
});
}