{"version":3,"file":"CrossDomainUTM_Tracking.CBb8Se6Q.mjs","names":["__legacyOverrideHOC_DataObserverContext","_jsx"],"sources":["https:/framerusercontent.com/modules/ieKS1rkAamBwxQyZz7BA/PDiI1LCtxPS8yR1NiScg/CrossDomainUTM_Tracking.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{useEffect}from\"react\";export function crossDomainTracking(){useEffect(()=>{function handleClick(e){// Store the original href in case we need fallback\nconst originalHref=e.currentTarget.href;const targetAttr=e.currentTarget.getAttribute(\"target\");try{// Prevent default only after we know we can handle it\ne.preventDefault();// Build the new URL with the parameters\nconst url=new URL(originalHref);// For Koodoo and agent URLs, add PostHog tracking IDs\nif(url.hostname===\"mip.koodoo.io\"||url.hostname===\"compare.koodoo.io\"||url.hostname===\"agent.koodoo.io\"||url.hostname===\"koodoo.io\"||url.hostname.includes(\"koodoo.io\")){// Safely check if PostHog exists and has the required methods\nif(typeof window.posthog!==\"undefined\"&&window.posthog&&typeof window.posthog.get_distinct_id===\"function\"&&typeof window.posthog.get_session_id===\"function\"){try{const distinctId=window.posthog.get_distinct_id();const sessionId=window.posthog.get_session_id();if(distinctId&&sessionId){url.searchParams.set(\"sessionId\",sessionId);url.searchParams.set(\"distinctId\",distinctId);url.searchParams.set(\"endUserId\",distinctId);}else{console.warn(\"PostHog IDs not available on click.\");}}catch(phError){console.error(\"Error accessing PostHog:\",phError);// Continue execution even if PostHog fails\n}}else{console.warn(\"PostHog not available or methods missing\");}}// Get UTM parameters from local storage - wrapped in try/catch\ntry{// Check if localStorage is available (it exists in incognito but might be restricted)\nif(typeof Storage!==\"undefined\"&&window.localStorage){const journeyData=localStorage.getItem(\"journey\");if(journeyData){const journey=JSON.parse(journeyData);// Set endUserId if available\nif(journey.endUserId){url.searchParams.set(\"endUserId\",journey.endUserId);}// Set introducer if available\nif(journey.introducer){url.searchParams.set(\"introducer\",journey.introducer);}// Check if UTM parameters exist in the nested utm object\nif(journey.utm){if(journey.utm.source)url.searchParams.set(\"utm_source\",journey.utm.source);if(journey.utm.medium)url.searchParams.set(\"utm_medium\",journey.utm.medium);if(journey.utm.campaign)url.searchParams.set(\"utm_campaign\",journey.utm.campaign);if(journey.utm.content)url.searchParams.set(\"utm_content\",journey.utm.content);if(journey.utm.term)url.searchParams.set(\"utm_term\",journey.utm.term);}console.log(\"Added parameters from local storage journey:\",journey);}}}catch(error){console.error(\"Error retrieving data from local storage:\",error);// Continue execution even if localStorage fails\n}console.log(\"Updating link on click:\",url.toString());// Navigate to the URL\nif(targetAttr===\"_blank\"){window.open(url.toString(),\"_blank\",\"noopener,noreferrer\");}else{window.location.href=url.toString();}}catch(error){console.error(\"Error in click handler, falling back to default behavior:\",error);// Fallback: navigate to original URL if anything goes wrong\nif(targetAttr===\"_blank\"){window.open(originalHref,\"_blank\",\"noopener,noreferrer\");}else{window.location.href=originalHref;}}}// Attach the click handler to matching links\nfunction attachClickListeners(){const links=document.querySelectorAll('a[href^=\"https://mip.koodoo.io/\"], '+'a[href^=\"https://compare.koodoo.io/\"], '+'a[href^=\"https://agent.koodoo.io/\"], '+'a[href^=\"https://calendly.com/koodoo/get-mortgage-advice-snoop\"]');links.forEach(link=>{// Avoid attaching duplicate handlers\nlink.removeEventListener(\"click\",handleClick);link.addEventListener(\"click\",handleClick);});}// Attach listeners initially\nattachClickListeners();// Use a MutationObserver to re-attach listeners if new links appear\nconst observer=new MutationObserver(()=>{attachClickListeners();});observer.observe(document.body,{childList:true,subtree:true});// Cleanup on unmount\nreturn()=>{const links=document.querySelectorAll('a[href^=\"https://mip.koodoo.io/\"], '+'a[href^=\"https://compare.koodoo.io/\"], '+'a[href^=\"https://agent.koodoo.io/\"], '+'a[href^=\"https://calendly.com/koodoo/get-mortgage-advice-snoop\"]');links.forEach(link=>{link.removeEventListener(\"click\",handleClick);});observer.disconnect();};},[]);return{}// Return an empty object to satisfy Framer Override\n;}import{useContext as __legacyOverrideHOC_useContext}from\"react\";import{DataObserverContext as __legacyOverrideHOC_DataObserverContext}from\"framer\";export function withcrossDomainTracking(C){return props=>{__legacyOverrideHOC_useContext(__legacyOverrideHOC_DataObserverContext);return _jsx(C,{...props,...crossDomainTracking(props)});};}withcrossDomainTracking.displayName=\"crossDomainTracking\";\nexport const __FramerMetadata__ = {\"exports\":{\"withcrossDomainTracking\":{\"type\":\"reactHoc\",\"name\":\"withcrossDomainTracking\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"crossDomainTracking\":{\"type\":\"override\",\"name\":\"crossDomainTracking\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./CrossDomainUTM_Tracking.map"],"mappings":"iSAAwE,SAAgB,GAAqB,CAmBoO,OAnBnO,MAAc,CAAC,SAAS,EAAY,EAAE,CACpJ,IAAM,EAAa,EAAE,cAAc,KAAW,EAAW,EAAE,cAAc,aAAa,UAAU,GAAG,CACnG,EAAE,iBACF,IAAM,EAAI,IAAI,IAAI,GAClB,GAAG,EAAI,WAAW,iBAAiB,EAAI,WAAW,qBAAqB,EAAI,WAAW,mBAAmB,EAAI,WAAW,aAAa,EAAI,SAAS,SAAS,aAC3J,GAAU,EAAO,UAAU,QAAa,EAAO,SAAS,OAAO,EAAO,QAAQ,iBAAkB,YAAY,OAAO,EAAO,QAAQ,gBAAiB,WAAY,GAAG,CAAC,IAAM,EAAW,EAAO,QAAQ,kBAAwB,EAAU,EAAO,QAAQ,iBAAoB,GAAY,GAAW,EAAI,aAAa,IAAI,YAAY,GAAW,EAAI,aAAa,IAAI,aAAa,GAAY,EAAI,aAAa,IAAI,YAAY,IAAkB,QAAQ,KAAK,sCAAyC,OAAM,EAAQ,CAAC,QAAQ,MAAM,2BAA2B,EACzhB,MAAM,QAAQ,KAAK,4CACpB,GAAG,CACH,GAAG,OAAO,QAAU,KAAa,EAAO,aAAa,CAAC,IAAM,EAAY,aAAa,QAAQ,WAAW,GAAG,EAAY,CAAC,IAAM,EAAQ,KAAK,MAAM,G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