X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/7c0055b5d71ed5be84998843cbc9b082d5ded2c5..9f7ec064e448a745e0ea2615a089f0988215dec6:/app/assets/javascripts/piwik.js diff --git a/app/assets/javascripts/piwik.js b/app/assets/javascripts/piwik.js index d0443ae6d..5353a99ac 100644 --- a/app/assets/javascripts/piwik.js +++ b/app/assets/javascripts/piwik.js @@ -1,21 +1,32 @@ -if (OSM.PIWIK_LOCATION && OSM.PIWIK_SITE) { +if (OSM.PIWIK) { $(document).ready(function () { - var base = document.location.protocol + "//" + OSM.PIWIK_LOCATION + "/"; + var base = document.location.protocol + "//" + OSM.PIWIK.location + "/"; + var piwikTracker; - $.ajax({ + var piwikLoader = $.ajax({ url: base + "piwik.js", dataType: "script", cache: true, success: function () { - var piwikTracker = Piwik.getTracker(base + "piwik.php", OSM.PIWIK_SITE); - + piwikTracker = Piwik.getTracker(base + "piwik.php", OSM.PIWIK.site); + + if (OSM.user) { + piwikTracker.setUserId(OSM.user.toString()); + } + piwikTracker.trackPageView(); piwikTracker.enableLinkTracking(); - + $("meta[name=piwik-goal]").each(function () { piwikTracker.trackGoal($(this).attr("content")); }); } }); + + $("body").on("piwikgoal", function (e, goal) { + piwikLoader.done(function () { + piwikTracker.trackGoal(goal); + }); + }); }); }