{"version":3,"file":"AppendUtmToLink.CMPj6aBf.mjs","names":["useCallback"],"sources":["https:/framerusercontent.com/modules/feAwC5pfCfYB0RSZ7NK5/FIJ96qqCqVQEVwNDBIYx/AppendUtmToLink.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{useEffect,useCallback}from\"react\";export function appendUtmToLink(Component){return props=>{const{id,layoutId,link}=props// Standard props from Framer\n;const initialLinkUrlFromProps=link?.url// For logging initial state only\n;useEffect(()=>{// Log initial props for context (runs once on mount)\nconsole.log(`Append UTM to Link (Initial Mount - ID: ${id||\"N/A\"}, LayoutID: ${layoutId||\"N/A\"}): Initial props.link.url was '${initialLinkUrlFromProps}'`);// eslint-disable-next-line react-hooks/exhaustive-deps\n},[]);const handleClick=useCallback(event=>{console.log(\"Append UTM to Link (onClick): Intercepted click.\");const clickedElement=event.currentTarget;let baseHref=null;if(clickedElement&&typeof clickedElement.href===\"string\"&&clickedElement.href.trim()!==\"\"){baseHref=clickedElement.href;console.log(\"Append UTM to Link (onClick): Base href from clicked element:\",baseHref);}else{console.warn(\"Append UTM to Link (onClick): Clicked element has no valid href. Cannot append UTMs or redirect.\");// Optionally, allow default behavior if it makes sense, but for an <a> tag usually it means no link.\n// event.preventDefault() might not have been called yet if we return early.\nreturn;}event.preventDefault()// Stop the original navigation now that we have a baseHref\n;const currentPageUrlParams=new URLSearchParams(window.location.search);let newRedirectUrl=baseHref// Start with the href from the element\n;let utmsWereAppended=false;try{const urlObject=new URL(baseHref)// baseHref should be a full URL\n;currentPageUrlParams.forEach((value,key)=>{if(key.startsWith(\"utm_\")||key===\"gclid\"||key===\"fbclid\"||key===\"msclkid\"){// Append to the existing search params of the baseHref\nurlObject.searchParams.append(key,value);utmsWereAppended=true;}});if(utmsWereAppended){newRedirectUrl=urlObject.toString();}console.log(\"Append UTM to Link (onClick): Navigating to:\",newRedirectUrl);window.location.href=newRedirectUrl// Perform the redirect\n;}catch(error){console.error(\"Append UTM to Link (onClick): Error processing URL. Navigating to the (potentially unmodified) base href from element.\",error,\"Base href:\",baseHref);window.location.href=baseHref// Fallback to the href we got from the element\n;}},[])// No dependencies needed here as it uses event.currentTarget and window.location\n;// This useEffect is now ONLY for attaching the click listener.\n// It no longer tries to modify the href beforehand.\nuseEffect(()=>{if(typeof window===\"undefined\")return;let elementToAttachListener=null;let actualLinkElement=null;// Try finding element by layoutId first, then by id\n// This assumes layoutId or id refers to the component's root DOM element from Framer\nif(layoutId)elementToAttachListener=document.getElementById(layoutId);if(!elementToAttachListener&&id)elementToAttachListener=document.getElementById(id);if(elementToAttachListener){// Check if the element itself is an <a> tag\nif(elementToAttachListener.tagName===\"A\"){actualLinkElement=elementToAttachListener;}else{// If not, look for an <a> tag within it (common for Framer buttons)\nactualLinkElement=elementToAttachListener.querySelector(\"a\");}}if(actualLinkElement){console.log(\"Append UTM to Link (Setup): Attaching click listener to <a> element:\",actualLinkElement);actualLinkElement.addEventListener(\"click\",handleClick);return()=>{if(actualLinkElement){console.log(\"Append UTM to Link (Setup): Removing click listener from <a> element:\",actualLinkElement);actualLinkElement.removeEventListener(\"click\",handleClick);}};}else{console.warn(`Append UTM to Link (Setup): Could not find target <a> DOM element using layoutId ('${layoutId}') or id ('${id}') to attach click listener. Override for props.id ${id} will not work as intended.`);}// Re-attach if id/layoutId changes, or if handleClick definition changes (it won't due to useCallback).\n},[id,layoutId,handleClick]);// Pass onClick to the Component. Framer's Button component should handle this\n// by attaching it to its underlying <a> tag or main clickable element.\nreturn /*#__PURE__*/_jsx(Component,{...props,onClick:handleClick});};}\nexport const __FramerMetadata__ = {\"exports\":{\"appendUtmToLink\":{\"type\":\"reactHoc\",\"name\":\"appendUtmToLink\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./AppendUtmToLink.map"],"mappings":"kIAAoF,SAAgB,EAAgB,EAAU,CAAC,MAAO,IAAO,CAAC,GAAK,CAAC,KAAG,WAAS,QAAM,EAC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