(function() {
function getParam(param) {
let params = new URLSearchParams(window.location.search);
return params.get(param);
}
function storeClickId(param, storageKey) {
let value = getParam(param);
if (value) {
let record = {
value: value,
expiry: new Date().getTime() + 90 * 24 * 60 * 60 * 1000
};
localStorage.setItem(storageKey, JSON.stringify(record));
console.log(`✅ Stored ${param}:`, record);
} else {
console.log(`⚠ No ${param} found in URL`);
}
}
function updateHubSpotIframe(attempt = 0) {
let iframe = document.querySelector('iframe[src*="hsforms.com"]');
if (!iframe) {
console.warn(`⚠ Attempt ${attempt}: HubSpot iFrame not found.`);
if (attempt < 20) setTimeout(() => updateHubSpotIframe(attempt + 1), 500);
return;
}
let gclid = JSON.parse(localStorage.getItem("gclid"))?.value || "";
let fbclid = JSON.parse(localStorage.getItem("fbclid"))?.value || "";
let li_fat_id = JSON.parse(localStorage.getItem("li_fat_id"))?.value || "";
let newSrc = iframe.src.split("?")[0] +
`?google_clickid=${encodeURIComponent(gclid)}` +
`&meta_clickid=${encodeURIComponent(fbclid)}` +
`&linkedin_clickid=${encodeURIComponent(li_fat_id)}`;
console.log("🔄 Updating HubSpot iFrame to:", newSrc);
iframe.src = newSrc;
}
// Delay execution until page is fully loade
top of page
bottom of page
Komentarze