From: Radek Czajka Date: Tue, 27 Apr 2021 09:21:52 +0000 (+0200) Subject: Add campaign custom dimension to donation form. X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/5d9b7d5f8dc95660c8d52da7329d3efd87947410?ds=inline Add campaign custom dimension to donation form. --- 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]); }); });