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