{"version":3,"file":"GainHubSpotForm.CAtp85aC.mjs","names":["useRef"],"sources":["https:/framerusercontent.com/modules/pDh7xPP9Mm00ifIa1eyE/qe8InA2prS1gwCINPMnF/GainHubSpotForm.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{addPropertyControls,ControlType}from\"framer\";import{useEffect,useRef}from\"react\";import{emptyStateStyle}from\"https://framer.com/m/framer/integrations-styles.js@0.2.0\";function poll(f,delay=50,count=50,i=0,errorCallback){if(i>count){errorCallback();return;}if(!f()){setTimeout(()=>{poll(f,delay,count,i+1,errorCallback);},delay);}}/**\n * These annotations control how your component sizes\n * Learn more: https://www.framer.com/docs/guides/auto-sizing\n *\n * @framerSupportedLayoutWidth any\n * @framerSupportedLayoutHeight auto\n */export default function GainHubSpotForm({portalId,formId,region,containerStyle,id,conversionEvent,handleSubmit,setIsFormReady,oktopostConversion,gatedPage,redirectUrl,...props}){const scriptTriggeredRef=useRef(false);if(!portalId||!formId||!region){return /*#__PURE__*/_jsxs(\"div\",{style:{...emptyStateStyle,width:\"100%\",height:\"100%\"},children:[/*#__PURE__*/_jsx(\"h1\",{children:\"Hubspot\"}),/*#__PURE__*/_jsx(\"p\",{children:\"Set a portal ID and form in the Properties.\"})]});}const elementId=`hubspot_form_${id}`;const cleanup=()=>{const element=document.querySelector(`#${elementId}`);if(element)element.innerHTML=\"\";};useEffect(()=>{if(window.hbspt){handleScriptLoad();return cleanup;}const script=document.createElement(\"script\");script.src=`https://js-${region}.hsforms.net/forms/shell.js`;script.onload=handleScriptLoad;document.body.appendChild(script);scriptTriggeredRef.current=true;return cleanup;},[formId]);function trackPageVisit(gatedPage){const currentPagePath=(gatedPage||window.location.pathname)?.toString();const storedVisitsString=localStorage.getItem(\"page_visit\");let visitedPagesObject={};if(storedVisitsString){try{visitedPagesObject=JSON.parse(storedVisitsString);}catch(error){console.error(\"Error parsing localStorage 'page_visit' object:\",error);visitedPagesObject={};}}visitedPagesObject[currentPagePath]=true;const updatedVisitsString=JSON.stringify(visitedPagesObject);localStorage.setItem(\"page_visit\",updatedVisitsString);}function getUtmParameters(){const params=new URLSearchParams(window.location.search);const utmParams={};// List of standard UTM parameters\nconst standardUtmKeys=[\"utm_source\",\"utm_medium\",\"utm_campaign\",\"utm_term\",\"utm_content\",\"utm_id\",\"utm_source_platform\",\"utm_creative_format\",\"utm_marketing_tactic\"];standardUtmKeys.forEach(key=>{if(params.has(key)){utmParams[key]=params.get(key);}});return utmParams;}const handleScriptLoad=()=>{poll(()=>{if(!window.hbspt){return false;}if(!id||!document.querySelector(`#${elementId}`)){return false;}cleanup();window.hbspt.forms.create({region,portalId,formId,target:`#${elementId}`,formInstanceId:formId,onFormReady:()=>{setIsFormReady();if(Array.isArray(window.dataLayer)){window.dataLayer.push({event:\"hubspot-form-ready-\"+elementId});}},onBeforeFormSubmit:()=>{if(redirectUrl){window.location.href=redirectUrl;handleSubmit();return false;}return true;},onFormSubmitted:(_,data)=>{delete data.submissionValues.hs_context;delete data.submissionValues[\"g-recaptcha-response\"];handleSubmit(data.submissionValues);const currentUtmParams=getUtmParameters();trackPageVisit(gatedPage);if(Array.isArray(window.dataLayer)){window.dataLayer.push({event:\"hubspot-form-submitted-\"+elementId,hubspotFormId:formId,...currentUtmParams});if(conversionEvent){window.dataLayer.push({event:\"hubspot-form-conversion\",hubspotFormId:formId,conversionEvent:conversionEvent,formData:data.submissionValues});}}if(oktopostConversion&&window?._oktrk){window?._oktrk(\"send\",{tag:oktopostConversion,firstName:data?.submissionValues?.firstname,lastName:data?.submissionValues?.lastname,email:data?.submissionValues?.email,company:data?.submissionValues?.company});}}});return true;},50,50,0,()=>{if(!window.hbspt){console.warn(`HubSpot could not be loaded: window.hbspt is missing`);return;}if(!document.querySelector(`#${elementId}`)){console.warn(`HubSpot could not be loaded: element not found #${elementId}`);return;}console.warn(`HubSpot could not be loaded: no idea why`);});};return /*#__PURE__*/_jsx(\"div\",{id:elementId,style:containerStyle,...props});}// Styles are written in object syntax\n// Learn more: https://reactjs.org/docs/dom-elements.html#style\nconst containerStyle={width:\"100%\",height:\"100%\"};GainHubSpotForm.displayName=\"General/GainHubSpotForm\";GainHubSpotForm.defaultProps={portalId:\"5422012\",advanced:false,region:\"na1\",handleSubmit:data=>{},setIsFormReady:()=>{}};addPropertyControls(GainHubSpotForm,{formId:{title:\"Form\",type:ControlType.String,placeholder:\"e7167571-4bc4-4c2c-bfdc-a0a8dbfd22f1\"},conversionEvent:{type:ControlType.String,title:\"Conversion Event\",defaultValue:\"\"},oktopostConversion:{type:ControlType.String,title:\"Oktopost Conversion Event\",defaultValue:\"\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"GainHubSpotForm\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\",\"framerSupportedLayoutWidth\":\"any\",\"framerSupportedLayoutHeight\":\"auto\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./GainHubSpotForm.map"],"mappings":"4QAAuO,SAAS,EAAK,EAAE,EAAM,GAAG,EAAM,GAAG,EAAE,EAAE,EAAc,CAAC,GAAG,EAAE,EAAM,CAAC,EAAc,EAAE,MAAO,CAAK,EAAE,GAAG,eAAe,CAAC,EAAK,EAAE,EAAM,EAAM,EAAE,EAAE,CAAa,CAAE,EAAE,CAAK,CAAG,CAMtY,SAAwB,EAAgB,CAAC,WAAS,SAAO,SAAO,iBAAe,KAAG,kBAAgB,eAAa,iBAAe,qBAAmB,YAAU,cAAY,GAAG,GAAO,CAAC,IAAM,EAAmBA,EAAO,EAAK,EAAE,GAAG,CAAC,GAAU,CAAC,GAAQ,CAAC,EAAQ,OAAoB,EAAM,MAAM,CAAC,MAAM,CAAC,GAAG,EAAgB,MAAM,OAAO,OAAO,MAAM,EAAE,SAAS,CAAc,EAAK,KAAK,CAAC,SAAS,SAAS,CAAC,EAAe,EAAK,IAAI,CAAC,SAAS,6CAA6C,CAAC,CAAC,CAAC,CAAC,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