Add campaign custom dimension to donation form.
authorRadek Czajka <rczajka@rczajka.pl>
Tue, 27 Apr 2021 09:21:52 +0000 (11:21 +0200)
committerRadek Czajka <rczajka@rczajka.pl>
Tue, 27 Apr 2021 09:21:52 +0000 (11:21 +0200)
src/club/static/club/form.js

index f590fdf..422cab4 100644 (file)
@@ -18,7 +18,18 @@ $(function() {
     $("#payment-form .plan").change(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() {
     $("#payment-form").submit(function() {
-        _paq.push(['trackGoal', 12, parseFloat($("#id_amount").val())]);
+        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]);
     });
 });
     });
 });