The client wants to track their contact, booking, and schedule an appointment form that will only capture a validated Zip Code for Land O’ Lakes, Lakeland, and Riverview.
Constructed a custom tracking that will validate the Zip Code first that falls under Land O’ Lakes, Lakeland, and Riverview before firing the RCFX lead event.
This is 1 of the 3 custom tracking; they’re similar in structure and just have a slight difference with the zipcode input ID, and virtual form ID.
// Array of valid zip codes
var validZipCodes = [
// Land O Lake
33510, 33523, 33524, 33525, 33526, 33527, 33537, 33539, 33540, 33541,
33542, 33543, 33544, 33545, 33565, 33574, 33576, 33583, 33584, 33587,
33592, 33593, 33594, 33595, 33596, 33849, 34610, 34637, 34638, 34639,
34654, 34667, 34668, 34669, 34673, 34674, 34679,
// Lakeland
33530, 33547, 33563, 33564, 33566, 33567,
33801, 33802, 33803, 33804, 33805, 33806,
33807, 33809, 33810,33811 ,33812 ,33813,
,33815 ,33840 ,33846,
// Riverview
,33503 ,33534 ,33568 ,33569 ,33570 ,
,33571 ,33572 ,33573 ,33575 ,33578 ,
,33579 ,33586 ,33598
];
// Convert array to Set for faster lookup
var validZipCodeSet = new Set(validZipCodes);
document.getElementById('send-zip').addEventListener('input', function(e) {
var zip = parseInt(e.target.value, 10);
if (validZipCodeSet.has(zip)) {
// The zip code is valid
console.log('Valid zip code: ' + zip);
// Call your function here
(function() {
var fxform = document.querySelector('div.contact-form-wrap form');
console.log('form found' + ' ' + fxform);
if (fxform) {
// Select the submit button within the form
var submitButton = fxform.querySelector('button[type="button"]');
console.log('button found' + ' ' + submitButton);
if (submitButton) {
submitButton.addEventListener('click', function() {
console.log('submit button clicked');
// Create a new virtual form element
var virtualForm = document.createElement('form');
virtualForm.setAttribute('id', 'fx-contact');
// Clone and append each input/textarea from the original div to the virtual form
fxform.querySelectorAll('input, textarea').forEach(function(field, index) {
var fxfield = field.cloneNode(true);
if (!fxfield.getAttribute('name')) {
fxfield.setAttribute('name', 'fx-' + index);
}
virtualForm.appendChild(fxfield);
});
mcfx('capture', virtualForm);
console.log(virtualForm);
});
}
}
})();//clone faux form end
}//if end
});//document end
Constructed a custom tracking for O’lakes that validates the Zip Code before RCFX/LMFX captures the lead.
Also, our team doesn’t have access to their CMS or GTM, and even with this limitation, we are still able to construct a custom tracking and test the code.
Ticket: link