The issue is that the Wix multi-step form was not tracking with the previously added custom code, and it stopped tracking.
I was able to create a custom tracking that will work with Wix multi-step forms.
Custom Code:
mcfx(function(t) {
t.configure("onFormCapture", function(form) {
console.log('onFormCapture triggered');
if (form.getAttribute('data-virtual-form') !== 'true') {
return false;
}
var formData = {};
var fields = form.querySelectorAll('input, textarea, select');
for (var i = 0; i < fields.length; i++) {
var field = fields[i];
var fieldName = field.name || field.id || 'field_' + i;
var fieldValue = '';
if (field.type === 'radio' || field.type === 'checkbox') {
if (field.checked) {
fieldValue = field.value;
}
} else {
fieldValue = field.value;
}
if (fieldValue && fieldValue.trim() !== '') {
formData[fieldName] = fieldValue.trim();
}
}
console.log('Form data captured:', formData);
return formData;
});
});
(function() {
var fxForm = document.querySelector('#form-68c2a746-ed02-42bc-bc94-2910177447a3');
console.log('WIX Form found:', fxForm);
if (!fxForm) {
console.error('Form not found');
return;
}
function attachSubmitListener() {
var submitButton = fxForm.querySelector('button[data-hook="submit-button"]');
if (submitButton) {
console.log('Submit button found and attaching listener');
submitButton.addEventListener('click', function() {
console.log('Submit button clicked');
setTimeout(function() {
var virtualForm = document.createElement('form');
virtualForm.setAttribute('id', 'mcfx-event-request');
virtualForm.setAttribute('data-virtual-form', 'true');
var formFields = fxForm.querySelectorAll('input, textarea, select');
console.log('Found ' + formFields.length + ' fields');
for (var i = 0; i < formFields.length; i++) {
var field = formFields[i];
var clonedField = field.cloneNode(true);
if (field.type === 'checkbox' || field.type === 'radio') {
clonedField.checked = field.checked;
} else {
clonedField.value = field.value;
}
if (!clonedField.getAttribute('name') || clonedField.getAttribute('name') === '') {
var fieldName = getFieldName(field);
clonedField.setAttribute('name', fieldName);
}
virtualForm.appendChild(clonedField);
}
console.log('Triggering MCFX capture');
mcfx('capture', virtualForm);
}, 500);
});
return true; // Button found and listener attached
}
return false; // Button not found yet
}
function getFieldName(field) {
var dataHook = field.closest('[data-hook*="form-field-"]');
if (dataHook) {
var hook = dataHook.getAttribute('data-hook');
if (hook) {
return hook.replace('form-field-', '');
}
}
if (field.name && field.name !== '') {
return field.name;
}
if (field.id && field.id !== '') {
return field.id;
}
return 'field_' + Math.random().toString(36).substring(2, 9);
}
// Try to attach immediately first
if (attachSubmitListener()) {
console.log('Submit button already present');
return;
}
// If not found, set up MutationObserver
console.log('Submit button not found, setting up MutationObserver...');
var observer = new MutationObserver(function(mutations) {
// Check if button now exists
if (attachSubmitListener()) {
console.log('Submit button appeared, stopping observer');
observer.disconnect();
}
});
// Start observing the form for changes
observer.observe(fxForm, {
childList: true, // Watch for child node additions/removals
subtree: true, // Watch all descendants
attributes: false // Don't need to watch attributes
});
console.log('MutationObserver started');
})();
Able to capture the full submission of a multi-step Wix form.
Ticket: https://app.webfx.com/todos/268146641