Skip to content

Commit

Permalink
Moved UTM append function inside of scan results submit form
Browse files Browse the repository at this point in the history
  • Loading branch information
maxxcrawford committed Apr 23, 2020
1 parent 618277b commit 148d3c7
Showing 1 changed file with 16 additions and 26 deletions.
42 changes: 16 additions & 26 deletions public/js/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,22 @@ function handleFormSubmits(formEvent) {
if (formClassList.contains("skip")) {
return;
}

if (document.body.dataset.experiment) {
const scanFormActionURL = new URL(thisForm.action);

["utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content" ].forEach(key => {
if (document.body.dataset[key]) {
scanFormActionURL.searchParams.append(key, document.body.dataset[key]);
}
});

const revisedActionURL = scanFormActionURL.pathname + scanFormActionURL.search;

thisForm.action = revisedActionURL;

}

if (thisForm.email && !isValidEmail(email)) {
sendPing(thisForm, "Failure");
formClassList.add("invalid");
Expand Down Expand Up @@ -402,30 +418,4 @@ function addBentoObserver(){
const dropDownMenu = document.querySelector(".mobile-nav.show-mobile");
dropDownMenu.addEventListener("click", () => toggleDropDownMenu(dropDownMenu));

if (document.body.dataset.experiment) {
const submitBtn = document.querySelector("#scan-user-email input[type='submit']");

submitBtn.addEventListener("click", (e)=> {

// Email Validation
const scanForm = document.getElementById("scan-user-email");
const scanFormEmailInput = document.getElementById("scan-email");

if (scanFormEmailInput) {
const scanFormActionURL = new URL(scanForm.action);

["utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content" ].forEach(key => {
if (document.body.dataset[key]) {
scanFormActionURL.searchParams.append(key, document.body.dataset[key]);
}
});

const revisedActionURL = scanFormActionURL.pathname + scanFormActionURL.search;

scanForm.action = revisedActionURL;
}

});
}

})();

0 comments on commit 148d3c7

Please sign in to comment.