1. Copy data-form-id from the <div> to the <form> before RCFX captures it. Use the page load script to do this automatically for all forms.
2. Update the script to try 10 different ways to catch the forms:
✅ Immediately on load
✅ After 100ms
✅ After 500ms
✅ After 1 second
✅ After 2 seconds
✅ After 3 seconds
✅ On DOMContentLoaded
✅ On window load
✅ MutationObserver (detects when forms are added to DOM)
✅ On first click (for popup forms)
3. Custom script
<script>
(function() {
console.log(‘Form ID enhancer loaded’);
function copyFormIds() {
// Find all divs with data-form-id
var containers = document.querySelectorAll(‘[data-form-id]’);
var count = 0;
Array.prototype.forEach.call(containers, function(container) {
var formId = container.getAttribute(‘data-form-id’);
// Find form inside this container
var form = container.querySelector(‘form’);
if (form) {
// Copy data-form-id to the form element
form.setAttribute(‘data-form-id’, formId);
// Also copy other data attributes if they exist
var apiUrl = container.getAttribute(‘data-form-api-url’);
if (apiUrl) {
form.setAttribute(‘data-form-api-url’, apiUrl);
}
count++;
console.log(‘✓ Copied data-form-id to form:’, formId);
}
});
console.log(‘✓ Enhanced ‘ + count + ‘ forms with data-form-id’);
}
// Run immediately
copyFormIds();
// Run after DOM is ready
if (document.readyState === ‘loading’) {
document.addEventListener(‘DOMContentLoaded’, copyFormIds);
}
// Watch for dynamically added forms
if (window.MutationObserver) {
var observer = new MutationObserver(function(mutations) {
var shouldUpdate = false;
for (var i = 0; i < mutations.length; i++) {
var mutation = mutations[i];
for (var j = 0; j < mutation.addedNodes.length; j++) {
var node = mutation.addedNodes[j];
if (node.nodeType === 1) { // Element node
if (node.hasAttribute && node.hasAttribute(‘data-form-id’) ||
node.querySelector && node.querySelector(‘[data-form-id]’)) {
shouldUpdate = true;
break;
}
}
}
if (shouldUpdate) break;
}
if (shouldUpdate) {
console.log(‘New form detected, updating…’);
copyFormIds();
}
});
observer.observe(document.body, {
childList: true,
subtree: true
});
}
console.log(‘✓ Watching for new forms…’);
})();
</script>
All forms are now tracking correctly.
LMFX: https://app.webfx.com/revenuecloudfx/15590/settings/leadmanager/forms