Move piwik code to a static JS asset
This commit is contained in:
parent
24453e7230
commit
7c0055b5d7
6 changed files with 30 additions and 15 deletions
|
@ -6,6 +6,7 @@
|
|||
//= require openlayers
|
||||
//= require i18n/translations
|
||||
//= require globals
|
||||
//= require piwik
|
||||
//= require browse
|
||||
//= require export
|
||||
//= require map
|
||||
|
|
|
@ -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 %>
|
||||
|
|
21
app/assets/javascripts/piwik.js
Normal file
21
app/assets/javascripts/piwik.js
Normal 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"));
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue