(function(){"use strict";const Q="https://seonaapi.conversion.ai/api",J="http://localhost:5180",tt="https://app.stage.conversion.ai",et="https://app.conversion.ai",I="https://p.conversion.ai/api";var M=(t=>(t.Exact="exact",t.Similar="similar",t))(M||{}),D=(t=>(t.AdwinJsReady="astra_js_ready",t.AdwinDevReady="astra_dev_ready",t.AdwinEnableDev="astra_enable_dev",t.AdwinDisableDev="astra_disable_dev",t.AdwinSaveDev="astra_save_dev",t.AdwinAddEvent="astra_add_event",t.AdwinRemoveEvent="astra_remove_event",t.AdwinSetEvents="astra_set_events",t))(D||{}),h=(t=>(t.HeadingPromotion="H1_PROMOTION",t.HeadingDemotion="H1_DEMOTION",t.AnchorTarget="ADD_LINK_TARGET",t.AnchorTitle="ADD_LINK_TITLE",t.MetaDescription="OPTIMIZE_DESCRIPTION",t.DocumentTitle="OPTIMIZE_TITLE",t.MetaOpenGraph="ADD_OG_SITE_TAG",t.MetaViewport="META_VIEWPORT",t.LinkCanonical="LINK_CANONICAL",t.ImageAlternateText="ADD_ALT_TAG",t))(h||{}),m=(t=>(t.Active="ACTIVE",t.Modified="EDITED",t.Disabled="REJECTED",t))(m||{});const y=t=>{var n;const e=[];for(;t;){if(t.id){e.unshift(`/*[@id="${t.id}"]`);break}const r=((n=t.parentNode)==null?void 0:n.childNodes)??[];let o=1;for(let a=0;a<r.length;a++){const i=r[a];if(i===t){e.unshift(`${t.tagName.toLowerCase()}[${o}]`);break}i.nodeType===1&&i.tagName===t.tagName&&o++}t=t.parentNode}return"/"+e.join("/")},c={initialState:{},modifiedXPaths:{},siteActions:[],formActions:[],eventRefs:{},devMode:!1};var u=(t=>(t[t.Debug=0]="Debug",t[t.Success=1]="Success",t[t.Warning=2]="Warning",t[t.Error=3]="Error",t))(u||{});const nt=t=>t===3?"#fb2c36":t===2?"#fe9a00":t===1?"#00bc7d":"#2b7fff";function p(t,e,...n){console.log("%c[Conversion]",`color: ${nt(t)};`,e,...n),window.postMessage({id:"conversion",type:"log",data:{level:t,message:e,data:n}})}const rt=`${Q}/v3/plugin-code-changes`,ot=async()=>{try{const t=await fetch(`${rt}?url=${encodeURIComponent(window.location.origin+window.location.pathname)}`),{success:e,data:n,error:r}=await t.json();if(!e)throw new Error(r);const o=n.codeChanges.filter((a,i,s)=>s.findIndex(({xpath:d,type:l})=>d===a.xpath&&l===a.type)===i).map(a=>({...a,data:JSON.parse(a.data)}));return p(u.Success,"Successfully fetched code changes",o),o}catch{return p(u.Error,"Failed to fetch code changes"),[]}},g=t=>document.evaluate(t,document,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue,at={apply:t=>{var d;const{data:{href:e},status:n,xpath:r,id:o}=t,{initialState:a}=c,i=g(r);if(!i||i.href!==e)return;let s="_blank";n===m.Disabled&&(s=(d=a[o])==null?void 0:d.target),a[o]||(a[o]={target:i.target}),i.target=s},property:"target"},it={apply:t=>{var l;const{data:{href:e,title:n},status:r,xpath:o,id:a}=t,{initialState:i}=c,s=g(o);if(!s||s.href!==e)return;let d=n;r===m.Disabled&&(d=(l=i[a])==null?void 0:l.title),i[a]||(i[a]={title:s.title}),s.title=d},property:"title"},st={apply:t=>{var l,f;const{data:{textContent:e},status:n,xpath:r,id:o}=t,{initialState:a}=c,i=g(r);let s=e;if(n===m.Disabled){if(!i)return;if(!((l=a[o])!=null&&l.textContent)){i.remove();return}s=(f=a[o])==null?void 0:f.textContent}if(i){a[o]||(a[o]={textContent:i.textContent}),i.textContent=s;return}const d=document.createElement("title");d.textContent=s,document.head.appendChild(d)},verify:t=>t.tagName.toLowerCase()==="title"},O=(t,e)=>{var r;e.innerHTML=t.innerHTML;for(const o of t.attributes)e.setAttribute(o.name,o.value);(r=t.parentElement)==null||r.insertBefore(e,t);const n=window.getComputedStyle(t);for(const o in n){const a=n.getPropertyValue(o);if(!a)continue;t.style.setProperty(o,"unset");const i=n.getPropertyValue(o);a!==i&&(e.style[o]=a)}},ct={apply:({xpath:t,status:e})=>{const n=e===m.Disabled,{modifiedXPaths:r}=c,o=g(n?r[t]:t);if(!o)return;const a=document.createElement(n?"h1":"h2");if(O(o,a),o.remove(),n){delete r[t];return}r[t]=y(a)},verify:(t,e)=>t.tagName.toLowerCase()==="h1"&&y(t)===e.xpath},dt={apply:t=>{const{data:{tagName:e},status:n,xpath:r}=t,o=n===m.Disabled,{modifiedXPaths:a}=c,i=g(o?a[r]:r);if(!i)return;const s=document.createElement(o?e:"h1");if(O(i,s),i.remove(),o){delete a[r];return}a[r]=y(s)},verify:(t,e)=>t.tagName.toLowerCase()!=="h1"&&y(t)===e.xpath},ut={apply:t=>{var l;const{data:{alt:e,src:n},status:r,xpath:o,id:a}=t,{initialState:i}=c,s=g(o);if(!s||s.src!==n)return;let d=e;r===m.Disabled&&(d=(l=i[a])==null?void 0:l.alt),i[a]||(i[a]={alt:s.alt}),s.alt=d},property:"alt"},lt={apply:t=>{var l,f;const{data:{href:e},status:n,xpath:r,id:o}=t,{initialState:a}=c,i=g(r);let s=e;if(n===m.Disabled){if(!i)return;if(!((l=a[o])!=null&&l.href)){i.remove();return}s=(f=a[o])==null?void 0:f.href}if(i){a[o]||(a[o]={href:i.href}),i.href=s;return}const d=document.createElement("link");d.rel="canonical",d.href=s,document.head.appendChild(d)},verify:t=>t.tagName.toLowerCase()==="link"&&t.rel==="canonical",property:"href"},pt={apply:t=>{var l,f;const{data:{content:e},status:n,xpath:r,id:o}=t,{initialState:a}=c,i=g(r);let s=e;if(n===m.Disabled){if(!i)return;if(!((l=a[o])!=null&&l.content)){i.remove();return}s=(f=a[o])==null?void 0:f.content}if(i){a[o]||(a[o]={content:i.content}),i.content=s;return}const d=document.createElement("meta");d.name="description",d.content=s,document.head.appendChild(d)},verify:t=>t.tagName.toLowerCase()==="meta"&&t.name==="description",property:"content"},ft={apply:t=>{var Y,Z;const{data:{content:e,name:n,property:r},status:o,xpath:a,id:i}=t,{initialState:s}=c,d=g(a);let l=e;if(o===m.Disabled){if(!d)return;if(!((Y=s[i])!=null&&Y.content)){d.remove();return}l=(Z=s[i])==null?void 0:Z.content}if(d){s[i]||(s[i]={content:d.content}),d.content=l;return}const f=document.createElement("meta");n&&f.setAttribute("name",n),r&&f.setAttribute("property",r),f.content=l,document.head.appendChild(f)},verify:(t,e)=>{if(t.tagName.toLowerCase()!=="meta")return!1;const{data:{name:n,property:r}}=e;return n?t.name===n:t.getAttribute("property")===r},property:"content"},mt={apply:t=>{var l,f;const{data:{content:e},status:n,xpath:r,id:o}=t,{initialState:a}=c,i=g(r);let s=e;if(n===m.Disabled){if(!i)return;if(!((l=a[o])!=null&&l.content)){i.remove();return}s=(f=a[o])==null?void 0:f.content}if(i){a[o]||(a[o]={content:i.content}),i.content=s;return}const d=document.createElement("meta");d.name="viewport",d.content=s,document.head.appendChild(d)},verify:t=>t.tagName.toLowerCase()==="meta"&&t.name==="viewport",property:"content"},T={[h.HeadingDemotion]:ct,[h.HeadingPromotion]:dt,[h.ImageAlternateText]:ut,[h.AnchorTarget]:at,[h.AnchorTitle]:it,[h.MetaDescription]:pt,[h.MetaOpenGraph]:ft,[h.DocumentTitle]:st,[h.MetaViewport]:mt,[h.LinkCanonical]:lt};let w=[],P=null,A={};const ht=8,k=(t,e)=>{if(t instanceof HTMLElement&&["title","h1","h2","h3","h4","h5","h6","meta","link","a","img"].includes(t.tagName.toLowerCase()))for(const n of e){if(A[n.id]===ht)continue;const{verify:r,property:o,apply:a}=T[n.type];if(!(r?r(t,n):y(t)===n.xpath)||n.type===h.AnchorTarget&&t.target==="_blank"||o&&t[o]===n.data[o])continue;const s=A[n.id]||0;A[n.id]=s+1,a(n)}},v=new MutationObserver(t=>{for(const{target:e,addedNodes:n}of t){k(e,w);for(const r of n)k(r,w)}}),R=t=>{if(t)try{return new URL(t,window.location.href).pathname}catch{return}},F=t=>{const e=R(t);if(!e||e===P||(v==null||v.disconnect(),!w))return;const n=w.filter(({status:r})=>r!==m.Disabled).map(r=>({...r,status:m.Disabled}));for(const r of n)T[r.type].apply(r);c.initialState={}},N=async t=>{const e=R(t);if(!(!e||e===P)){P=e,A={},w=await ot();for(const n of w)T[n.type].apply(n);v==null||v.observe(document,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["alt","property","content","title","target","href"]})}},gt=history.pushState;history.pushState=function(...t){F(t[2]),gt.apply(history,t),N(t[2])};const yt=history.replaceState;history.replaceState=function(...t){F(t[2]),yt.apply(history,t),N(t[2])};const H=[J,et,tt],wt=t=>{var e;for(const n of H)(e=window.opener)==null||e.postMessage(t,n)},U="_s__t",j="_s__s",V=1e3*60*60*24*365,z=()=>{const t=document.cookie.split("; ").find(e=>e.startsWith(`${j}=`));return t==null?void 0:t.split("=")[1]},vt=t=>{if(z()&&document.referrer)try{if(new URL(document.referrer).hostname.endsWith(t)){p(u.Debug,"Ignoring referrer URL",document.referrer);return}}catch(o){p(u.Error,"Failed to parse referrer URL",o);return}const n=crypto.randomUUID(),r=new Date;r.setTime(r.getTime()+V),document.cookie=`${j}=${n}; path=/; domain=${t}; expires=${r.toUTCString()}`,p(u.Debug,"Set session ID",n)},B=()=>{const t=document.cookie.split("; ").find(e=>e.startsWith(`${U}=`));return t==null?void 0:t.split("=")[1]},Et=t=>{const e=B();if(e){p(u.Debug,"Found tracking ID",e);return}const n=crypto.randomUUID(),r=new Date;r.setTime(r.getTime()+V),document.cookie=`${U}=${n}; path=/; domain=${t}; expires=${r.toUTCString()}`,p(u.Debug,"Set tracking ID",n)},bt=async(t,e)=>{const n=B(),r=z();if(!n)return p(u.Error,"Failed to send request","No tracking ID found"),!1;try{return await fetch(t,{...e,keepalive:!0,method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({pageUrl:window.location.origin+window.location.pathname,trackingId:n,sessionId:r,...e==null?void 0:e.body})}),!0}catch{return!1}};var E=(t=>(t.PageVisit="PAGE_VISIT",t.FormSubmission="FORM_SUBMISSION",t))(E||{}),_=(t=>(t.Custom="CUSTOM",t.Hubspot="HUBSPOT",t.Default="DEFAULT",t))(_||{});async function $(t,e){const n=await bt(`${I}/v1/e/t`,{body:{data:e,type:t}});return n?p(u.Success,"Successfully tracked engagement",{type:t,data:e}):p(u.Error,"Failed to track engagement",{type:t,data:e}),n}const It=t=>{if(t.id)return[t.id];if(t.name)return[t.name];const e=Array.from(t.classList);if(e.length>0)return e;const n=t.getAttribute("action");if(n)return[n]},Dt=t=>{p(u.Debug,"Detected a form submission");const e=t.target,n=new FormData(e),r=Array.from(n.entries()).reduce((a,[i,s])=>{const d=e.querySelector(`[name="${i}"]`);return i.toLowerCase().includes("password")||d&&d.type==="password"?(p(u.Debug,"Detected a sensitive form field",{name:i}),a):(a.push({name:i.toString(),value:s.toString()}),a)},[]),o=It(e);if(!o){p(u.Warning,"Did not track form submission for a form without a key",{fields:r});return}$(E.FormSubmission,{type:_.Custom,key:o,submission:{fields:r}})},At=()=>{document.addEventListener("submit",Dt)},_t=async()=>{try{const t=await fetch(`${I}/v1/bd?url=${encodeURIComponent(window.location.origin+window.location.pathname)}`);if(!t.ok)return;const{data:e}=await t.json();return e}catch{p(u.Error,"Failed to fetch base domain",window.location.href)}},$t=t=>{if(!window.HubSpotFormsV4)return;const e=window.HubSpotFormsV4.getFormFromEvent(t);e&&$(E.FormSubmission,{type:_.Hubspot,key:[e.getFormId()],submission:{fields:e.getFormFieldValues()}})},St=()=>{window.addEventListener("hs-form-event:on-submission:success",$t)},Ct=t=>{var n;if(((n=t.data)==null?void 0:n.type)!=="hsFormCallback")return;const e=t.data;e.eventName==="onBeforeFormSubmit"&&$(E.FormSubmission,{type:_.Hubspot,key:[e.id],submission:{fields:e.data}})},Tt=()=>{window.addEventListener("message",Ct)},Pt=()=>{const t=new URLSearchParams(window.location.search);return Array.from(t).reduce((n,[r,o])=>(r.startsWith("utm_")&&(n[r]=o),n),{})};let W=!1;const Nt=async()=>{if(W)return!0;const t=await _t();return t?(W=!0,vt(t),Et(t),St(),Tt(),At(),!0):!1},xt=async()=>{await Nt()&&$(E.PageVisit,{utmFields:Pt()})},Lt=t=>{const e=t.tagName.toLowerCase();if(e==="a"&&t.href)return"a";if(e==="button")return"button";if(e==="input"){const n=t.getAttribute("type");if(n==="submit"||n==="button")return`input[type='${n}']`}else if(t.getAttribute("role")==="button")return`${e}[role='button']`},Mt=t=>{var n;const e=t.tagName.toLowerCase();return e==="a"&&t.href?t.href:e==="input"?t.value:t.textContent?(n=t.textContent)==null?void 0:n.trim().toLowerCase():t.innerText?t.innerText.trim().toLowerCase():""},x=(t,e)=>e.matchType===M.Exact?e.path===window.location.pathname&&e.xpath===y(t):e.tagType!==Lt(t)?!1:Mt(t)===e.content||y(t)===e.xpath,S=["button","a[href]:not([href=''])","[role='button']","input[type='submit']","input[type='button']"],G=(t,e)=>{const{eventRefs:n}=c;e.addEventListener("click",n[t.id],!0)},Ot=(t,e)=>{const{eventRefs:n}=c;e.removeEventListener("click",n[t.id],!0)},kt=t=>{Array.from(document.querySelectorAll(S.join(","))).forEach(n=>{x(n,t)&&G(t,n)})},Rt=t=>{if(!c.eventRefs[t.id])return;Array.from(document.querySelectorAll(S.join(","))).forEach(n=>{x(n,t)&&Ot(t,n)})},X=(t,e)=>{t.forEach(n=>{x(e,n)&&G(n,e)})},Ft=t=>{const e=new MutationObserver(n=>{n.forEach(r=>{r.type==="childList"&&r.addedNodes.forEach(o=>{if(o.nodeType===Node.ELEMENT_NODE){const a=o;a.matches(S.join(","))?X(t,a):a.querySelectorAll(S.join(",")).forEach(i=>X(t,i))}})})});return e.observe(document,{childList:!0,subtree:!0}),e},Ht=t=>{if(c.devMode)return;const e={send_to:`${c.gtagId}/${t}`};window.gtag("event","conversion",e)},Ut=()=>{if(!c.gtagId&&!c.gaMeasurementId||c.gInstalled)return;const t=document.createElement("script");t.async=!0,t.src=`https://www.googletagmanager.com/gtag/js?id=${c.gtagId??c.gaMeasurementId}`,t.onload=()=>c.gInstalled=!0,document.head.appendChild(t),window.dataLayer=window.dataLayer||[],window.gtag=function(){window.dataLayer.push(arguments)},window.gtag("js",new Date),c.gtagId&&window.gtag("config",c.gtagId),c.gaMeasurementId&&window.gtag("config",c.gaMeasurementId)},jt=`${I}/v1/a`,Vt=async()=>{try{const t=await fetch(`${jt}?domain=${encodeURIComponent(window.location.origin+window.location.pathname)}`),{success:e,data:n,error:r}=await t.json();if(!e)throw new Error(r);return n}catch{return null}},zt=async()=>{try{const t=await fetch(`${I}/v1/c?url=${encodeURIComponent(window.location.origin+window.location.pathname)}`),{success:e,data:n,error:r}=await t.json();if(!e&&r!==10404)throw new Error(r.toString());return n}catch{return null}};let q=null,C=null;const L=async()=>{if(window.location.pathname===q)return;q=window.location.pathname,C&&(C.disconnect(),C=null),c.siteActions.forEach(n=>{Rt(n)}),c.eventRefs={};const[t,e]=await Promise.all([zt(),Vt()]);t&&(c.gtagId=t.gtagId,c.siteActions=t.conversionEvents,c.formActions=t.formConversionActions),e&&(c.gaMeasurementId=e),Ut(),xt(),t&&(t.conversionEvents.forEach(n=>{const r=Ht.bind(null,n.gtagEventId);c.eventRefs[n.id]=r,kt(n)}),C=Ft(t.conversionEvents))},Bt=history.pushState;history.pushState=function(...t){Bt.apply(history,t),L()};const Wt=history.replaceState;history.replaceState=function(...t){Wt.apply(history,t),L()};const Gt="https://p.conversion.ai/astra/editor";let b;const Xt=()=>{c.devMode||(c.devMode=!0,b=document.createElement("script"),b.src=Gt,b.id="astra-editor-script",document.head.appendChild(b))},qt=()=>{c.devMode=!1,b.remove()},Kt=t=>{if(!H.includes(t.origin)||!t.data.type)return;const{type:e}=t.data;e===D.AdwinEnableDev?Xt():e===D.AdwinDisableDev&&qt()},Yt=()=>{window.addEventListener("message",Kt)},K=()=>{p(u.Debug,"Initializing pixel"),N(window.location.href),L(),Yt(),wt({type:D.AdwinJsReady})};(()=>{if(p(u.Debug,"Loading pixel"),window.self!==window.parent||window.location.href==="about:srcdoc"){p(u.Warning,"Injecting pixel in parent window");try{if(window.parent.__conversion_loaded){p(u.Warning,"Pixel already loaded in the parent window");return}const t=window.parent.document.createElement("script");t.src="https://p.conversion.ai",t.defer=!0,window.parent.document.head.appendChild(t),p(u.Debug,"Injected pixel in parent window")}catch(t){p(u.Error,"Failed to inject pixel in parent window",t)}return}if(window.__conversion_loaded){p(u.Warning,"Pixel already loaded");return}if(window.__conversion_loaded=!0,p(u.Success,"Pixel loaded"),document.readyState==="loading"){document.addEventListener("DOMContentLoaded",K);return}K()})()})();
