(function(){var e=`https://seonaapi.conversion.ai/api`,t=`https://p.conversion.ai/api`,n={HeadingPromotion:`H1_PROMOTION`,HeadingDemotion:`H1_DEMOTION`,AnchorTarget:`ADD_LINK_TARGET`,AnchorTitle:`ADD_LINK_TITLE`,MetaDescription:`OPTIMIZE_DESCRIPTION`,DocumentTitle:`OPTIMIZE_TITLE`,MetaOpenGraph:`ADD_OG_SITE_TAG`,MetaViewport:`META_VIEWPORT`,LinkCanonical:`LINK_CANONICAL`,ImageAlternateText:`ADD_ALT_TAG`},r={Active:`ACTIVE`,Modified:`EDITED`,Disabled:`REJECTED`},i=e=>{let t=[];for(;e;){if(e.id){t.unshift(`/*[@id="${e.id}"]`);break}let n=e.parentNode?.childNodes??[],r=1;for(let i=0;i<n.length;i++){let a=n[i];if(a===e){t.unshift(`${e.tagName.toLowerCase()}[${r}]`);break}a.nodeType===1&&a.tagName===e.tagName&&r++}e=e.parentNode}return`/`+t.join(`/`)},a={initialState:{},modifiedXPaths:{}},o={Debug:0,Success:1,Warning:2,Error:3},s=e=>e===o.Error?`#fb2c36`:e===o.Warning?`#fe9a00`:e===o.Success?`#00bc7d`:`#2b7fff`;function c(e,t,...n){console.log(`%c[Conversion]`,`color: ${s(e)};`,t,...n),window.postMessage({id:`conversion`,type:`log`,data:{level:e,message:t,data:n}})}var l=`${e}/v3/plugin-code-changes`,u=async()=>{try{let{success:e,data:t,error:n}=await(await fetch(`${l}?url=${encodeURIComponent(window.location.origin+window.location.pathname)}`)).json();if(!e)throw Error(n);let r=t.codeChanges.filter((e,t,n)=>n.findIndex(({xpath:t,type:n})=>t===e.xpath&&n===e.type)===t).map(e=>({...e,data:JSON.parse(e.data)}));return c(o.Success,`Successfully fetched code changes`,r),r}catch{return c(o.Error,`Failed to fetch code changes`),[]}},d=e=>document.evaluate(e,document,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue,f={apply:e=>{let{data:{href:t},status:n,xpath:i,id:o}=e,{initialState:s}=a,c=d(i);if(!c||c.href!==t)return;let l=`_blank`;n===r.Disabled&&(l=s[o]?.target),s[o]||(s[o]={target:c.target}),c.target=l},property:`target`},p={apply:e=>{let{data:{href:t,title:n},status:i,xpath:o,id:s}=e,{initialState:c}=a,l=d(o);if(!l||l.href!==t)return;let u=n;i===r.Disabled&&(u=c[s]?.title),c[s]||(c[s]={title:l.title}),l.title=u},property:`title`},m={apply:e=>{let{data:{textContent:t},status:n,xpath:i,id:o}=e,{initialState:s}=a,c=d(i),l=t;if(n===r.Disabled){if(!c)return;if(!s[o]?.textContent){c.remove();return}l=s[o]?.textContent}if(c){s[o]||(s[o]={textContent:c.textContent}),c.textContent=l;return}let u=document.createElement(`title`);u.textContent=l,document.head.appendChild(u)},verify:e=>e.tagName.toLowerCase()===`title`},h=(e,t)=>{t.innerHTML=e.innerHTML;for(let n of e.attributes)t.setAttribute(n.name,n.value);e.parentElement?.insertBefore(t,e);let n=window.getComputedStyle(e);for(let r in n){let i=n.getPropertyValue(r);i&&(e.style.setProperty(r,`unset`),i!==n.getPropertyValue(r)&&(t.style[r]=i))}},g={apply:({xpath:e,status:t})=>{let n=t===r.Disabled,{modifiedXPaths:o}=a,s=d(n?o[e]:e);if(!s)return;let c=document.createElement(n?`h1`:`h2`);if(h(s,c),s.remove(),n){delete o[e];return}o[e]=i(c)},verify:(e,t)=>e.tagName.toLowerCase()===`h1`&&i(e)===t.xpath},_={apply:e=>{let{data:{tagName:t},status:n,xpath:o}=e,s=n===r.Disabled,{modifiedXPaths:c}=a,l=d(s?c[o]:o);if(!l)return;let u=document.createElement(s?t:`h1`);if(h(l,u),l.remove(),s){delete c[o];return}c[o]=i(u)},verify:(e,t)=>e.tagName.toLowerCase()!==`h1`&&i(e)===t.xpath},v={apply:e=>{let{data:{alt:t,src:n},status:i,xpath:o,id:s}=e,{initialState:c}=a,l=d(o);if(!l||l.src!==n)return;let u=t;i===r.Disabled&&(u=c[s]?.alt),c[s]||(c[s]={alt:l.alt}),l.alt=u},property:`alt`},y={apply:e=>{let{data:{href:t},status:n,xpath:i,id:o}=e,{initialState:s}=a,c=d(i),l=t;if(n===r.Disabled){if(!c)return;if(!s[o]?.href){c.remove();return}l=s[o]?.href}if(c){s[o]||(s[o]={href:c.href}),c.href=l;return}let u=document.createElement(`link`);u.rel=`canonical`,u.href=l,document.head.appendChild(u)},verify:e=>e.tagName.toLowerCase()===`link`&&e.rel===`canonical`,property:`href`},b={apply:e=>{let{data:{content:t},status:n,xpath:i,id:o}=e,{initialState:s}=a,c=d(i),l=t;if(n===r.Disabled){if(!c)return;if(!s[o]?.content){c.remove();return}l=s[o]?.content}if(c){s[o]||(s[o]={content:c.content}),c.content=l;return}let u=document.createElement(`meta`);u.name=`description`,u.content=l,document.head.appendChild(u)},verify:e=>e.tagName.toLowerCase()===`meta`&&e.name===`description`,property:`content`},x={apply:e=>{let{data:{content:t,name:n,property:i},status:o,xpath:s,id:c}=e,{initialState:l}=a,u=d(s),f=t;if(o===r.Disabled){if(!u)return;if(!l[c]?.content){u.remove();return}f=l[c]?.content}if(u){l[c]||(l[c]={content:u.content}),u.content=f;return}let p=document.createElement(`meta`);n&&p.setAttribute(`name`,n),i&&p.setAttribute(`property`,i),p.content=f,document.head.appendChild(p)},verify:(e,t)=>{if(e.tagName.toLowerCase()!==`meta`)return!1;let{data:{name:n,property:r}}=t;return n?e.name===n:e.getAttribute(`property`)===r},property:`content`},S={apply:e=>{let{data:{content:t},status:n,xpath:i,id:o}=e,{initialState:s}=a,c=d(i),l=t;if(n===r.Disabled){if(!c)return;if(!s[o]?.content){c.remove();return}l=s[o]?.content}if(c){s[o]||(s[o]={content:c.content}),c.content=l;return}let u=document.createElement(`meta`);u.name=`viewport`,u.content=l,document.head.appendChild(u)},verify:e=>e.tagName.toLowerCase()===`meta`&&e.name===`viewport`,property:`content`},C={[n.HeadingDemotion]:g,[n.HeadingPromotion]:_,[n.ImageAlternateText]:v,[n.AnchorTarget]:f,[n.AnchorTitle]:p,[n.MetaDescription]:b,[n.MetaOpenGraph]:x,[n.DocumentTitle]:m,[n.MetaViewport]:S,[n.LinkCanonical]:y},w=[],T=null,E={},D=8,O=(e,t)=>{if(e instanceof HTMLElement&&[`title`,`h1`,`h2`,`h3`,`h4`,`h5`,`h6`,`meta`,`link`,`a`,`img`].includes(e.tagName.toLowerCase()))for(let r of t){if(E[r.id]===D)continue;let{verify:t,property:a,apply:o}=C[r.type];if(!(t?t(e,r):i(e)===r.xpath)||r.type===n.AnchorTarget&&e.target===`_blank`||a&&e[a]===r.data[a])continue;let s=E[r.id]||0;E[r.id]=s+1,o(r)}},k=new MutationObserver(e=>{for(let{target:t,addedNodes:n}of e){O(t,w);for(let e of n)O(e,w)}}),A=e=>{if(e)try{return new URL(e,window.location.href).pathname}catch{return}},j=e=>{let t=A(e);if(!t||t===T||(k?.disconnect(),!w))return;let n=w.filter(({status:e})=>e!==r.Disabled).map(e=>({...e,status:r.Disabled}));for(let e of n)C[e.type].apply(e);a.initialState={}},M=async e=>{let t=A(e);if(!(!t||t===T)){T=t,E={},w=await u();for(let e of w)C[e.type].apply(e);k?.observe(document,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`alt`,`property`,`content`,`title`,`target`,`href`]})}},N=history.pushState;history.pushState=function(...e){j(e[2]),N.apply(history,e),M(e[2])};var P=history.replaceState;history.replaceState=function(...e){j(e[2]),P.apply(history,e),M(e[2])};var F=async()=>{try{let e=await fetch(`${t}/v1/bd?url=${encodeURIComponent(window.location.origin+window.location.pathname)}`);if(!e.ok)return;let{data:n}=await e.json();return n}catch{c(o.Error,`Failed to fetch base domain`,window.location.href)}},I=`_s__t`,L=`_s__s`,R=`_s__s__set`,z=1e3*60*60*24*365,B=()=>document.cookie.split(`; `).find(e=>e.startsWith(`${L}=`))?.split(`=`)[1],V=e=>{let t=B();if(t&&sessionStorage.getItem(R)){c(o.Debug,`Continuing existing session`,t);return}if(t&&document.referrer)try{if(new URL(document.referrer).hostname.endsWith(e)){c(o.Debug,`Ignoring referrer URL`,document.referrer),sessionStorage.setItem(R,`true`);return}}catch(e){c(o.Error,`Failed to parse referrer URL`,e);return}let n=crypto.randomUUID(),r=new Date;r.setTime(r.getTime()+z),document.cookie=`${L}=${n}; path=/; domain=${e}; expires=${r.toUTCString()}`,sessionStorage.setItem(R,`true`),c(o.Debug,`Set session ID`,n)},H=()=>document.cookie.split(`; `).find(e=>e.startsWith(`${I}=`))?.split(`=`)[1],U=e=>{let t=H();if(t){c(o.Debug,`Found tracking ID`,t);return}let n=crypto.randomUUID(),r=new Date;r.setTime(r.getTime()+z),document.cookie=`${I}=${n}; path=/; domain=${e}; expires=${r.toUTCString()}`,c(o.Debug,`Set tracking ID`,n)},W=async(e,t,n=!0)=>{let r=H(),i=B();if(!n&&!r&&(c(o.Warning,`Unable to find tracking ID, generating a fallback ID`),r=crypto.randomUUID()),!n&&!i&&(c(o.Warning,`Unable to find session ID, generating a fallback ID`),i=crypto.randomUUID()),!r)return c(o.Error,`Failed to send request`,`No tracking ID found`),!1;try{return await fetch(e,{...t,keepalive:!0,method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({pageUrl:window.location.origin+window.location.pathname,trackingId:r,sessionId:i,referrer:document.referrer,...t?.body})}),!0}catch{return!1}},G={PageVisit:`PAGE_VISIT`,FormSubmission:`FORM_SUBMISSION`};async function K(e,n){let r=await W(`${t}/v1/e/t`,{body:{data:n,type:e}},e!==G.FormSubmission);return r?c(o.Success,`Successfully tracked engagement`,{type:e,data:n}):c(o.Error,`Failed to track engagement`,{type:e,data:n}),r}var q=()=>{let e=new URLSearchParams(window.location.search);return Array.from(e).reduce((e,[t,n])=>((t.startsWith(`utm_`)||t.startsWith(`cai_`))&&(e[t]=n),e),{})},J=null,Y=async()=>{if(window.__conversion_initialized)return!0;let e=await F();return e?(V(e),U(e),window.__conversion_initialized=!0,window.dispatchEvent(new CustomEvent(`__conversion:initialized`)),!0):!1},X=async()=>{window.location.pathname!==J&&(J=window.location.pathname,await Y()&&K(G.PageVisit,{utmFields:q()}))},Z=history.pushState;history.pushState=function(...e){Z.apply(history,e),X()};var Q=history.replaceState;history.replaceState=function(...e){Q.apply(history,e),X()};var $=()=>{c(o.Debug,`Initializing pixel`),M(window.location.href),X()};(()=>{if(c(o.Debug,`Loading pixel`),window.self!==window.parent||window.location.href===`about:srcdoc`){c(o.Warning,`Injecting pixel in parent window`);try{if(window.parent.__conversion_loaded){c(o.Warning,`Pixel already loaded in the parent window`);return}let e=window.parent.document.createElement(`script`);e.src=`https://p.conversion.ai`,e.defer=!0,window.parent.document.head.appendChild(e),c(o.Debug,`Injected pixel in parent window`)}catch(e){c(o.Error,`Failed to inject pixel in parent window`,e)}return}if(window.__conversion_loaded){c(o.Warning,`Pixel already loaded`);return}if(window.__conversion_loaded=!0,c(o.Success,`Pixel loaded`),document.readyState===`loading`){document.addEventListener(`DOMContentLoaded`,$);return}$()})()})();