HubSpot New Editor – Exclude Non-Iframe Forms

Posted by: Nico Cagalitan Date Posted: April 13, 2026
Back to Case Studies

Issue

They had a duplicate issue, where if you add the custom tracking it will capture twice for those that are non-iframe forms

Solution

Able to create a custom code that excludes non-iframe forms

Custom Code:
//Will only track forms made with the new form editor
window.addEventListener(‘hs-form-event:on-submission:success’, function(event){
console.log(“New form editor form submitted.”);

// Excluded form ID patterns (will match if ID contains these strings)
var excludedFormIds = [
‘939795cb-4d96-4396-8417-4ebcbfce896f’,
‘2e648c1c-3061-44b1-a082-21251dd11a27’
];

// Get the form ID
var formId = event.detail.formId;

console.log(“Form ID detected: ” + formId);

// Check if this form ID contains any excluded pattern (like CSS id*=”…”)
var shouldExclude = false;
for (var i = 0; i < excludedFormIds.length; i++) { if (formId && formId.indexOf(excludedFormIds[i]) !== -1) { shouldExclude = true; console.log("Form excluded from tracking (ID contains): " + formId); break; } } if (shouldExclude) { return; // Exit early, don't track this form } if(window.mcfx && window.HubspotFormsV4){ var fxForm = document.createElement("form"); fxForm.id = formId; //the HubspotFormsV4 interface can find the form that was just submitted by the event HubspotFormsV4.getFormFromEvent(event).getFormFieldValues().then(function(response){ console.log("Found form fields: ", response); response.forEach(function(field){ var fxField = document.createElement("input"); fxField.name = field.name; fxField.value = field.value; fxForm.appendChild(fxField); }) console.log("Capturing form..."); mcfx('capture', fxForm); console.log("Form captured."); }) } });

Achievement

Able to capture the iframe forms only, and exclude the non-iframe forms

Snippet/Screenshot/Link

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