(()=>{"use strict";class t{getPerformanceMetrics(){const t={};try{window.performance&&(t.timeOrigin=performance.timeOrigin)}catch(t){console.warn("Failed to collect performance metrics:",t)}return t}}var e=function(){var t=self.performance&&performance.getEntriesByType&&performance.getEntriesByType("navigation")[0];if(t&&t.responseStart>0&&t.responseStart=0?s="back-forward-cache":a&&(document.prerendering||r()>0?s="prerender":document.wasDiscarded?s="restore":a.type&&(s=a.type.replace(/_/g,"-"))),{name:t,value:void 0===i?-1:i,rating:"good",delta:0,entries:[],id:"v4-".concat(Date.now(),"-").concat(Math.floor(8999999999999*Math.random())+1e12),navigationType:s}},a=function(t,e,n,r){var i,a;return function(s){e.value>=0&&(s||r)&&((a=e.value-(i||0))||void 0===i)&&(i=e.value,e.delta=a,e.rating=function(t,e){return t>e[1]?"poor":t>e[0]?"needs-improvement":"good"}(e.value,n),t(e))}},s=[],o=new Map,c=function(t){var e=self.requestIdleCallback||self.setTimeout,n=-1;return t=function(t){var e=!1;return function(){e||(t(),e=!0)}}(t),"hidden"===document.visibilityState?t():(n=e(t),function(t){document.addEventListener("visibilitychange",(function(){"hidden"===document.visibilityState&&t()}))}(t)),n},u=[],d=[],f=0,l=new WeakMap,h=new Map,p=-1,m=function(){h.size>10&&h.forEach((function(t,e){o.has(e)||h.delete(e)}));var t=s.map((function(t){return l.get(t.entries[0])})),e=d.length-50;d=d.filter((function(n,r){return r>=e||t.includes(n)}));for(var n=new Set,r=0;rf&&e>a||n.has(t)})),p=-1};[].push((function(t){t.interactionId&&t.target&&!h.has(t.interactionId)&&h.set(t.interactionId,t.target)}),(function(t){var e,n=t.startTime+t.duration;f=Math.max(f,t.processingEnd);for(var r=d.length-1;r>=0;r--){var i=d[r];if(Math.abs(n-i.renderTime)<=8){(e=i).startTime=Math.min(t.startTime,e.startTime),e.processingStart=Math.min(t.processingStart,e.processingStart),e.processingEnd=Math.max(t.processingEnd,e.processingEnd),e.entries.push(t);break}}e||(e={startTime:t.startTime,processingStart:t.processingStart,processingEnd:t.processingEnd,renderTime:n,entries:[t]},d.push(e)),(t.interactionId||"first-input"===t.entryType)&&l.set(t,e),p<0&&(p=c(m))}));var g=function(t,e){for(var n,r=[],i=0;n=u[i];i++)if(!(n.startTime+n.duratione)break;r.push(n)}return r},v=[800,1800],T=function t(e){document.prerendering?function(t){document.prerendering?addEventListener("prerenderingchange",(function(){return t()}),!0):t()}((function(){return t(e)})):"complete"!==document.readyState?addEventListener("load",(function(){return t(e)}),!0):setTimeout(e,0)},S=function(t,s){s=s||{};var o=i("TTFB"),c=a(t,o,v,s.reportAllChanges);T((function(){var u=e();u&&(o.value=Math.max(u.responseStart-r(),0),o.entries=[u],c(!0),function(t){addEventListener("pageshow",(function(e){e.persisted&&(n=e.timeStamp,t(e))}),!0)}((function(){o=i("TTFB",0),(c=a(t,o,v,s.reportAllChanges))(!0)})))}))};new Date;class w{metrics={};constructor(e){var n;this.analyticsService=e,this.performanceService=new t,n=this.handleMetric.bind(this),S((function(t){var e=function(t){var e={waitingDuration:0,cacheDuration:0,dnsDuration:0,connectionDuration:0,requestDuration:0};if(t.entries.length){var n=t.entries[0],r=n.activationStart||0,i=Math.max((n.workerStart||n.fetchStart)-r,0),a=Math.max(n.domainLookupStart-r,0),s=Math.max(n.connectStart-r,0),o=Math.max(n.connectEnd-r,0);e={waitingDuration:i,cacheDuration:a-i,dnsDuration:s-a,connectionDuration:o-s,requestDuration:t.value-o,navigationEntry:n}}return Object.assign(t,{attribution:e})}(t);n(e)}),void 0)}parseTTFB(t){if(!t)return;const{transferSize:e}=t.entries[0],n=0===e;return{value:Math.floor(t.value),rating:t.rating,attribution:t.attribution,navigationType:t.navigationType,isCache:n}}handleMetric(t){if(t)if("TTFB"===t.name){const e=this.parseTTFB(t);if(!e)return;this.metrics.ttfb=e,this.analyticsService.handledMetric(t.name)}else console.warn(`Unknown metric: ${t.name}`)}getMetrics(){return this.metrics.performance=this.performanceService.getPerformanceMetrics(),this.metrics}}const D=(new class{scriptSelector="script.elementor-browser-metrics[data-request-info]";requestInfoAttribute="data-request-info";getRequestData(){try{const t=document.querySelector(this.scriptSelector);if(!t)return null;const e=t.getAttribute(this.requestInfoAttribute);return e?JSON.parse(e):null}catch(t){return console.warn("Failed to parse request data:",t),null}}}).getRequestData();D?new class{sentTTFB=!1;constructor(t){this.requestData=t,this.metricsCollector=new w(this)}handledMetric(t){"TTFB"===t&&this.sendTTFB()}validateTTFB(t){return!!(t?.metrics?.ttfb&&isFinite(t?.metrics?.ttfb?.value??NaN)&&isFinite(t?.metrics?.performance?.timeOrigin??NaN)&&t?.userAgent&&"unknown"!==t?.userAgent)}sendTTFB(){if(this.sentTTFB)return;const t=this.getAnalyticsData();this.validateTTFB(t)&&(this.sentTTFB=!0,this.sendMetrics(t))}updateTraceparent(t){const e=t.split("-"),n=e[0],r=e[1],i=e[2],a=e[3],s=Date.now().toString(16).padStart(16,"0");return`${n}-${r.substring(0,16)+s}-${i}-${a}`}getAnalyticsData(){const t=this.metricsCollector.getMetrics(),e=t.ttfb?.isCache?this.updateTraceparent(this.requestData.traceparent):this.requestData.traceparent;return{metrics:t,timestamp:Date.now(),url:window.location.href,traceparent:e,version:this.requestData.version,status:this.requestData.status,ecSource:this.requestData.ecSource,instanceId:this.requestData.instanceId,userAgent:this.requestData.userAgent}}sendMetrics(t){if(t)try{const e=JSON.stringify(t);fetch(this.requestData.endpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:e,keepalive:!0}).catch((()=>{console.warn("Failed to send metrics via fetch")}))}catch(t){console.warn("Failed to send metrics:",t)}}}(D):console.warn("Request data not found")})();