1(()=>{if(!window.__MEGA_OPTIMIZER_LOADED__){window.__MEGA_OPTIMIZER_LOADED__=!0;let i=18e5,x={VISITOR_ID:"_mega_vid",SESSION_ID:"_mega_sid",LAST_ACTIVITY:"_mega_last",ATTRIBUTION:"_mega_attr",INITIAL_LANDING_PAGE:"_mega_initial_landing_page",INITIAL_REFERRER:"_mega_initial_referrer"},L="1"===new URLSearchParams(window.location.search).get("mega_debug"),h=(r=new URLSearchParams(window.location.search).get("mega_max_per_type"),a="undefined"!=typeof window?window.MEGA_MAX_PER_TYPE:void 0,r=Number(r??a),Number.isFinite(r)&&0<r&&r<=500?Math.floor(r):Number.POSITIVE_INFINITY);var a,r;a=new URLSearchParams(window.location.search).get("mega_max_apply_ms"),r="undefined"!=typeof window?window.MEGA_MAX_APPLY_MS:void 0,a=Number(a??r);let n=Number.isFinite(a)&&0<a&&a<=3e4?Math.floor(a):100,O=3,e=(()=>{let o={siteKey:null,debug:!1,gtmId:null,gaId:null,pixelId:null,ctmAccountId:null},s={visitorId:null,sessionId:null,lastSessionActivity:null,attribution:{},initialLandingPage:null,initialReferrer:null,initialized:!1},c=new WeakMap;function u(){let e=P(x.VISITOR_ID,"cookie");(e=e||P(x.VISITOR_ID,"local"))?D("Retrieved visitor ID:",e):D("Generated new visitor ID:",e=k("vis")),M(x.VISITOR_ID,e,"cookie"),M(x.VISITOR_ID,e,"local"),s.visitorId=e}function d(){var e=Date.now();let t=P(x.SESSION_ID,"session");var n=P(x.LAST_ACTIVITY,"local");t&&n&&e-parseInt(n,10)>i&&(D("Session expired (timeout), generating new session ID"),t=null),t?D("Retrieved session ID:",t):D("Generated new session ID:",t=k("sess")),s.sessionId=t,s.lastSessionActivity=e,M(x.SESSION_ID,t,"session"),M(x.LAST_ACTIVITY,e.toString(),"local"),t}function p(){var e=Date.now();s.lastSessionActivity=e,M(x.LAST_ACTIVITY,e.toString(),"local")}function r(){return s.visitorId||u(),s.visitorId}function l(){return s.sessionId||d(),s.sessionId}function m(){let e=P(x.INITIAL_LANDING_PAGE,"local"),t=P(x.INITIAL_REFERRER,"local");e?D("Retrieved initial landing data:",{initialLandingPage:e,initialReferrer:t}):(e=window.location.href,t=document.referrer||null,M(x.INITIAL_LANDING_PAGE,e,"local"),t&&M(x.INITIAL_REFERRER,t,"local"),D("Captured initial landing data:",{initialLandingPage:e,initialReferrer:t})),s.initialLandingPage=e,s.initialReferrer=t,e,t}function a(){var e={},t=new URL(window.location.href).searchParams;return e.utm_source=t.get("utm_source")||null,e.utm_medium=t.get("utm_medium")||null,e.utm_campaign=t.get("utm_campaign")||null,e.utm_term=t.get("utm_term")||null,e.utm_content=t.get("utm_content")||null,e.utm_id=t.get("utm_id")||null,e.click_id=t.get("click_id")||null,e.gclid=t.get("gclid")||null,e.gbraid=t.get("gbraid")||null,e.wbraid=t.get("wbraid")||null,e.fbclid=t.get("fbclid")||null,e.fbp=R("_fbp")||null,e.fbc=R("_fbc")||null,e.fbclid&&!e.fbc&&(e.fbc="fb.1."+Date.now()+"."+e.fbclid),e.landing_page=window.location.href,e.referrer=document.referrer||null,D("Captured attribution:",e),e}function g(){let t=new URL(window.location.href);if(["utm_source","gclid","fbclid","click_id"].some(e=>
1t.searchParams.has(e))){D("URL has tracking params, capturing fresh attribution");let e=a();return s.attribution=e,M(x.ATTRIBUTION,JSON.stringify(e),"local"),e.gclid&&M("_mega_gclid",e.gclid,"cookie"),e.fbclid&&M("_mega_fbclid",e.fbclid,"cookie"),e.utm_source&&M("_mega_utm_source",e.utm_source,"cookie"),e}if(0<Object.keys(s.attribution).length)return s.attribution;var e=P(x.ATTRIBUTION,"local");if(e)try{return s.attribution=JSON.parse(e),s.attribution}catch{D("Failed to parse stored attribution")}e={gclid:P("_mega_gclid","cookie"),fbclid:P("_mega_fbclid","cookie"),utm_source:P("_mega_utm_source","cookie")};if(e.gclid||e.fbclid||e.utm_source)return D("Recovered attribution from backup cookies"),s.attribution={...s.attribution,...e},M(x.ATTRIBUTION,JSON.stringify(s.attribution),"local"),s.attribution;let n=a();return s.attribution=n,M(x.ATTRIBUTION,JSON.stringify(n),"local"),n}function f(e,t){var n="https://events-api.gomega.ai",i=JSON.stringify(e);return D("Sending event:",e),t&&navigator.sendBeacon?(e=new Blob([i],{type:"application/json"}),D("Event sent via beacon:",t=navigator.sendBeacon(n,e)),Promise.resolve({sent:t})):fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:i,keepalive:!0}).then(e=>{if(e.ok)return D("Event sent successfully"),e;throw new Error("HTTP "+e.status)}).catch(e=>{throw D("Failed to send event:",e),e})}function h(e,t,n,i){var a=g();return{eventId:k("evt"),eventType:e,sessionId:l(),userId:r(),clientTimestamp:(new Date).toISOString(),currentUrl:window.location.href,context:null,userAgent:navigator.userAgent,referrer:document.referrer||null,pageLoadTime:Math.round(performance.now()),ip:null,clickData:t||null,siteKey:o.siteKey||null,visitorId:r(),source:n||"web",initialLandingPage:(s.initialLandingPage||m(),s.initialLandingPage||null),initialReferrer:(s.initialReferrer||null===s.initialReferrer||m(),s.initialReferrer||null),pixelId:o.pixelId||null,gtmId:o.gtmId||null,googleTagId:o.gaId||null,utmSource:a.utm_source||null,utmMedium:a.utm_medium||null,utmCampaign:a.utm_campaign||null,utmTerm:a.utm_term||null,utmContent:a.utm_content||null,utmId:a.utm_id||null,clickId:a.click_id||null,gclid:a.gclid||null,gbraid:a.gbraid||null,wbraid:a.wbraid||null,fbclid:a.fbclid||null,fbp:a.fbp||null,fbc:a.fbc||null,value:null,currency:null,formId:i?.formId||null,formData:i?.fields||null}}function y(t){if(!t)return"";var e=t.tagName?.toLowerCase();if("input"===e)return("submit"===t.type||"button"===t.type)&&t.value||"";if("button"===e){let e=t.innerText?.trim().substring(0,50);return e?e:t.title?t.title.substring(0,50):t.getAttribute("aria-label")?t.getAttribute("aria-label").substring(0,50):""}if("a"===e){if(t.innerText){let e=t.innerText.trim().substring(0,50);if(e)return e}if(t.title)return t.title.substring(0,50);if(t.alt)return t.alt.substring(0,50)}if("img"===e)return t.alt?t.alt.substring(0,50):t.title?t.title.substring(0,50):"[image]";let n=t.innerText||t.textContent||"";return n.trim().substring(0,50)}function b(e){if(e){if("string"==typeof e)return e;if("object"==typeof e&&null!==e){var t;for(t of["href","url","link","path","to","pathname"])if(e[t]&&"string"==typeof e[t])return e[t];if("function"==typeof e.toString){var n=e.toString();if("[object Object]"!==n&&n.includes("://"))return n}}}return""}function w(e){if(!e||"string"!=typeof e)return"";if(e.includes("://"))return e;if(e.startsWith("/")&&!e.startsWith("//"))return window.location.origin+e;try{return new URL(e,window.location.href).href}catch{return e}}function I(e){if(e&&"string"==typeof e)try{var t=new URL(e,window.location.origin);return t.href&&("http:"===t.protocol||"https:"===t.protocol||"mailto:"===t.protocol||"tel:"===t.protocol)}catch{}}function _(e){var t,n={};for(t of e.attributes)n[t.name]=t.value;return n}function T(e){var t=e.getAttribute("id");if(t)return"#"+t;let n=e.tagName.toLowerCase();return e.className&&"string"==typeof e.className&&(t=e.className.split(" ").filter(e=>e).join("."))&&(n+="."+t),n}function v(e){e=e.closest("section, article, form, nav, header, footer, main, div");return e?{tag:e.tagName,id:e.getAttribute("id")||null,class:e.className||null}:null}function A(){p(),f(h("page_view",{targetUrl:null,elementText:document.title||null,elementType:"page",elementId:null,elementClasses:null,elementAttributes:{title:document.title,path:window.location.pathname},isActualTarget:!0,viewport:{width:window.innerWidth,height:window.innerHeight},scroll:{x:0,y:0},mousePosition:null},"web"),!1)}function C(e){var t,n,i,a,r,l,o,s,u,c,d,m,g;0===e.button&&(n=(e=>{var t=e.closest('a, button, input[type="submit"], input[type="button"], [role="button"], [role="link"], [onclick]');if(t)return t;var n=["[data-action]","[data-click]","[data-href]","[data-url]","[data-link]",".btn",".button",".clickable",".link",'[style*="cursor: pointer"]','[tabindex]:not
1([tabindex="-1"])'].join(", ");if(t=e.closest(n)){var n="pointer"===window.getComputedStyle(t).cursor,i=null!==t.onclick;if(n||i||t.hasAttribute("data-action")||t.hasAttribute("data-href")||t.hasAttribute("data-url")||t.hasAttribute("data-click")||t.hasAttribute("data-link"))return t}let a=e;for(;a&&a!==document.body;){var r=a.tagName?a.tagName.toLowerCase():"";if(r.includes("button")||r.includes("-widget"))return a;a=a.parentElement}return null})(t=e.target))&&(p(),a=(i=n.closest("form"))&&("submit"===n.type||"BUTTON"===n.tagName&&(!n.type||"submit"===n.type)),l=(r=n.getAttribute("href")||"").startsWith("tel:"),o=w((e=>{if("a"===e.tagName?.toLowerCase()&&e.href&&I(e.href))return e.href;var t,n;if("FORM"===e.tagName)return I(t=b(e.action||window.location.href))?t:"";for(n of[e.getAttribute("data-href"),e.getAttribute("data-url"),e.getAttribute("data-link")])if(n)try{var i=b(JSON.parse(n));if(i&&I(i))return i}catch{var a=b(n);if(a&&I(a))return a}var r,l=e.getAttribute("onclick");if(l&&(l.includes("location")||l.includes("window.open")))for(r of[/location\.href\s*=\s*['"`]([^'"`]+)['"`]/,/window\.location\s*=\s*['"`]([^'"`]+)['"`]/,/window\.open\s*\(\s*['"`]([^'"`]+)['"`]/]){var o=l.match(r);if(o&&o[1]){o=b(o[1]);if(I(o))return o}}return""})(n)),s=y(n),u=n.tagName?.toLowerCase()||"unknown",c=v(n),m="a"===(m=(g=n).tagName?.toLowerCase())&&g.href?!(d=g.href).startsWith("javascript:")&&d!==window.location.href+"#"&&!d.endsWith("#"):!!("form"===m||"input"===m&&["submit","button"].includes(g.type))||!(!(d=g.getAttribute("onclick"))||!d.includes("location")&&!d.includes("window.open")),(g=h("click",{targetUrl:o,elementText:s,elementType:u,elementId:n.getAttribute("id")||null,elementClasses:n.className||null,elementAttributes:_(n),selector:T(n),isActualTarget:n===t,viewport:{width:window.innerWidth,height:window.innerHeight},scroll:{x:window.scrollX,y:window.scrollY},mousePosition:{x:e.clientX,y:e.clientY}},"web")).context=c?JSON.stringify(c):null,l&&(g.formData={tel:r.replace("tel:","")}),f(g,m),a)&&E(i,"button_click")}function E(e,t){let n,i=null;if(e&&e.target?(n=e.target,i=e.submitter):n=e,n&&"FORM"===n.tagName){var e=Date.now(),a=c.get(n);if(a&&e-a<1e3)D("Skipping duplicate form submission",{timeSinceLastSubmit:e-a});else{c.set(n,e),p();var a=(e=>{var t={},n=e.elements;for(let e=0;e<n.length;e++){var i=n[e];i.name&&"password"!==i.type&&("checkbox"===i.type?t[i.name]=i.checked:"radio"===i.type?i.checked&&(t[i.name]=i.value):(i.tagName,t[i.name]=i.value))}return t})(n),e=n.getAttribute("id")||n.getAttribute("name")||null,r=n.action||null,l=[];for(let e=0;e<n.elements.length;e++){var o=n.elements[e];o.name&&"password"!==o.type&&l.push(o.name)}i=i||n.querySelector('input[type="submit"], button[type="submit"], button:not([type])');var s=v(n),u={targetUrl:w(r||window.location.href),elementText:i?y(i):"[form]",elementType:"form",elementId:e,elementClasses:n.className||null,elementAttributes:_(n),selector:T(n),isActualTarget:!0,viewport:{width:window.innerWidth,height:window.innerHeight},scroll:{x:window.scrollX,y:window.scrollY},mousePosition:null},e={formId:e,fields:a,fieldNames:l,fieldCount:l.length,formAction:r,formMethod:n.getAttribute("method")||"GET"},a=(t&&(e.submissionMethod=t),h("form_submit",u,"web",e));a.context=JSON.stringify({parentContext:s,formAction:r,formMethod:n.getAttribute("method")||"GET",fieldNames:l}),f(a,!0)}}}function N(i){if(i.origin!==window.location.origin)if(!["https://challenges.cloudflare.com","https://www.googletagmanager.com","https://www.google-analytics.com","https://googleads.g.doubleclick.net","https://td.doubleclick.net"].some(e=>i.origin.includes(e))){let t=i.data,e=((o.debug||L)&&D("postMessage received from "+i.origin,t),null),n=null;if("string"==typeof t){if(t.includes("|")){var a=t.split("|");n=a[0];try{e=JSON.parse(a.slice(1).join("|"))}catch{D("Failed to parse pipe-delimited data")}}else try{e=JSON.parse(t)}catch{e=null}e&&(t=e,n)&&"object"==typeof t&&(t._eventType=n)}if(t&&"hsFormCallback"===t.type&&"onFormSubmit"===t.eventName)D("HubSpot form submitted via postMessage",t),f(h("form_submit",{targetUrl:null,elementText:null,elementType:"iframe",elementId:t.data?.formGuid||t.data?.id||"hubspot-form",elementClasses:null,elementAttributes:{iframe_source:"hubspot",iframe_origin:i.origin},isActualTarget:!0,viewport:{width:window.innerWidth,height:window.innerHeight},scroll:{x:window.scrollX,y:window.scrollY},mousePosition:null},"iframe",{formId:t.data?.formGuid||t.data?.id||"hubspot-form",fields:t.data||{},iframeSource:"hubspot",iframeOrigin:i.origin}),!1);else if(t&&t.meetingBookSucceeded&&t.meetingsPayload)D("HubSpot meeting booked via postMessage",t),a=t.meetingsPayload.bookingResponse?.postResponse?.contact||{},f(h("form_submit",{targetUrl:null,elementText:null,elementType:"iframe",elementId:t.meetingsPayload.formGuid||"hubspot-meeting",elementClasses:null,elementAttributes:{iframe_source:"hubspot",iframe_origin:i.origin},isActualTarget:!0,viewport:{width:window.innerWidth,height:window.innerHeight},scroll:{x:window.scrollX,y:window.scrollY},mousePosition:null},"iframe",{formId:t.meetingsPayload.formGuid||"hubspot-meeting",fields:{firstName:a.firstName,lastName:a.lastName,email:a.email,linkType:t.meetingsPayload.linkType,userSlug:t.meetingsPayload.userSlug,meetingTime:t.meetingsPayload.bookingResponse?.event?.dateTime},iframeSource:"hubspot",iframeOrigin:i.origin}),!1);else if(t&&("form_submit"===t.type||"submit"===t.eventType||t.formSubmitted))D("Go High Level form submitted via postMessage",t),f(h("form_submit",{targetUrl:null,elementText:null,elementType:"iframe",elementId:t.formId||"ghl-form",elementClasses:null,elementAttributes:{iframe_source:"gohighlevel",iframe_origin:i.origin},isActualTarget:!0,viewport:{width:window.innerWidth,height:window.innerHeight},scroll:{x:window.scrollX,y:window.scrollY},mousePosition:null},"iframe",{formId:t.formId||"ghl-form",fields:t.data||t.formData||{},iframeSource:"gohighlevel",iframeOrigin:i.origin}),!1);else if(t&&t.event&&0===t.event.indexOf("calendly"))D("Calendly event via postMessage",t),"calendly.event_scheduled"===t.event&&f(h("form_submit",{targetUrl:null,elementText:null,elementType:"iframe",elementId:"calendly",elementClasses:null,elementAttributes:{iframe_source:"calendly",iframe_origin:i.origin},isActualTarget:!0,viewport:{width:window.innerWidth,height:window.innerHeight},scroll:{x:window.scrollX,y:window.scrollY},mousePosition:null},"iframe",{formId:"calendly",fields:{event_uri:t.payload?.event?.uri||null,invitee_uri:t.payload?.invitee?.uri||null},iframeSource:"calendly",iframeOrigin:i.origin}),!1);else if(t&&"form-submit"===t.type&&i.origin.includes("typeform"))D("Typeform submitted via postMessage",t),f(h("form_submit",{targetUrl:null,elementText:null,elementType:"iframe",elementId:t.formId||"typeform",elementClasses:null,elementAttributes:{iframe_source:"typeform",iframe_origin:i.origin},isActualTarget:!0,viewport:{width:window.innerWidth,height:window.innerHeight},scroll:{x:window.scrollX,y:window.scrollY},mousePosition:null},"iframe",{formId:t.formId||"typeform",fields:{response_id:t.responseId||null},iframeSource:"typeform",iframeOrigin:i.origin}),!1);else if(t&&"object"==typeof t)if(t.form||t.formId||t.formGuid||t.submitted||t.submission||t.completed||t.status&&"string"==typeof t.status&&("completed"===t.status.toLowerCase()||"submitted"===t.status.toLowerCase()||"success"===t.status.toLowerCase())||t.type&&"string"==typeof t.type&&(t.type.toLowerCase().includes("form")||t.type.toLowerCase().includes("submit")||t.type.toLowerCase().includes("complete"))||t._eventType&&"string"==typeof t._eventType&&(t._eventType.toLowerCase().includes("submit")||t._eventType.toLowerCase().includes("complete")||t._eventType.toLowerCase().includes("success")||t._eventType.toLowerCase().includes("status"))){let e="unknown";i.origin.includes("autodriven.com")?e="capital-one":i.origin.includes("hubspot")?e="hubspot":i.origin.includes("calendly")?e="calendly":i.origin.includes("typeform")?e="typeform":i.origin.includes("gohighlevel")&&(e="gohighlevel"),D("Generic iframe form/completion event detected",{source:e,data:t}),f(h("form_submit",{targetUrl:null,elementText:null,elementType:"iframe",elementId:t.formId||t.id||t.vin||e+"-form",elementClasses:null,elementAttributes:{iframe_source:e,iframe_origin:i.origin,event_type:t._eventType||t.type||null,status:t.status||null},isActualTarget:!0,viewport:{width:window.innerWidth,height:window.innerHeight},scroll:{x:window.scrollX,y:window.scrollY},mousePosition:null},"iframe",{formId:t.formId||t.id||t.vin||e+"-form",fields:t,iframeSource:e,iframeOrigin:i.origin,eventType:t._eventType||t.type||null}),!1)}}}function S(){let t=window.location.href,e=history.pushState,n=history.replaceState;function i(){var e=window.location.href;e!==t&&(D("URL changed:",e),t=e,(()=>{let t=new URL(window.location.href);return["utm_source","utm_medium","utm_campaign","gclid","fbclid","click_id"].some(e=>
1t.searchParams.has(e))&&(D("New tracking parameters detected, updating attribution"),1)})()&&(s.attribution=a(),M(x.ATTRIBUTION,JSON.stringify(s.attribution),"local")),setTimeout(A,100))}history.pushState=function(){e.apply(this,arguments),i()},history.replaceState=function(){n.apply(this,arguments),i()},window.addEventListener("popstate",i)}return{init:function(e){var t,n,i,a,r;function l(){dataLayer.push(arguments)}s.initialized?D("MegaTag already initialized"):(D("Initializing MegaTag tracking"),e&&(e.siteKey&&(o.siteKey=e.siteKey),void 0!==e.debug&&(o.debug=e.debug),e.gtmId&&(o.gtmId=e.gtmId),e.gaId&&(o.gaId=e.gaId),e.pixelId&&(o.pixelId=e.pixelId),e.ctmAccountId)&&(o.ctmAccountId=e.ctmAccountId),o.gtmId&&(e=o.gtmId)&&!document.getElementById("mega-gtm")&&(D("Installing Google Tag Manager:",e),a=window,t=document,e=e,a[n="dataLayer"]=a[n]||[],a[n].push({"gtm.start":(new Date).getTime(),event:"gtm.js"}),a=t.getElementsByTagName("script")[0],(n=t.createElement("script")).async=!0,n.src="https://www.googletagmanager.com/gtm.js?id="+e,n.id="mega-gtm",a.parentNode.insertBefore(n,a)),o.gaId&&(t=o.gaId)&&!document.getElementById("mega-gtag")&&(D("Installing Google Analytics (gtag.js):",t),window.dataLayer=window.dataLayer||[],(window.gtag=l)("js",new Date),l("config",t),(e=document.createElement("script")).async=!0,e.src="https://www.googletagmanager.com/gtag/js?id="+t,e.id="mega-gtag",document.head.appendChild(e)),o.pixelId&&(n=o.pixelId)&&!document.getElementById("mega-pixel")&&(D("Installing Meta Pixel:",n),a=window,e=document,a.fbq||(i=a.fbq=function(){i.callMethod?i.callMethod.apply(i,arguments):i.queue.push(arguments)},a._fbq||(a._fbq=i),(i.push=i).loaded=!0,i.version="2.0",i.queue=[],(a=e.createElement("script")).async=!0,a.src="https://connect.facebook.net/en_US/fbevents.js",e=e.getElementsByTagName("script")[0],a.id="mega-pixel",e.parentNode.insertBefore(a,e)),fbq("init",n),fbq("track","PageView")),o.ctmAccountId&&(e=o.ctmAccountId,document.getElementById("ctm-script")?D("CTM script already loaded"):(D("Installing CTM tracking script for account:",e),(r=document.createElement("script")).id="ctm-script",r.src="https://"+e+".tctm.co/t.js",r.async=!0,r.onload=function(){D("CTM tracking script loaded successfully")},r.onerror=function(){D("Failed to load CTM tracking script")},document.head.appendChild(r))),u(),d(),g(),document.addEventListener("click",C,!0),document.addEventListener("submit",E,!0),window.addEventListener("message",N,!1),S(),A(),s.initialized=!0,D("MegaTag tracking initialization complete"))},trackEvent:function(e,t){e=h(e,{targetUrl:t?.targetUrl||null,elementText:t?.elementText||null,elementType:t?.elementType||"custom",elementId:t?.elementId||null,elementClasses:t?.elementClasses||null,elementAttributes:t?.elementAttributes||null,isActualTarget:!0,viewport:{width:window.innerWidth,height:window.innerHeight},scroll:{x:window.scrollX,y:window.scrollY},mousePosition:null},"web");return t?.value&&(e.value=t.value),t?.currency&&(e.currency=t.currency),t?.formData&&(e.formData=t.formData),f(e,!1)},getVisitorId:r,getSessionId:l,getAttribution:function(){return Object.assign({},g())},version:"2.0.0"}})(),t=(()=>{let l=[],o=null,s=!1,u=["OPTIMIZE_TITLE","OPTIMIZE_DESCRIPTION","H1_PROMOTION","H1_DEMOTION","ADD_LINK_TARGET","ADD_LINK_TITLE","ADD_ALT_TAG","BROKEN_LINK","FIX_REDIRECT","FIX_MIXED_CONTENT"],c={fetchDurationMs:null,payloadBytes:null,changeCount:0,applyDurationMs:null,applyTotalDurationMs:0,applyCallCount:0,retryCount:0,mutationCallbacks:0,xpathEvaluations:0,incompleteCount:0,completedCount:0,failedCount:0,observerTimedOut:!1,incompleteAtTimeout:0,applyBudgetMs:n,budgetExceeded:!1},A={mutationCallbacks:0,applyChangesInvocations:0,xpathEvaluations:0,applyChangesStartTime:null,totalApplyChangesTime:0,isCurrentlyApplying:!1,mutationsDuringApply:0,largestSnapshotSize:0,changesByType:{},lastApplyDuration:null};function d(){L&&(console.table({"Mutation Callbacks":A.mutationCallbacks,"applyChanges() Calls":A.applyChangesInvocations,"XPath Evaluations":A.xpathEvaluations,"Total applyChanges Time (ms)":A.totalApplyChangesTime.toFixed(2),"Avg applyChanges Time (ms)":(A.totalApplyChangesTime/A.applyChangesInvocations).toFixed(2),"Mutations During Apply (self-trigger)":A.mutationsDuringApply,"Largest XPath Snapshot":A.largestSnapshotSize}),console.log("[Optimizer] Changes by Type:",A.changesByType))}function C(e){return L&&A.xpathEvaluations++,document.evaluate(e,document,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue}function t(e){return e.replace(/["'\\]/g,"\\$&")}function E(e){if(!e)return[];try{return Array.from(document.querySelectorAll(`a[href="${t(e)}"]`))}catch(e){return D("findAnchorsByHref selector failed, skipping",e),[]}}function N(t){if(t){let e=t;for(;e&&e!==document.body;){var n=e.tagName?.toLowerCase();if("nav"===n||"header"===n||"footer"===n)return 1;if("navigation"===e.getAttribute?.("role"))return 1;e=e.parentElement}}}function S(e){if(!e)return[];try{return Array.from(document.querySelectorAll(`img[src="${t(e)}"]`))}catch(e){return D("findImagesBySrc selector failed, skipping",e),[]}}function i(e){var t=e.toLowerCase(),n=document.querySelectorAll('script[type="application/ld+json"]');for(let e=0;e<n.length;e++){var i=n[e]?.textContent||"";if(i){var a=(e=>{try{return JSON.parse(e)}catch(e){return null}})(i);if(a&&function t(e,n){if(!e)return!1;if(Array.isArray(e))return e.some(e=>t(e,n));if("object"!=typeof e)return!1;var i=e["@type"];if("string"==typeof i){if(i.toLowerCase()===n)return!0}else if(Array.isArray(i)&&i.some(e=>"string"==typeof e&&e.toLowerCase()===n))return!0;return Object.values(e).some(e=>t(e,n))}(a,t))return 1;if(!a&&i.toLowerCase().includes('"@type"')&&i.toLowerCase().includes(t))return 1}}}function x(e,t){var n=document.head||C("//head");n&&e.newContent?(i(t)||((t=document.createElement("script")).type="application/ld+json",t.textContent=e.newContent,n.appendChild(t),e.element=t),e.completed=!0):e._attempts>=O&&(e.failed=!0)}function k(e,t){let n=document.createElement(t);
1for(Array.from(e.attributes).forEach(e=>{n.setAttribute(e.name,e.value)});e.firstChild;)n.appendChild(e.firstChild);return e.parentNode.replaceChild(n,e),n}function m(){l.forEach(e=>{var t;e.element&&e.completed||(t=C(e.xPath),e.element=t)})}function g(){L&&(A.applyChangesInvocations++,A.applyChangesStartTime=performance.now(),A.isCurrentlyApplying=!0);var e,t=l.filter(e=>!e.completed&&!e.failed);0===t.length?(L&&(A.isCurrentlyApplying=!1),(e=l.filter(e=>e.failed&&!e._loggedFailed)).length&&e.forEach(e=>{e._loggedFailed=!0,D("Change failed",{type:e.type,xPath:e.xPath,content:e.content,attributes:e.attributes,newContent:e.newContent})})):(L&&(D(`applyChanges #${A.applyChangesInvocations}:Processing ${t.length}incomplete changes`),t.forEach(e=>{A.changesByType[e.type]=(A.changesByType[e.type]||0)+1})),t.forEach(a=>{switch(a._attempts=(a._attempts||0)+1,a.type){case"H1_PROMOTION":var e=a.element;if(!e)return;a.content&&e.innerText===a.content&&(a.element=k(e,"h1"),a.completed=!0);break;case"H1_DEMOTION":{let t=a.element;if(t&&a.content&&t.innerText===a.content)return a.element=k(t,"h2"),void(a.completed=!0);e="//h1",L&&A.xpathEvaluations++,v=document.evaluate(e,document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),L&&v.snapshotLength>A.largestSnapshotSize&&(A.largestSnapshotSize=v.snapshotLength,D(`Large XPath snapshot:${e}returned ${v.snapshotLength}elements`));var n=v;for(let e=n.snapshotLength-1;0<=e;e--)if((t=n.snapshotItem(e)).innerText===a.content)return a.element=k(t,"h2"),void(a.completed=!0);break}case"OPTIMIZE_TITLE":v=document.head||C("//head");if(v){let e=a.element;e?e.innerText&&e.innerText!==a.content||(e.textContent=a.newContent,a.completed=!0):((e=document.createElement("title")).textContent=a.newContent,v.appendChild(e),a.element=e,a.completed=!0),document.title=a.newContent}break;case"OPTIMIZE_DESCRIPTION":var i=document.head||C("//head");if(i){let e=a.element;e?(r=e.getAttribute("content")||"")&&r!==a.content&&r===a.newContent||(e.setAttribute("content",a.newContent),a.completed=!0):((e=document.createElement("meta")).setAttribute("name","description"),e.setAttribute("content",a.newContent),i.appendChild(e),a.completed=!0)}break;case"ADD_LINK_TARGET":{var r=a?.attributes?.href;if(!r){a._attempts>=O&&(a.failed=!0);break}var l=E(r);if(0===l.length){a._attempts>=O&&(a.failed=!0);break}let t=!1,n=!0;for(let e=0;e<l.length;e++){var o,s=l[e];s&&((o=s.getAttribute("target"))!==a.attributes.target?(s.setAttribute("target",a.attributes.target),t=!0):o||(n=!1))}t||n?a.completed=!0:a._attempts>=O&&(a.failed=!0);break}case"ADD_LINK_TITLE":{i=a?.attributes?.href;if(!i){a._attempts>=O&&(a.failed=!0);break}var u=E(i);if(0===u.length){a._attempts>=O&&(a.failed=!0);break}let t=!1,n=!0;for(let e=0;e<u.length;e++){var c,d=u[e];d&&((c=d.getAttribute("title"))?c!==a.attributes.title&&(n=!1):(d.setAttribute("title",a.attributes.title),t=!0))}t||n?a.completed=!0:a._attempts>=O&&(a.failed=!0);break}case"BROKEN_LINK":{let n=a?.attributes?.href;if(!n){a._attempts>=O&&(a.failed=!0);break}var t=E(n);if(0===t.length){a._attempts>=O&&(a.failed=!0);break}let i=!1;!a.newContent?t.forEach(e=>{var t;e&&e.parentNode&&(N(e)?D("Skipping BROKEN_LINK removal in protected zone",n):(t=e.textContent||"",t=document.createTextNode(t),e.parentNode.replaceChild(t,e),i=!0))}):t.forEach(e=>{e&&(N(e)?D("Skipping BROKEN_LINK modification in protected zone",n):(a.attributes?.title&&e.getAttribute("title")!==a.attributes.title&&(e.setAttribute("title",a.attributes.title),i=!0),a.attributes?.target&&e.getAttribute("target")!==a.attributes.target&&(e.setAttribute("target",a.attributes.target),i=!0),a.newContent&&e.getAttribute("href")!==a.newContent&&(/^(https?|mailto|tel):/i.test(a.newContent)||a.newContent.startsWith("/"))&&(e.setAttribute("href",a.newContent),i=!0)))}),i,a.completed=!0;break}case"ADD_ALT_TAG":{a.element;var m=S(a.content);if(0===m.length){a._attempts>=O&&(a.failed=!0);break}let t=!1,n=!0;for(let e=m.length-1;0<=e;e--){var g,p=m[e];p&&((g=p.getAttribute("alt"))?g!==a.attributes.alt&&(n=!1):(p.setAttribute("alt",a.attributes.alt),t=!0))}t||n?a.completed=!0:a._attempts>=O&&(a.failed=!0);break}case"LINK_CANONICAL":r=document.head||C("//head");if(r){let e=a.element;e||(e=document.createElement("link"),r.appendChild(e),a.element=e),e.setAttribute("rel","canonical"),e.setAttribute("href",a.attributes.href),a.completed=!0}break;case"ADD_GOOGLE_ANALYTICS_TAG":i=document.head||C("//head");if(i&&!a.completed){if(window.gtag||i.querySelector('script[src*="googletagmanager.com"]')){a.completed=!0;break}let e=a.attributes?.measurementId;if(!e)return;function f(){dataLayer.push(arguments)}window.dataLayer=window.dataLayer||[],window.gtag=f;t=document.createElement("script");
1t.async=!0,t.src="https://www.googletagmanager.com/gtag/js?id="+e,t.onload=function(){f("js",new Date),f("config",e)},i.appendChild(t),a.completed=!0}break;case"FAQ_SCHEMA":x(a,"faqpage");break;case"LOCAL_BUSINESS_SCHEMA":x(a,"localbusiness");break;case"ORGANIZATION_SCHEMA":x(a,"organization");break;case"WEBSITE_SCHEMA":x(a,"website");break;case"FIX_MIXED_CONTENT":var h,y;a.actionRequired?a.completed=!0:(r=a.element)?(t=(i=a.attributes||{}).src?"src":i.href?"href":i.data?"data":null)?(h=i[t],i=i.originalUrl||a.content,(y=r.getAttribute(t))===h?a.completed=!0:y===i&&(r.setAttribute(t,h),a.completed=!0)):a.failed=!0:a._attempts>=O&&(a.failed=!0);break;case"FIX_REDIRECT":{var b=a?.attributes?.originalUrl||a?.content;if(!b){a._attempts>=O&&(a.failed=!0);break}var w=E(b);if(0===w.length){a._attempts>=O&&(a.failed=!0);break}var I=a?.attributes?.href||a?.newContent;if(!I){a._attempts>=O&&(a.failed=!0);break}let t=!1,n=!0;for(let e=0;e<w.length;e++){var _,T=w[e];T&&((_=T.getAttribute("href"))===b?(T.setAttribute("href",I),t=!0):_!==I&&(n=!1))}t||n?a.completed=!0:a._attempts>=O&&(a.failed=!0);break}}var v;!a.completed&&!a.failed&&a._attempts>=O&&(a.failed=!0)}),L&&(e=performance.now()-A.applyChangesStartTime,A.totalApplyChangesTime+=e,A.isCurrentlyApplying=!1,A.lastApplyDuration=e,0<n&&A.totalApplyChangesTime>n&&(s=!0,c.budgetExceeded=!0),c.applyDurationMs=e,c.applyTotalDurationMs=A.totalApplyChangesTime,c.applyCallCount=A.applyChangesInvocations,c.retryCount=0<A.applyChangesInvocations?A.applyChangesInvocations-1:0,c.mutationCallbacks=A.mutationCallbacks,c.xpathEvaluations=A.xpathEvaluations,D(`applyChanges #${A.applyChangesInvocations}completed in ${e.toFixed(2)}ms`)))}function p(e){return e instanceof HTMLElement&&["title","h1","h2","h3","h4","h5","h6","meta","link","a","img","script"].includes(e.tagName.toLowerCase())}function f(){var e=l.filter(e=>!e.completed&&!e.failed).length,t=l.filter(e=>e.failed).length,n=l.filter(e=>e.completed).length;c.incompleteCount=e,c.failedCount=t,c.completedCount=n,c.applyTotalDurationMs=A.totalApplyChangesTime,c.applyCallCount=A.applyChangesInvocations,c.retryCount=0<A.applyChangesInvocations?A.applyChangesInvocations-1:0}async function a(){try{(e=new URL(window.location.href)).searchParams.delete("mega_debug"),e.searchParams.delete("mega_max_per_type"),e.search="",e.hash="";var e=e.toString(),t="https://optimizer.gomega.ai",n=performance.now(),t=await fetch(t+"?page_url="+encodeURIComponent(e));if(c.fetchDurationMs=performance.now()-n,!t.ok)throw new Error("API returned HTTP "+t.status);var i,e=await t.json(),a=(c.payloadBytes=Number(t.headers.get("content-length"))||JSON.stringify(e).length,c.changeCount=Array.isArray(e)?e.length:0,{}),r=[];for(i of e)a[i.type]||(a[i.type]=0),a[i.type]>=h||(a[i.type]++,r.push(i));l=r,L&&(D(`Loaded ${e.length}changes from API`),D("Changes by type:",a)),await 0}catch(e){return void D("Failed to fetch changes:",e)}if(0===l.length)D("No changes to apply");else{m(),g();n=l.filter(e=>!e.completed&&!e.failed).length;if(f(),s)D("Apply budget exceeded, skipping further retries"),L&&(d(),D("Telemetry:",c)),l.filter(e=>e.failed&&!e._loggedFailed).forEach(e=>{e._loggedFailed=!0,D("Change failed",{type:e.type,xPath:e.xPath,content:e.content,attributes:e.attributes,newContent:e.newContent})});else if(0<n||l.some(e=>u.includes(e.type))){D(0<n?n+" changes incomplete, setting up observer":"All changes complete but has revertible types, setting up observer to watch for framework hydration");let e=new MutationObserver(e=>{L&&(A.mutationCallbacks++,A.isCurrentlyApplying)&&A.mutationsDuringApply++,e.some(e=>"childList"===e.type?!!Array.from(e.addedNodes).some(p)||!!p(e.target)||!!Array.from(e.addedNodes).some(e=>1===e.nodeType&&e.querySelector&&e.querySelector("h1, h2, a, img, meta, title")):"characterData"===e.type?p(e.target.parentElement):"attributes"===e.type&&p(e.target))&&!A.isCurrentlyApplying&&(clearTimeout(o),o=setTimeout(()=>{s||(e=(()=>{let a=0;return l.forEach(t=>{if(t.completed&&!t.failed&&u.includes(t.type)){let e=!1;switch(t.type){case"OPTIMIZE_TITLE":var n=document.querySelector("title");n&&(n=n.innerText||n.textContent||"")!==t.newContent&&""!==n&&(e=!0,D("Title reverted, will re-apply",{current:n,expected:t.newContent}));break;case"OPTIMIZE_DESCRIPTION":var n=document.querySelector('meta[name="description"]');n&&(n=n.getAttribute("content")||"")!==t.newContent&&""!==n&&(e=!0,D("Description reverted, will re-apply",{current:n,expected:t.newContent}));break;case"H1_PROMOTION":case"H1_DEMOTION":t.element&&t.element.parentNode&&(n="H1_PROMOTION"===t.type?"H1":"H2",t.element.tagName!==n)&&(e=!0,D(t.type+" reverted, will re-apply"));break;case"ADD_LINK_TARGET":n=t.attributes?.href;n&&E(n).some(e=>e.getAttribute("target")!==t.attributes.target)&&(e=!0,D("Link target reverted, will re-apply",{href:n}));break;case"ADD_LINK_TITLE":n=t.attributes?.href;n&&E(n).some(e=>!e.getAttribute("title")||e.getAttribute("title")!==t.attributes.title)&&(e=!0,D("Link title reverted, will re-apply",{href:n}));break;case"ADD_ALT_TAG":n=t.content;n&&S(n).some(e=>!e.getAttribute("alt")||e.getAttribute("alt")!==t.attributes.alt)&&(e=!0,D("Image alt reverted, will re-apply",{src:n}));break;
1case"BROKEN_LINK":case"FIX_REDIRECT":n=t.attributes?.originalUrl||t.attributes?.href||t.content;n&&t.newContent&&0<E(n).length&&(e=!0,D(t.type+" reverted, will re-apply",{oldHref:n,newHref:t.newContent}));break;case"FIX_MIXED_CONTENT":var i;t.element&&!t.actionRequired&&(i=(n=t.attributes||{}).src?"src":n.href?"href":n.data?"data":null)&&t.element.getAttribute(i)!==n[i]&&(e=!0,D("Mixed content fix reverted, will re-apply"))}e&&(t.completed=!1,t._attempts=0,a++)}}),0<a&&D(`Detected ${a}reverted changes`),a})(),m(),g(),0<e&&D(`Re-applied ${e}changes that were reverted by framework`));var e=l.filter(e=>!e.completed&&!e.failed).length;f(),0===e&&D("All changes complete, continuing to watch for framework reverts")},100))});e.observe(document.documentElement,{childList:!0,subtree:!0,characterData:!0,attributes:!0,attributeFilter:["content","href","src","alt","target","title"]}),setTimeout(()=>{e.disconnect(),D("Observer timeout - disconnecting after 30s"),c.observerTimedOut=!0,c.incompleteAtTimeout=l.filter(e=>!e.completed&&!e.failed).length,f(),l.filter(e=>e.failed&&!e._loggedFailed).forEach(e=>{e._loggedFailed=!0,D("Change failed",{type:e.type,xPath:e.xPath,content:e.content,attributes:e.attributes,newContent:e.newContent})}),L&&(d(),D("Telemetry:",c))},3e4)}else D("All changes applied on first pass (no revertible types)"),f(),L&&(d(),D("Telemetry:",c))}}return{init:async function(){D("Initializing SEO Optimizer"),await a();let{pushState:t,replaceState:n}=history;history.pushState=function(...e){t.apply(history,e),a()},history.replaceState=function(...e){n.apply(history,e),a()},D("SEO Optimizer initialization complete")},applyChanges:g}})();function D(e,t){L&&console.log("[MegaTag] "+e,t||"")}function k(e){return"undefined"!=typeof crypto&&crypto.randomUUID?e+"_"+crypto.randomUUID():e+"_"+"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})}function R(e){e=("; "+document.cookie).split("; "+e+"=");return 2===e.length?e.pop().split(";").shift():null}function P(e,t){try{return"cookie"===t?R(e):("session"===t?sessionStorage:localStorage).getItem(e)}catch(e){return D("Storage read failed:",e),null}}function M(e,t,n){try{var i;"cookie"===n?((i=new Date).setTime(i.getTime()+31536e6),document.cookie=`${e}=${t};expires=${i.toUTCString()};path=/;SameSite=Lax;Secure`):("session"===n?sessionStorage:localStorage).setItem(e,t)}catch(e){D("Storage write failed:",e)}}window.MegaTag=e,(async()=>{await t.init(),window.MEGA_TAG_CONFIG?e.init(window.MEGA_TAG_CONFIG):e.init()})()}})()
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.