They have a form that was not tracking in the LeadManagerFX, and it was under an unconventional form setup, and it doesn’t have any input name attribute, which is needed for passing data value, and they have multiple forms within the page, which share the same form application (CSS selectors/attributes)
Created custom code that captures the unconventional form application to make it fire lead events and also to at least make the script recognize each form as separate and not overwrite the lead submitted.
Code:
<script>
(function() {
function checkAndSetupButtons() {
var buttons = document.querySelectorAll(‘div.pc-form-widget .btn-primary.form-button’);
if (buttons.length > 0) {
for (var i = 0; i < buttons.length; i++) {
(function(btn) {
var fxform = btn.closest(‘.pc-form-widget’) || btn.closest(‘[class*=”pc-form”]’);
btn.addEventListener(‘click’, function() {
if (typeof mcfx === ‘function’) {
var virtualForm = document.createElement(‘form’);
virtualForm.style.display = ‘none’;
var widgetId = fxform.getAttribute(‘id’);
if (widgetId) {
virtualForm.setAttribute(‘id’, widgetId);
virtualForm.setAttribute(‘name’, widgetId);
}
fxform.querySelectorAll(‘input, textarea, select’).forEach(function(field) {
if (field.type === ‘hidden’) return;
var fxfield = field.cloneNode(true);
var fieldKey = field.getAttribute(‘data-field-key’);
if (fieldKey) {
fxfield.setAttribute(‘name’, fieldKey);
} else {
return;
}
virtualForm.appendChild(fxfield);
});
document.body.appendChild(virtualForm);
mcfx(‘capture’, virtualForm);
console.log(‘[MCFX] Form captured:’, widgetId);
setTimeout(function() {
if (virtualForm.parentNode) virtualForm.parentNode.removeChild(virtualForm);
}, 2000);
}
}, true);
console.log(‘[MCFX] Listener attached:’, fxform.getAttribute(‘id’));
})(buttons[i]);
}
clearInterval(intervalId);
}
}
var intervalId = setInterval(checkAndSetupButtons, 1000);
})();
</script>
Able to create a custom tracking that captures the unconventional form, adds input name field, and able to separate the forms within the same page.
Ticket: https://app.webfx.com/todos/269505468