Skip to content

Revert "Santi/star 1183 implement all events from ctas" #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 2 additions & 28 deletions segment-tracker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,9 @@ function get_form_inputs(properties) {
});
}


// Create flags
var button_event_triggered = false;
var form_event_triggered = false;

$(document).ready(function () {
// capture a click on any element that has
$("[data-analytics]").on("click", async function (e) {
if (button_event_triggered) {
button_event_triggered = false; // reset flag
return; // let the event bubble away
}

e.preventDefault();

$("[data-analytics]").on("click", async function () {
// Get event name
var event = $(this).attr("data-analytics");

Expand All @@ -49,22 +37,11 @@ $(document).ready(function () {
get_extra_attributes.call(this, properties);
// Fire Segment event
if ("analytics" in window) await analytics.track(event, properties);

button_event_triggered = true; // set flag
$(this).trigger('click');

});


// Add submit listener for all forms
$("form").on("submit", function (e) {

if (form_event_triggered) {
form_event_triggered = false; // reset flag
return; // let the event bubble away
}

e.preventDefault();
$("form").bind("submit", function (e) {

var properties = {
// capture the URL where this event is fired
Expand Down Expand Up @@ -105,9 +82,6 @@ $(document).ready(function () {

}

form_event_triggered = true; // set flag
$(this).trigger('submit');

});

});