From 5d9b7d5f8dc95660c8d52da7329d3efd87947410 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Tue, 27 Apr 2021 11:21:52 +0200 Subject: [PATCH] Add campaign custom dimension to donation form. --- src/club/static/club/form.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/club/static/club/form.js b/src/club/static/club/form.js index f590fdf96..422cab4f9 100644 --- a/src/club/static/club/form.js +++ b/src/club/static/club/form.js @@ -18,7 +18,18 @@ $(function() { $("#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() { - _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]); }); }); -- 2.20.1