Skip to content

Commit

Permalink
Make sure form conversion only counts when the form submitted was in …
Browse files Browse the repository at this point in the history
…the popup

Issue #775
  • Loading branch information
fpcorso committed Oct 9, 2020
1 parent 371c4b2 commit 6f89bac
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions assets/js/src/site/plugins/pum-analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,13 @@ var PUM_Analytics;
if (data.pid > 0 && !$("body").hasClass("single-popup")) {
PUM_Analytics.beacon(data);
}
})
/**
* Track form submission conversions
*/
.on("pum.integration.form.success", function() {
var $popup = PUM.getPopup(this),
});
/**
* Track form submission conversions
*/
$(function() {
PUM.hooks.addAction("pum.integration.form.success", function(form, args) {
var $popup = PUM.getPopup(form),
data = {
pid:
parseInt($popup.popmake("getSettings").id, 10) ||
Expand All @@ -94,9 +95,14 @@ var PUM_Analytics;
};

// Shortcode popups use negative numbers, and single-popup (preview mode) shouldn't be tracked.
if (data.pid > 0 && !$("body").hasClass("single-popup")) {
if (
$popup.length &&
data.pid > 0 &&
!$("body").hasClass("single-popup")
) {
PUM_Analytics.beacon(data);
}
});
});
}
})(jQuery);

0 comments on commit 6f89bac

Please sign in to comment.