Skip to content

Commit

Permalink
Start tracking donate button clicks
Browse files Browse the repository at this point in the history
- Old approach used functions expected in mysociety.org
  • Loading branch information
ajparsons committed May 29, 2024
1 parent cf2a057 commit 8e8ddb4
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions www/docs/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,23 @@ var trackEvent = function(eventName, params) {
var dfd = $.Deferred();

var callback = function(){
dfd.resolve();
dfd.resolve();
};

// Tell Gtag to resolve our promise when it's done.
var params = $.extend(params, {
if (typeof gtag !== 'undefined') {
// Tell Gtag to resolve our promise when it's done.
var params = $.extend(params, {
event_callback: callback
});
});

gtag('event', eventName, params);
gtag('event', eventName, params);

// Wait a maximum of 2 seconds for Gtag to resolve promise.
setTimeout(callback, 2000);
// Wait a maximum of 2 seconds for Gtag to resolve promise.
setTimeout(callback, 2000);
} else {
// If gtag is not defined, e.g. in dev mode, resolve the promise immediately.
callback();
}

return dfd.promise();
};
Expand Down Expand Up @@ -478,15 +483,11 @@ $(function() {
grecaptcha.execute();
};

if (!window.analytics) {
return submitPaymentForm();
}

window.analytics.trackEvent(
trackEvent(
"donate_form_submit", {"frequency": howoften, "value": amount }
).done(submitPaymentForm);
});
).always(submitPaymentForm);
});

});

function onDonateError(message) {
Expand Down

0 comments on commit 8e8ddb4

Please sign in to comment.