function loadHubspotHiddenForm() {
hbspt.forms.create({
region: "na1",
portalId: "42291744",
formId: "6f0976b5-fc44-4e2b-8164-c2f73a0f3921",
onFormReady: function($form) {
$form.style.display = "none";
var prefilled_email = $form.email.value;
// Wait 3 seconds for UTM script to prefill fields before auto-submitting
setTimeout(function() {
if (prefilled_email) {
$form.submit();
}
}, 3000);
},
onFormSubmitted: function($form) {
$form.style.display = "none";
},
});
}
function checkAndLoadHubspotForm() {
var formlist = document.querySelectorAll('form');
if (!formlist || formlist.length === 0) {
loadHubspotHiddenForm();
return;
}
for (var i = 0; i < formlist.length; i++) {
var formid = formlist[i].id;
if (!formid.toLowerCase().includes("hsform")) {
// if hubspot form not found on page, add hidden form and submit it.
loadHubspotHiddenForm();
}
}
}
var pagelocation = document.location.href;
if (!pagelocation.includes("thank") && !pagelocation.includes("confirmation")) {
// Wait for 5 seconds for any existing HubSpot form to load
setTimeout(checkAndLoadHubspotForm, 5000);
}
// Navigation API listener (if supported)
if (window.navigation && window.navigation.addEventListener) {
window.navigation.addEventListener("navigate", function() {
var pagelocation = document.location.href;
if (!pagelocation.includes("thank") && !pagelocation.includes("confirmation")) {
setTimeout(checkAndLoadHubspotForm, 5000); // Wait 5 seconds
}
});
}