]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/piwik.js
Move piwik code to a static JS asset
[rails.git] / app / assets / javascripts / piwik.js
diff --git a/app/assets/javascripts/piwik.js b/app/assets/javascripts/piwik.js
new file mode 100644 (file)
index 0000000..d0443ae
--- /dev/null
@@ -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"));
+        });
+      }
+    });
+  });
+}