]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/piwik.js
Use bootstrap_form as the formbuilder for GPX upload form
[rails.git] / app / assets / javascripts / piwik.js
index d0443ae6d983ad9ee137f92eb66d8ed5cf15e3fe..5353a99ac199609cd763903e953083625501cdc0 100644 (file)
@@ -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);
+      });
+    });
   });
 }