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