"use strict";(()=>{var se=Object.defineProperty;var ae=(r,e,t)=>e in r?se(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var d=(r,e,t)=>ae(r,typeof e!="symbol"?e+"":e,t);function oe(r){let e="__DOUBLE_ASTERISK_TOKEN__",t="__SINGLE_ASTERISK_TOKEN__",n=r.replace(/\*\*/g,e).replace(/\*/g,t).replace(/[.+?^${}()|[\]\\]/g,"\\$&");n=n.replace(new RegExp(`/${e}/`,"g"),"/(?:.+/)?"),n=n.replace(new RegExp(e,"g"),".*"),n=n.replace(/\//g,"\\/");let c=n.replace(new RegExp(t,"g"),"[^/]+");return new RegExp("^"+c+"$")}function T(r,e){for(let t of e)try{if(oe(t).test(r))return t}catch(i){console.error(`Invalid pattern: ${t}`,i)}return null}function F(r,e){let t=null;return(...i)=>{t&&clearTimeout(t),t=setTimeout(()=>{t=null,r(...i)},e)}}function W(r){try{let e=window.location.hostname,t=new URL(r).hostname;return t!==e&&t!==""}catch(e){return console.error("Error checking outbound link:",e),!1}}function E(r,e){if(!r)return e;try{let t=JSON.parse(r);return Array.isArray(e)&&!Array.isArray(t)?e:t}catch(t){return console.error("Error parsing JSON:",t),e}}function H(r){if(!r.getAttribute("src"))return console.error("Script src attribute is missing"),null;let t=(r.getAttribute("data-host")||"https://flyrankpixel.com").replace(/\/$/,"");if(!t)return console.error("Please provide a valid analytics host"),null;let i=r.getAttribute("data-site-id")||r.getAttribute("site-id");if(!i||isNaN(Number(i)))return console.error("Please provide a valid site ID using the data-site-id attribute"),null;let n=r.getAttribute("data-debounce")?Math.max(0,parseInt(r.getAttribute("data-debounce"))):500,c=E(r.getAttribute("data-skip-patterns"),[]),a=E(r.getAttribute("data-mask-patterns"),[]),s=r.getAttribute("data-api-key")||void 0,l=r.getAttribute("data-replay-batch-size")?Math.max(1,parseInt(r.getAttribute("data-replay-batch-size"))):25,o=r.getAttribute("data-replay-batch-interval")?Math.max(1e3,parseInt(r.getAttribute("data-replay-batch-interval"))):2e3;return{analyticsHost:t,siteId:i,debounceDuration:n,autoTrackPageview:r.getAttribute("data-auto-track-pageview")!=="false",autoTrackSpa:r.getAttribute("data-track-spa")!=="false",trackQuerystring:r.getAttribute("data-track-query")!=="false",trackOutbound:r.getAttribute("data-track-outbound")!=="false",enableWebVitals:r.getAttribute("data-web-vitals")==="true",trackErrors:r.getAttribute("data-track-errors")==="true",enableSessionReplay:r.getAttribute("data-session-replay")==="true",sessionReplayBatchSize:l,sessionReplayBatchInterval:o,skipPatterns:c,maskPatterns:a,apiKey:s}}var y=class{constructor(e,t,i){d(this,"config");d(this,"isRecording",!1);d(this,"stopRecordingFn");d(this,"userId");d(this,"eventBuffer",[]);d(this,"batchTimer");d(this,"sendBatch");this.config=e,this.userId=t,this.sendBatch=i}async initialize(){this.config.enableSessionReplay&&(window.rrweb||await this.loadRrweb(),window.rrweb&&this.startRecording())}async loadRrweb(){return new Promise((e,t)=>{let i=document.createElement("script");i.src=`${this.config.analyticsHost}/api/replay.js`,i.async=!1,i.onload=()=>{e()},i.onerror=()=>t(new Error("Failed to load rrweb")),document.head.appendChild(i)})}startRecording(){if(!(this.isRecording||!window.rrweb||!this.config.enableSessionReplay))try{this.stopRecordingFn=window.rrweb.record({emit:e=>{this.addEvent({type:e.type,data:e.data,timestamp:e.timestamp||Date.now()})},recordCanvas:!0,collectFonts:!0,checkoutEveryNms:3e4,checkoutEveryNth:200,maskAllInputs:!0,maskInputOptions:{password:!0,email:!0},slimDOMOptions:{script:!1,comment:!0,headFavicon:!0,headWhitespace:!0,headMetaDescKeywords:!0,headMetaSocial:!0,headMetaRobots:!0,headMetaHttpEquiv:!0,headMetaAuthorship:!0,headMetaVerification:!0},sampling:{mousemove:!1,mouseInteraction:!0,scroll:150,input:"last"}}),this.isRecording=!0,this.setupBatchTimer()}catch{}}stopRecording(){this.isRecording&&(this.stopRecordingFn&&this.stopRecordingFn(),this.isRecording=!1,this.clearBatchTimer(),this.eventBuffer.length>0&&this.flushEvents())}isActive(){return this.isRecording}addEvent(e){this.eventBuffer.push(e),this.eventBuffer.length>=this.config.sessionReplayBatchSize&&this.flushEvents()}setupBatchTimer(){this.clearBatchTimer(),this.batchTimer=window.setInterval(()=>{this.eventBuffer.length>0&&this.flushEvents()},this.config.sessionReplayBatchInterval)}clearBatchTimer(){this.batchTimer&&(clearInterval(this.batchTimer),this.batchTimer=void 0)}async flushEvents(){if(this.eventBuffer.length===0)return;let e=[...this.eventBuffer];this.eventBuffer=[];let t={userId:this.userId,events:e,metadata:{pageUrl:window.location.href,viewportWidth:screen.width,viewportHeight:screen.height,language:navigator.language}};try{await this.sendBatch(t)}catch{this.eventBuffer.unshift(...e)}}updateUserId(e){this.userId=e}onPageChange(){this.isRecording&&this.flushEvents()}cleanup(){this.stopRecording()}};var b=class{constructor(e){d(this,"config");d(this,"customUserId",null);d(this,"sessionReplayRecorder");d(this,"uaDataLogged",!1);this.config=e,this.loadUserId(),e.enableSessionReplay&&this.initializeSessionReplay()}loadUserId(){try{let e=localStorage.getItem("flyrank-user-id");e&&(this.customUserId=e)}catch{}}async initializeSessionReplay(){try{this.sessionReplayRecorder=new y(this.config,this.customUserId||"",e=>this.sendSessionReplayBatch(e)),await this.sessionReplayRecorder.initialize()}catch(e){console.error("Failed to initialize session replay:",e)}}async sendSessionReplayBatch(e){try{await fetch(`${this.config.analyticsHost}/api/session-replay/record/${this.config.siteId}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e),mode:"cors",keepalive:!1})}catch(t){throw console.error("Failed to send session replay batch:",t),t}}createBasePayload(){let e=new URL(window.location.href),t=e.pathname;if(e.hash&&e.hash.startsWith("#/")&&(t=e.hash.substring(1)),T(t,this.config.skipPatterns))return null;let i=T(t,this.config.maskPatterns);i&&(t=i);let n=this.getDeviceInfo(),c={site_id:this.config.siteId,hostname:e.hostname,pathname:t,querystring:this.config.trackQuerystring?e.search:"",screenWidth:window.innerWidth,screenHeight:window.innerHeight,language:navigator.language,page_title:document.title,referrer:document.referrer,...n};return this.customUserId&&(c.user_id=this.customUserId),c}async sendTrackingData(e){try{let t=`${this.config.analyticsHost}/api/track`,i=JSON.stringify(e);await fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:i,mode:"cors",keepalive:!0})}catch(t){console.error("Failed to send tracking data:",t)}}track(e,t="",i={}){if(e==="custom_event"&&(!t||typeof t!="string")){console.error("Event name is required and must be a string for custom events");return}let n=this.createBasePayload();if(!n)return;let c={...n,type:e,event_name:t,properties:e==="custom_event"||e==="outbound"?JSON.stringify(i):void 0};this.sendTrackingData(c)}trackPageview(){this.track("pageview")}trackEvent(e,t={}){this.track("custom_event",e,t)}trackOutbound(e,t="",i="_self"){this.track("outbound","",{url:e,text:t,target:i})}trackWebVitals(e){let t=this.createBasePayload();if(!t)return;let i={...t,type:"performance",event_name:"web-vitals",...e};this.sendTrackingData(i)}trackError(e,t={}){let i=window.location.origin,n=t.filename||"",c=e.stack||"";if(n)try{if(new URL(n).origin!==i)return}catch{}else if(c&&!c.includes(i))return;let a={message:e.message?.substring(0,500)||"Unknown error",stack:c.substring(0,2e3)||""};if(n&&(a.fileName=n),t.lineno){let s=typeof t.lineno=="string"?parseInt(t.lineno,10):t.lineno;s&&s!==0&&(a.lineNumber=s)}if(t.colno){let s=typeof t.colno=="string"?parseInt(t.colno,10):t.colno;s&&s!==0&&(a.columnNumber=s)}for(let s in t)!["lineno","colno"].includes(s)&&t[s]!==void 0&&(a[s]=t[s]);this.track("error",e.name||"Error",a)}identify(e){if(typeof e!="string"||e.trim()===""){console.error("User ID must be a non-empty string");return}this.customUserId=e.trim();try{localStorage.setItem("flyrank-user-id",this.customUserId)}catch{console.warn("Could not persist user ID to localStorage")}this.sessionReplayRecorder&&this.sessionReplayRecorder.updateUserId(this.customUserId)}clearUserId(){this.customUserId=null;try{localStorage.removeItem("flyrank-user-id")}catch{}}getUserId(){return this.customUserId}startSessionReplay(){this.sessionReplayRecorder?this.sessionReplayRecorder.startRecording():console.warn("Session replay not initialized")}stopSessionReplay(){this.sessionReplayRecorder&&this.sessionReplayRecorder.stopRecording()}isSessionReplayActive(){return this.sessionReplayRecorder?.isActive()??!1}isErrorTrackingActive(){return this.config.trackErrors??!1}onPageChange(){this.sessionReplayRecorder&&this.sessionReplayRecorder.onPageChange()}cleanup(){this.sessionReplayRecorder&&this.sessionReplayRecorder.cleanup()}getDeviceInfo(){let e=navigator.userAgent,t={},i=navigator.userAgentData,n=this.detectSpecialBrowserFromUAData(i);if(n){t.browser=n;let o=e.match(/Chrome\/(\d+)/);o&&(t.browser_version=o[1])}else if(e.includes("Chrome")&&!e.includes("Edg")){t.browser="Chrome";let o=e.match(/Chrome\/(\d+)/);o&&(t.browser_version=o[1])}else if(e.includes("Firefox")){t.browser="Firefox";let o=e.match(/Firefox\/(\d+)/);o&&(t.browser_version=o[1])}else if(e.includes("Safari")&&!e.includes("Chrome")){t.browser="Safari";let o=e.match(/Version\/(\d+)/);o&&(t.browser_version=o[1])}else if(e.includes("Edg")){t.browser="Edge";let o=e.match(/Edg\/(\d+)/);o&&(t.browser_version=o[1])}else if(e.includes("Opera")||e.includes("OPR")){t.browser="Opera";let o=e.match(/(?:Opera|OPR)\/(\d+)/);o&&(t.browser_version=o[1])}if(e.includes("Windows NT")){t.operating_system="Windows";let o=e.match(/Windows NT ([\d.]+)/);if(o){let u=o[1];u==="10.0"?t.operating_system_version="10":u==="6.3"?t.operating_system_version="8.1":u==="6.2"?t.operating_system_version="8":u==="6.1"?t.operating_system_version="7":t.operating_system_version=u}}else if(e.includes("Mac OS X")){t.operating_system="macOS";let o=e.match(/Mac OS X ([\d_]+)/);o&&(t.operating_system_version=o[1].replace(/_/g,"."))}else if(e.includes("Linux"))t.operating_system="Linux";else if(e.includes("Android")){t.operating_system="Android";let o=e.match(/Android ([\d.]+)/);o&&(t.operating_system_version=o[1])}else if(e.includes("iPhone")||e.includes("iPad")){t.operating_system="iOS";let o=e.match(/OS ([\d_]+)/);o&&(t.operating_system_version=o[1].replace(/_/g,"."))}let c=window.innerWidth,a=window.innerHeight,s=Math.max(c,a),l=Math.min(c,a);return s>1024?t.device_type="Desktop":s>768&&l>1024?t.device_type="Tablet":t.device_type="Mobile",e.includes("Mobile")||e.includes("Android")||e.includes("iPhone")?t.device_type="Mobile":(e.includes("iPad")||e.includes("Tablet"))&&(t.device_type="Tablet"),t}detectSpecialBrowserFromUAData(e){try{if(!e||!Array.isArray(e.brands))return;let t=e.brands.map(l=>typeof l?.brand=="string"?l.brand:"").filter(Boolean),i=l=>t.includes(l),n=i("Chromium"),c=i("Google Chrome"),a=i("Not_A Brand"),s=i("Not?A_Brand");return n&&c&&a&&t.length>=3?"ChatGPT Atlas":n&&c&&s&&t.length>=3?"Perplexity Comet":n&&a&&!c&&t.length===2?"Arc":void 0}catch{return}}};var Q=-1,g=r=>{addEventListener("pageshow",(e=>{e.persisted&&(Q=e.timeStamp,r(e))}),!0)},h=(r,e,t,i)=>{let n,c;return a=>{e.value>=0&&(a||i)&&(c=e.value-(n??0),(c||n===void 0)&&(n=e.value,e.delta=c,e.rating=((s,l)=>s>l[1]?"poor":s>l[0]?"needs-improvement":"good")(e.value,t),r(e)))}},M=r=>{requestAnimationFrame((()=>requestAnimationFrame((()=>r()))))},D=()=>{let r=performance.getEntriesByType("navigation")[0];if(r&&r.responseStart>0&&r.responseStartD()?.activationStart??0,p=(r,e=-1)=>{let t=D(),i="navigate";return Q>=0?i="back-forward-cache":t&&(document.prerendering||m()>0?i="prerender":document.wasDiscarded?i="restore":t.type&&(i=t.type.replace(/_/g,"-"))),{name:r,value:e,rating:"good",delta:0,entries:[],id:`v5-${Date.now()}-${Math.floor(8999999999999*Math.random())+1e12}`,navigationType:i}},P=new WeakMap;function x(r,e){return P.get(r)||P.set(r,new e),P.get(r)}var A=class{constructor(){d(this,"t");d(this,"i",0);d(this,"o",[])}h(e){if(e.hadRecentInput)return;let t=this.o[0],i=this.o.at(-1);this.i&&t&&i&&e.startTime-i.startTime<1e3&&e.startTime-t.startTime<5e3?(this.i+=e.value,this.o.push(e)):(this.i=e.value,this.o=[e]),this.t?.(e)}},v=(r,e,t={})=>{try{if(PerformanceObserver.supportedEntryTypes.includes(r)){let i=new PerformanceObserver((n=>{Promise.resolve().then((()=>{e(n.getEntries())}))}));return i.observe({type:r,buffered:!0,...t}),i}}catch{}},U=r=>{let e=!1;return()=>{e||(r(),e=!0)}},f=-1,X=new Set,V=()=>document.visibilityState!=="hidden"||document.prerendering?1/0:0,C=r=>{if(document.visibilityState==="hidden"){if(r.type==="visibilitychange")for(let e of X)e();isFinite(f)||(f=r.type==="visibilitychange"?r.timeStamp:0,removeEventListener("prerenderingchange",C,!0))}},R=()=>{if(f<0){let r=m();f=(document.prerendering?void 0:globalThis.performance.getEntriesByType("visibility-state").filter((t=>t.name==="hidden"&&t.startTime>r))[0]?.startTime)??V(),addEventListener("visibilitychange",C,!0),addEventListener("prerenderingchange",C,!0),g((()=>{setTimeout((()=>{f=V()}))}))}return{get firstHiddenTime(){return f},onHidden(r){X.add(r)}}},k=r=>{document.prerendering?addEventListener("prerenderingchange",(()=>r()),!0):r()},z=[1800,3e3],N=(r,e={})=>{k((()=>{let t=R(),i,n=p("FCP"),c=v("paint",(a=>{for(let s of a)s.name==="first-contentful-paint"&&(c.disconnect(),s.startTime{n=p("FCP"),i=h(r,n,z,e.reportAllChanges),M((()=>{n.value=performance.now()-a.timeStamp,i(!0)}))})))}))},$=[.1,.25],Y=(r,e={})=>{let t=R();N(U((()=>{let i,n=p("CLS",0),c=x(e,A),a=l=>{for(let o of l)c.h(o);c.i>n.value&&(n.value=c.i,n.entries=c.o,i())},s=v("layout-shift",a);s&&(i=h(r,n,$,e.reportAllChanges),t.onHidden((()=>{a(s.takeRecords()),i(!0)})),g((()=>{c.i=0,n=p("CLS",0),i=h(r,n,$,e.reportAllChanges),M((()=>i()))})),setTimeout(i))})))},Z=0,_=1/0,w=0,ce=r=>{for(let e of r)e.interactionId&&(_=Math.min(_,e.interactionId),w=Math.max(w,e.interactionId),Z=w?(w-_)/7+1:0)},I,K=()=>I?Z:performance.interactionCount??0,le=()=>{"interactionCount"in performance||I||(I=v("event",ce,{type:"event",buffered:!0,durationThreshold:0}))},q=0,B=class{constructor(){d(this,"u",[]);d(this,"l",new Map);d(this,"m");d(this,"p")}v(){q=K(),this.u.length=0,this.l.clear()}L(){let e=Math.min(this.u.length-1,Math.floor((K()-q)/50));return this.u[e]}h(e){if(this.m?.(e),!e.interactionId&&e.entryType!=="first-input")return;let t=this.u.at(-1),i=this.l.get(e.interactionId);if(i||this.u.length<10||e.duration>t.P){if(i?e.duration>i.P?(i.entries=[e],i.P=e.duration):e.duration===i.P&&e.startTime===i.entries[0].startTime&&i.entries.push(e):(i={id:e.interactionId,entries:[e],P:e.duration},this.l.set(i.id,i),this.u.push(i)),this.u.sort(((n,c)=>c.P-n.P)),this.u.length>10){let n=this.u.splice(10);for(let c of n)this.l.delete(c.id)}this.p?.(i)}}},ee=r=>{let e=globalThis.requestIdleCallback||setTimeout;document.visibilityState==="hidden"?r():(r=U(r),addEventListener("visibilitychange",r,{once:!0,capture:!0}),e((()=>{r(),removeEventListener("visibilitychange",r,{capture:!0})})))},J=[200,500],te=(r,e={})=>{if(!globalThis.PerformanceEventTiming||!("interactionId"in PerformanceEventTiming.prototype))return;let t=R();k((()=>{le();let i,n=p("INP"),c=x(e,B),a=l=>{ee((()=>{for(let u of l)c.h(u);let o=c.L();o&&o.P!==n.value&&(n.value=o.P,n.entries=o.entries,i())}))},s=v("event",a,{durationThreshold:e.durationThreshold??40});i=h(r,n,J,e.reportAllChanges),s&&(s.observe({type:"first-input",buffered:!0}),t.onHidden((()=>{a(s.takeRecords()),i(!0)})),g((()=>{c.v(),n=p("INP"),i=h(r,n,J,e.reportAllChanges)})))}))},L=class{constructor(){d(this,"m")}h(e){this.m?.(e)}},j=[2500,4e3],re=(r,e={})=>{k((()=>{let t=R(),i,n=p("LCP"),c=x(e,L),a=l=>{e.reportAllChanges||(l=l.slice(-1));for(let o of l)c.h(o),o.startTime{a(s.takeRecords()),s.disconnect(),i(!0)})),o=u=>{u.isTrusted&&(ee(l),removeEventListener(u.type,o,{capture:!0}))};for(let u of["keydown","click","visibilitychange"])addEventListener(u,o,{capture:!0});g((u=>{n=p("LCP"),i=h(r,n,j,e.reportAllChanges),M((()=>{n.value=performance.now()-u.timeStamp,i(!0)}))}))}}))},G=[800,1800],O=r=>{document.prerendering?k((()=>O(r))):document.readyState!=="complete"?addEventListener("load",(()=>O(r)),!0):setTimeout(r)},ie=(r,e={})=>{let t=p("TTFB"),i=h(r,t,G,e.reportAllChanges);O((()=>{let n=D();n&&(t.value=Math.max(n.responseStart-m(),0),t.entries=[n],i(!0),g((()=>{t=p("TTFB",0),i=h(r,t,G,e.reportAllChanges),i(!0)})))}))};var S=class{constructor(e){d(this,"data",{lcp:null,cls:null,inp:null,fcp:null,ttfb:null});d(this,"sent",!1);d(this,"timeout",null);d(this,"onReadyCallback",null);this.onReadyCallback=e}initialize(){try{re(this.collectMetric.bind(this)),Y(this.collectMetric.bind(this)),te(this.collectMetric.bind(this)),N(this.collectMetric.bind(this)),ie(this.collectMetric.bind(this)),this.timeout=setTimeout(()=>{this.sent||this.sendData()},2e4),window.addEventListener("beforeunload",()=>{this.sent||this.sendData()})}catch(e){console.warn("Error initializing web vitals tracking:",e)}}collectMetric(e){if(this.sent)return;let t=e.name.toLowerCase();this.data[t]=e.value,Object.values(this.data).every(n=>n!==null)&&this.sendData()}sendData(){this.sent||(this.sent=!0,this.timeout&&(clearTimeout(this.timeout),this.timeout=null),this.onReadyCallback&&this.onReadyCallback(this.data))}getData(){return{...this.data}}};(function(){let r=document.currentScript;if(!r){console.error("Could not find current script tag");return}if(window.__FLYRANK_OPTOUT__||localStorage.getItem("disable-flyrank")!==null){window.flyrank={pageview:()=>{},event:()=>{},trackOutbound:()=>{},identify:()=>{},clearUserId:()=>{},getUserId:()=>null,trackError:()=>{},startSessionReplay:()=>{},stopSessionReplay:()=>{},isSessionReplayActive:()=>!1,isErrorTrackingActive:()=>!1};return}let e=H(r);if(!e)return;let t=new b(e);e.enableWebVitals&&new S(s=>{t.trackWebVitals(s)}).initialize(),e.trackErrors&&(window.addEventListener("error",a=>{t.trackError(a.error||new Error(a.message),{filename:a.filename,lineno:a.lineno,colno:a.colno})}),window.addEventListener("unhandledrejection",a=>{let s=a.reason instanceof Error?a.reason:new Error(String(a.reason));t.trackError(s,{type:"unhandledrejection"})}));let i=()=>t.trackPageview(),n=e.debounceDuration>0?F(i,e.debounceDuration):i;function c(){if(document.addEventListener("click",function(a){let s=a.target;for(;s&&s!==document.documentElement;){if(s.hasAttribute("data-flyrank-event")){let l=s.getAttribute("data-flyrank-event");if(l){let o={};for(let u of s.attributes)if(u.name.startsWith("data-flyrank-prop-")){let ne=u.name.replace("data-flyrank-prop-","");o[ne]=u.value}t.trackEvent(l,o)}break}s=s.parentElement}if(e.trackOutbound){let l=a.target.closest("a");l?.href&&W(l.href)&&t.trackOutbound(l.href,l.innerText||l.textContent||"",l.target||"_self")}}),e.autoTrackSpa){let a=history.pushState,s=history.replaceState;history.pushState=function(...l){a.apply(this,l),n()},history.replaceState=function(...l){s.apply(this,l),n()},window.addEventListener("popstate",n),window.addEventListener("hashchange",n)}}window.flyrank={pageview:()=>t.trackPageview(),event:(a,s={})=>t.trackEvent(a,s),trackOutbound:(a,s="",l="_self")=>t.trackOutbound(a,s,l),identify:a=>t.identify(a),clearUserId:()=>t.clearUserId(),getUserId:()=>t.getUserId(),trackError:(a,s={})=>{let l=a instanceof Error?a:new Error(String(a));t.trackError(l,s)},isErrorTrackingActive:()=>t.isErrorTrackingActive(),startSessionReplay:()=>t.startSessionReplay(),stopSessionReplay:()=>t.stopSessionReplay(),isSessionReplayActive:()=>t.isSessionReplayActive()},c(),e.autoTrackPageview&&t.trackPageview()})();})();