{"version":3,"file":"URLTracking.Tm93R8zT.mjs","names":["useState"],"sources":["https:/framerusercontent.com/modules/SojhKCOrexKs01ULbI8V/3AnRZYpnMsVcRq9Rv4fY/URLTracking.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{useState,useEffect}from\"react\";// --- Attribution config ---\nconst STORAGE_KEY=\"attribution\";// Query params we capture on landing and later append to outbound links.\n// Extend this list if you add new channels/networks.\nconst TRACKED_KEYS=[\"utm_source\",\"utm_medium\",\"utm_campaign\",\"utm_content\",\"utm_term\",\"gclid\",\"gbraid\",\"wbraid\",\"fbclid\",\"ttclid\",\"awc\"];// --- localStorage helpers ---\nconst readAttribution=()=>{if(typeof window===\"undefined\")return{};try{const raw=window.localStorage.getItem(STORAGE_KEY);return raw?JSON.parse(raw):{};}catch{return{};}};// Capture happens in the sitewide custom-code script (End of <body> tag in\n// Framer Site Settings), not here — that script must write to the same\n// STORAGE_KEY (\"attribution\") and cover the same TRACKED_KEYS below so this\n// override reads the format it expects. This file only reads + appends.\n// Serialize object into query string\nconst serializeQueryParams=params=>Object.keys(params).map(key=>`${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`).join(\"&\");// Parse query string into object\nconst parseQueryParams=query=>{const params={};if(!query)return params;const pairs=query.substring(1).split(\"&\");pairs.forEach(pair=>{const[key,value]=pair.split(\"=\");if(key)params[decodeURIComponent(key)]=decodeURIComponent(value||\"\");});return params;};// --- Update links to include stored attribution ---\nconst updateLinkWithUTM=(link,location)=>{if(!link)return link;try{const url=new URL(link);const linkParams=parseQueryParams(url.search);// Stored attribution (from an earlier landing on this site)\nconst stored=readAttribution();const attributionParams={};TRACKED_KEYS.forEach(key=>{if(stored[key])attributionParams[key]=stored[key];});// Current URL params take priority over stored ones, in case this\n// click is happening on a freshly-tagged page (e.g. a second ad click\n// before the mount-time capture ran, or a param not in TRACKED_KEYS'\n// usual capture path).\nconst currentParams=parseQueryParams(location?location.search:\"\");// --- Merge: link's own params < stored attribution < current URL params ---\nconst mergedParams={...linkParams,...attributionParams,...currentParams};const newQueryString=serializeQueryParams(mergedParams);url.search=newQueryString?`?${newQueryString}`:\"\";return url.toString();}catch(error){console.error(\"Error updating link:\",error);return link;}};// --- Recursive rewrite for nested children (handles href) ---\nconst rewriteChildren=(child,windowObj)=>{if(!child||!child.props)return child;// Rewrite href if present\nif(child.props.href){const updatedHref=windowObj?updateLinkWithUTM(child.props.href,windowObj.location):child.props.href;return{...child,props:{...child.props,href:updatedHref}};}// Otherwise recurse into children\nif(child.props.children){return{...child,props:{...child.props,children:rewriteChildren(child.props.children,windowObj)}};}return child;};// --- Wrapper component ---\nconst LinkRewriteWrapper=({Component,props})=>{const[myWindow,setMyWindow]=useState(null);useEffect(()=>{setMyWindow(window);},[]);const originalLink=props.link||props.href;const updatedLink=myWindow&&originalLink?updateLinkWithUTM(originalLink,myWindow.location):originalLink;const newChildren=rewriteChildren(props.children,myWindow);return /*#__PURE__*/_jsx(Component,{...props,link:props.link?updatedLink:props.link,href:props.href?updatedLink:props.href,children:newChildren});};// --- HOC for easy reuse ---\nexport function withUTMTracking(Component){return props=>/*#__PURE__*/_jsx(LinkRewriteWrapper,{Component:Component,props:props});}\nexport const __FramerMetadata__ = {\"exports\":{\"withUTMTracking\":{\"type\":\"reactHoc\",\"name\":\"withUTMTracking\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./URLTracking.map"],"mappings":"uIAsBA,SAAgB,EAAgB,EAAU,CAAC,MAAO,IAAoB,EAAK,EAAmB,CAAW,YAAgB,OAAK,CAAC,CAAE,qCAtBvF,IAAsC,EAC1E,EAAY,cAEZ,EAAa,CAAC,aAAa,aAAa,eAAe,cAAc,WAAW,QAAQ,SAAS,SAAS,SAAS,SAAS,KAAK,EACjI,MAAoB,CAAC,GAAU,IAAS,OAAY,MAAM,CAAC,EAAE,GAAG,CAAC,IAAM,EAAI,EAAO,aAAa,QAAQ,CAAW,EAAE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