Add campaign custom dimension to donation form.
[wolnelektury.git] / src / club / static / club / form.js
index 6be8220..422cab4 100644 (file)
@@ -16,5 +16,20 @@ $(function() {
     }
     update_methods();
     $("#payment-form .plan").change(update_methods);
-    
+
+
+    function qs(key) {
+        key = key.replace(/[*+?^$.\[\]{}()|\\\/]/g, "\\$&"); // escape RegEx meta chars
+        var match = location.search.match(new RegExp("[?&]"+key+"=([^&]+)(&|$)"));
+        return match && decodeURIComponent(match[1].replace(/\+/g, " "));
+    }
+
+    $("#payment-form").submit(function() {
+        let camp = qs('pk_campaign');
+        if (!camp && window.location.pathname !== "/towarzystwo/") {
+            camp = window.location.pathname;
+        }
+        let dims = camp ? {dimension2: camp} : {};
+        _paq.push(['trackGoal', 12, parseFloat($("#id_amount").val()), dims]);
+    });
 });