Custom Tracking (WIX) – Adds 3 input data values in LMFX

Posted by: Nico Cagalitan Date Posted: November 19, 2026
Back to Case Studies

Issue

They requested additional input fields to be captured within LMFX.

Solution

Able to add the requested input fields and restructure the custom code.

 

Achievement

Able to update the code that captures additional input fields to the custom code that is needed for the contact us.

Snippet/Screenshot/Link

Ticket: https://app.webfx.com/todos/270585786

Snippet:

var fieldNames = [“name”, “email”, “phone”, “message”, “handyman_referral”];
function setupEventListeners() {
var forms = document.querySelectorAll(“form#form-539f2858-52c1-4f72-a95c-0c121b848cef”);
for (var b = 0; b < forms.length; b++) {
var btns = forms[b].querySelectorAll(‘button[data-hook=”submit-button”]’);
for (var a = 0; a < btns.length; a++) {
if (btns[a]._fxListenerAttached) continue;
btns[a]._fxListenerAttached = true;
(function (e) {
e.addEventListener(“click”, function () {
var form = e.closest(“form”);
var f = document.createElement(“form”);
f.style.display = “none”;
f.setAttribute(“id”, “fx-contact-us”);
function add(name, value) {
var h = document.createElement(“input”);
h.type = “hidden”;
h.name = name;
h.value = value;
f.appendChild(h);
}

// original behavior: every input/textarea by index
var inputs = form.querySelectorAll(“input, textarea”);
for (var g = 0; g < inputs.length; g++) {
var v = inputs[g].value;
if (inputs[g].type === “checkbox”) {
v = inputs[g].checked ? “Yes” : “”;
}
add(fieldNames[g] || “fx-” + g, v);
}

// new: the two dropdowns
var dd = form.querySelectorAll(‘[data-hook=”dropdown-base-text”]’);
add(“project_type”, dd[0] ? dd[0].textContent.trim() : “”);
add(“budget_range”, dd[1] ? dd[1].textContent.trim() : “”);

document.body.appendChild(f);
mcfx(“capture”, f);
document.body.removeChild(f);
});
})(btns[a]);
}
}
}

var observer = new MutationObserver(function (d) {
for (var b = 0; b < d.length; b++)
if (d[b].type === “childList”)
for (var c = d[b].addedNodes, a = 0; a < c.length; a++) {
var e = c[a];
e.nodeType === Node.ELEMENT_NODE &&
(e.matches(“form#form-539f2858-52c1-4f72-a95c-0c121b848cef”) ||
e.querySelector(“form#form-539f2858-52c1-4f72-a95c-0c121b848cef”)) &&
setupEventListeners();
}
});
observer.observe(document.body, { childList: true, subtree: true });
setupEventListeners();
setTimeout(function () { setupEventListeners(); }, 2000);