posthog-js
Version:
Posthog-js allows you to automatically capture usage and send events to PostHog.
2 lines • 27 kB
JavaScript
!function(){"function"!=typeof[].at&&Object.defineProperty(Array.prototype,"at",{value(t){const n=this.length;let i=Math.trunc(t)||0;return 0>i&&(i+=n),0>i||i>=n?void 0:this[i]},writable:!0,enumerable:!1,configurable:!0}),"function"!=typeof[].findLast&&Object.defineProperty(Array.prototype,"findLast",{value(t,n){for(let i=this.length-1;i>=0;i--){const e=this[i];if(t.call(n,e,i,this))return e}},writable:!0,enumerable:!1,configurable:!0});const t="u">typeof window?window:void 0,n="u">typeof globalThis?globalThis:t;null!=n&&n.XMLHttpRequest&&new n.XMLHttpRequest;const i="undefined"!=typeof globalThis?globalThis:t;i&&"undefined"==typeof self&&(i.self=i),i&&"undefined"==typeof File&&(i.File=function(){});const e=null!=t?t:{};function o(t){return o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},o(t)}function r(t,n,i){return(n=function(t){var n=function(t){if("object"!=o(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var i=n.call(t,"string");if("object"!=o(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==o(n)?n:n+""}(n))in t?Object.defineProperty(t,n,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[n]=i,t}function a(t,n){var i=Object.keys(t);if(Object.getOwnPropertySymbols){var e=Object.getOwnPropertySymbols(t);n&&(e=e.filter(function(n){return Object.getOwnPropertyDescriptor(t,n).enumerable})),i.push.apply(i,e)}return i}function s(t){for(var n=1;arguments.length>n;n++){var i=null!=arguments[n]?arguments[n]:{};n%2?a(Object(i),!0).forEach(function(n){r(t,n,i[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):a(Object(i)).forEach(function(n){Object.defineProperty(t,n,Object.getOwnPropertyDescriptor(i,n))})}return t}var c=class{constructor(){this.t=void 0,this.o=0,this.i=[]}l(t){var n;if(t.hadRecentInput)return;const i=this.i[0],e=this.i.at(-1);this.o&&i&&e&&1e3>t.startTime-e.startTime&&5e3>t.startTime-i.startTime?(this.o+=t.value,this.i.push(t)):(this.o=t.value,this.i=[t]),null===(n=this.t)||void 0===n||n.call(this,t)}};const l=()=>{const t=performance.getEntriesByType("navigation")[0];if(t&&t.responseStart>0&&t.responseStart<performance.now())return t},u=t=>{if("loading"===document.readyState)return"loading";const n=l();if(n){if(n.domInteractive>t)return"loading";if(0===n.domContentLoadedEventStart||n.domContentLoadedEventStart>t)return"dom-interactive";if(0===n.domComplete||n.domComplete>t)return"dom-content-loaded"}return"complete"},f=t=>{const n=t.nodeName;return 1===t.nodeType?n.toLowerCase():n.toUpperCase().replace(/^#/,"")},v=t=>{let n="";try{for(;9!==(null==t?void 0:t.nodeType);){var i;const e=t,o=e.id?"#"+e.id:[f(e),...Array.from(null!==(i=e.classList)&&void 0!==i?i:[]).sort()].join(".");if(n.length+o.length>99)return n||o;if(n=n?o+">"+n:o,e.id)break;t=e.parentNode}}catch(t){}return n},d=new WeakMap;function h(t,n){let i=d.get(n);return i||(i=new WeakMap,d.set(n,i)),i.get(t)||i.set(t,new n),i.get(t)}let g=-1;const m=()=>g,b=t=>{addEventListener("pageshow",n=>{n.persisted&&(g=n.timeStamp,t(n))},!0)},p=(t,n,i,e)=>{let o,r;return a=>{var s;n.value>=0&&(a||e)&&(r=n.value-(null!==(s=o)&&void 0!==s?s:0),(r||void 0===o)&&(o=n.value,n.delta=r,n.rating=((t,n)=>t>n[1]?"poor":t>n[0]?"needs-improvement":"good")(n.value,i),t(n)))}},y=t=>{requestAnimationFrame(()=>requestAnimationFrame(()=>t()))},T=()=>{var t,n;return null!==(t=null===(n=l())||void 0===n?void 0:n.activationStart)&&void 0!==t?t:0};let M=-1;const w=new Set,L=()=>"hidden"!==document.visibilityState||document.prerendering?1/0:0,S=t=>{if("hidden"===document.visibilityState){if("visibilitychange"===t.type)for(const t of w)t();isFinite(M)||(M="visibilitychange"===t.type?t.timeStamp:0,removeEventListener("prerenderingchange",S,!0))}},k=(t=!1)=>{if(t&&(M=1/0),0>M){var n;const t=T(),i=document.prerendering||null===(n=globalThis.performance.getEntriesByType("visibility-state").find(n=>"hidden"===n.name&&n.startTime>=t))||void 0===n?void 0:n.startTime;M=null!=i?i:L(),addEventListener("visibilitychange",S,!0),addEventListener("prerenderingchange",S,!0),b(()=>{setTimeout(()=>{M=L()})})}return{get firstHiddenTime(){return M},onHidden(t){w.add(t)}}},P=(t,n=-1,i,e=0,o,r,a)=>{const s=l(),c=(null==s?void 0:s.navigationId)||0;let u="navigate";return i?u=i:0>m()?s&&(document.prerendering||T()>0?u="prerender":document.wasDiscarded?u="restore":s.type&&(u=s.type.replace(/_/g,"-"))):u="back-forward-cache",{name:t,value:n,rating:"good",delta:0,entries:[],id:`v6-${Date.now()}-${Math.floor(8999999999999*Math.random())+1e12}`,navigationType:u,navigationId:e||c,navigationInteractionId:o,navigationURL:r||(null==s?void 0:s.name),navigationStartTime:a||0}},E=(t,n,i={})=>{try{const e=t.filter(t=>PerformanceObserver.supportedEntryTypes.includes(t));if(e.length>0){const t=new PerformanceObserver(t=>{queueMicrotask(()=>{const i=t.getEntries();e.length>1&&i.sort((t,n)=>t.startTime+t.duration-(n.startTime+n.duration)),n(i)})});for(const n of e)t.observe(s({type:n,buffered:!0},i));return t}}catch(t){}},C=t=>{var n,i;return(null===(n=globalThis.PerformanceObserver)||void 0===n||null===(n=n.supportedEntryTypes)||void 0===n?void 0:n.includes("soft-navigation"))&&"function"==typeof(null===(i=globalThis.PerformanceSoftNavigation)||void 0===i||null===(i=i.prototype)||void 0===i?void 0:i.getLargestInteractionContentfulPaint)&&t&&t.reportSoftNavs},O=(t,n)=>{if(t.set(n.navigationId,n),t.size>2){const n=t.keys().next().value;void 0!==n&&t.delete(n)}},j=t=>{let n=!1;return()=>{n||(t(),n=!0)}};var F=class{constructor(){this.u=void 0}};const D=t=>{document.prerendering?addEventListener("prerenderingchange",t,!0):t()},I=[1800,3e3],A=(t,n={})=>{const i=C(n);D(()=>{const e=h(n,F),o=k();let r,a=P("FCP");const s=E(["paint"],t=>{for(const n of t)"first-contentful-paint"===n.name&&(s.disconnect(),o.firstHiddenTime>n.startTime&&(a.value=Math.max(n.startTime-T(),0),a.entries.push(n),a.navigationId=n.navigationId||a.navigationId,r(!0)))});s&&(r=p(t,a,I,n.reportAllChanges),b(i=>{a=P("FCP",-1,"back-forward-cache",a.navigationId,a.navigationInteractionId,a.navigationURL,m()),r=p(t,a,I,n.reportAllChanges),y(()=>{a.value=performance.now()-i.timeStamp,r(!0)})})),i&&E(["soft-navigation"],i=>{i.forEach(i=>{e.u&&i.navigationId&&O(e.u,i);const o=Math.max((i.presentationTime||i.paintTime||0)-i.startTime,0);a=P("FCP",o,"soft-navigation",i.navigationId,i.interactionId,i.name,i.startTime),r=p(t,a,I,n.reportAllChanges),r(!0)})},n)})},q=[.1,.25],B=t=>t.find(t=>{var n;return 1===(null===(n=t.node)||void 0===n?void 0:n.nodeType)})||t[0];let W=0,N=1/0,H=0;const R=t=>{for(const n of t)n.interactionId&&(N=Math.min(N,n.interactionId),H=Math.max(H,n.interactionId),W=H?(H-N)/7+1:0)};let U;const _=()=>{var t;return U?W:null!==(t=performance.interactionCount)&&void 0!==t?t:0};var x=class{constructor(){this.h=0,this.v=[],this.p=new Map,this.m=void 0,this.M=void 0}T(){return _()-this.h}D(){this.h=_(),this.v.length=0,this.p.clear()}S(t){const n=this.T(),i=Math.min(this.v.length-1,Math.floor(n/50));return!n||-1!==i||"soft-navigation"!==t&&"back-forward-cache"!==t?this.v[i]:{k:8,id:-1,entries:[]}}l(t){var n;if(null===(n=this.m)||void 0===n||n.call(this,t),!t.interactionId)return;const i=this.v.at(-1);let e=this.p.get(t.interactionId);if(e||10>this.v.length||t.duration>i.k){var o;if(e?t.duration>e.k?(e.entries=[t],e.k=t.duration):t.duration===e.k&&t.startTime===e.entries[0].startTime&&e.entries.push(t):(e={id:t.interactionId,entries:[t],k:t.duration},this.p.set(e.id,e),this.v.push(e)),this.v.sort((t,n)=>n.k-t.k),this.v.length>10){const t=this.v.splice(10);for(const n of t)this.p.delete(n.id)}null===(o=this.M)||void 0===o||o.call(this,e)}}};const V=t=>{const n="requestIdleCallback"in globalThis?1e3:0,i=globalThis.requestIdleCallback||setTimeout,e=globalThis.cancelIdleCallback||clearTimeout;if("hidden"===document.visibilityState)t();else{const o=j(t);let r=-1;const a=()=>{e(r),o()};addEventListener("visibilitychange",a,{once:!0,capture:!0}),r=i(()=>{removeEventListener("visibilitychange",a,{capture:!0}),o()},{timeout:n})}},z=[200,500];var G=class{constructor(){this.m=void 0,this.u=void 0}l(t){var n;null===(n=this.m)||void 0===n||n.call(this,t)}};const $=[2500,4e3];let J=50;const K=[];E(["resource"],t=>{for(const n of t)K.push(n),K.length>J&&K.shift()});let Q=-1;const X=()=>Q,Y=t=>{addEventListener("pageshow",n=>{n.persisted&&(Q=n.timeStamp,t(n))},!0)},Z=(t,n,i,e)=>{let o,r;return a=>{var s;n.value>=0&&(a||e)&&(r=n.value-(null!==(s=o)&&void 0!==s?s:0),(r||void 0===o)&&(o=n.value,n.delta=r,n.rating=((t,n)=>t>n[1]?"poor":t>n[0]?"needs-improvement":"good")(n.value,i),t(n)))}},tt=t=>{requestAnimationFrame(()=>requestAnimationFrame(()=>t()))},nt=()=>{const t=performance.getEntriesByType("navigation")[0];if(t&&t.responseStart>0&&t.responseStart<performance.now())return t},it=()=>{var t,n;return null!==(t=null===(n=nt())||void 0===n?void 0:n.activationStart)&&void 0!==t?t:0};let et=-1;const ot=new Set,rt=()=>"hidden"!==document.visibilityState||document.prerendering?1/0:0,at=t=>{if("hidden"===document.visibilityState){if("visibilitychange"===t.type)for(const t of ot)t();isFinite(et)||(et="visibilitychange"===t.type?t.timeStamp:0,removeEventListener("prerenderingchange",at,!0))}},st=(t=!1)=>{if(t&&(et=1/0),0>et){var n;const t=it(),i=document.prerendering||null===(n=globalThis.performance.getEntriesByType("visibility-state").find(n=>"hidden"===n.name&&n.startTime>=t))||void 0===n?void 0:n.startTime;et=null!=i?i:rt(),addEventListener("visibilitychange",at,!0),addEventListener("prerenderingchange",at,!0),Y(()=>{setTimeout(()=>{et=rt()})})}return{get firstHiddenTime(){return et},onHidden(t){ot.add(t)}}},ct=(t,n=-1,i,e=0,o,r,a)=>{const s=nt(),c=(null==s?void 0:s.navigationId)||0;let l="navigate";return i?l=i:0>X()?s&&(document.prerendering||it()>0?l="prerender":document.wasDiscarded?l="restore":s.type&&(l=s.type.replace(/_/g,"-"))):l="back-forward-cache",{name:t,value:n,rating:"good",delta:0,entries:[],id:`v6-${Date.now()}-${Math.floor(8999999999999*Math.random())+1e12}`,navigationType:l,navigationId:e||c,navigationInteractionId:o,navigationURL:r||(null==s?void 0:s.name),navigationStartTime:a||0}},lt=new WeakMap;function ut(t,n){let i=lt.get(n);return i||(i=new WeakMap,lt.set(n,i)),i.get(t)||i.set(t,new n),i.get(t)}var ft=class{constructor(){this.t=void 0,this.i=0,this.o=[]}h(t){var n;if(t.hadRecentInput)return;const i=this.o[0],e=this.o.at(-1);this.i&&i&&e&&1e3>t.startTime-e.startTime&&5e3>t.startTime-i.startTime?(this.i+=t.value,this.o.push(t)):(this.i=t.value,this.o=[t]),null===(n=this.t)||void 0===n||n.call(this,t)}};const vt=(t,n,i={})=>{try{const e=t.filter(t=>PerformanceObserver.supportedEntryTypes.includes(t));if(e.length>0){const t=new PerformanceObserver(t=>{queueMicrotask(()=>{const i=t.getEntries();e.length>1&&i.sort((t,n)=>t.startTime+t.duration-(n.startTime+n.duration)),n(i)})});for(const n of e)t.observe(s({type:n,buffered:!0},i));return t}}catch(t){}},dt=t=>{var n,i;return(null===(n=globalThis.PerformanceObserver)||void 0===n||null===(n=n.supportedEntryTypes)||void 0===n?void 0:n.includes("soft-navigation"))&&"function"==typeof(null===(i=globalThis.PerformanceSoftNavigation)||void 0===i||null===(i=i.prototype)||void 0===i?void 0:i.getLargestInteractionContentfulPaint)&&t&&t.reportSoftNavs},ht=(t,n)=>{if(t.set(n.navigationId,n),t.size>2){const n=t.keys().next().value;void 0!==n&&t.delete(n)}},gt=t=>{let n=!1;return()=>{n||(t(),n=!0)}};var mt=class{constructor(){this.l=void 0}};const bt=t=>{document.prerendering?addEventListener("prerenderingchange",t,!0):t()},pt=[1800,3e3],yt=(t,n={})=>{const i=dt(n);bt(()=>{const e=ut(n,mt),o=st();let r,a=ct("FCP");const s=vt(["paint"],t=>{for(const n of t)"first-contentful-paint"===n.name&&(s.disconnect(),o.firstHiddenTime>n.startTime&&(a.value=Math.max(n.startTime-it(),0),a.entries.push(n),a.navigationId=n.navigationId||a.navigationId,r(!0)))});s&&(r=Z(t,a,pt,n.reportAllChanges),Y(i=>{a=ct("FCP",-1,"back-forward-cache",a.navigationId,a.navigationInteractionId,a.navigationURL,X()),r=Z(t,a,pt,n.reportAllChanges),tt(()=>{a.value=performance.now()-i.timeStamp,r(!0)})})),i&&vt(["soft-navigation"],i=>{i.forEach(i=>{e.l&&i.navigationId&&ht(e.l,i);const o=Math.max((i.presentationTime||i.paintTime||0)-i.startTime,0);a=ct("FCP",o,"soft-navigation",i.navigationId,i.interactionId,i.name,i.startTime),r=Z(t,a,pt,n.reportAllChanges),r(!0)})},n)})},Tt=[.1,.25];let Mt=0,wt=1/0,Lt=0;const St=t=>{for(const n of t)n.interactionId&&(wt=Math.min(wt,n.interactionId),Lt=Math.max(Lt,n.interactionId),Mt=Lt?(Lt-wt)/7+1:0)};let kt;const Pt=()=>{var t;return kt?Mt:null!==(t=performance.interactionCount)&&void 0!==t?t:0};var Et=class{constructor(){this.u=0,this.v=[],this.m=new Map,this.p=void 0,this.T=void 0}_(){return Pt()-this.u}M(){this.u=Pt(),this.v.length=0,this.m.clear()}L(t){const n=this._(),i=Math.min(this.v.length-1,Math.floor(n/50));return!n||-1!==i||"soft-navigation"!==t&&"back-forward-cache"!==t?this.v[i]:{P:8,id:-1,entries:[]}}h(t){var n;if(null===(n=this.p)||void 0===n||n.call(this,t),!t.interactionId)return;const i=this.v.at(-1);let e=this.m.get(t.interactionId);if(e||10>this.v.length||t.duration>i.P){var o;if(e?t.duration>e.P?(e.entries=[t],e.P=t.duration):t.duration===e.P&&t.startTime===e.entries[0].startTime&&e.entries.push(t):(e={id:t.interactionId,entries:[t],P:t.duration},this.m.set(e.id,e),this.v.push(e)),this.v.sort((t,n)=>n.P-t.P),this.v.length>10){const t=this.v.splice(10);for(const n of t)this.m.delete(n.id)}null===(o=this.T)||void 0===o||o.call(this,e)}}};const Ct=t=>{const n="requestIdleCallback"in globalThis?1e3:0,i=globalThis.requestIdleCallback||setTimeout,e=globalThis.cancelIdleCallback||clearTimeout;if("hidden"===document.visibilityState)t();else{const o=gt(t);let r=-1;const a=()=>{e(r),o()};addEventListener("visibilitychange",a,{once:!0,capture:!0}),r=i(()=>{removeEventListener("visibilitychange",a,{capture:!0}),o()},{timeout:n})}},Ot=[200,500];var jt=class{constructor(){this.p=void 0,this.l=void 0}h(t){var n;null===(n=this.p)||void 0===n||n.call(this,t)}};const Ft=[2500,4e3],Dt={onLCP(t,n={}){null!=(n=Object.assign({},n)).resourceBufferSize&&(J=n.resourceBufferSize);const i=h(n,G),e=new WeakMap;C(n)&&(i.u=new Map),i.m=t=>{const i=t.element;if(i){var o,r;const a=null!==(o=null===(r=n.generateTarget)||void 0===r?void 0:r.call(n,i))&&void 0!==o?o:v(i);e.set(t,a)}else t.id&&e.set(t,`#${t.id}`)},((t,n={})=>{let i=!1;const e=C(n);D(()=>{let o,r=k(),a=P("LCP");const s=h(n,G),c=(e,s,c,l,u)=>{a=P("LCP",-1,e,s,c,l,u),o=p(t,a,$,n.reportAllChanges),i=!1,"soft-navigation"===e&&(r=k(!0))},l=t=>{var n;s.u&&t.navigationId&&O(s.u,t),i||o(!0),c("soft-navigation",t.navigationId,t.interactionId,t.name,t.startTime);const e=null===(n=t.getLargestInteractionContentfulPaint)||void 0===n?void 0:n.call(t);e&&u([e])},u=t=>{n.reportAllChanges||e||(t=t.slice(-1));for(const n of t){if(!n)continue;if("soft-navigation"===n.entryType){l(n);continue}let t=0,e=[],c=n.startTime;if("largest-contentful-paint"===n.entryType)t=Math.max(n.startTime-T(),0),s.l(n),e=[n];else if("interaction-contentful-paint"===n.entryType){var i;const o=n;if(!a.navigationId)continue;if("interactionId"in o&&o.interactionId!=a.navigationInteractionId)continue;c=(null===(i=o.largestContentfulPaint)||void 0===i?void 0:i.renderTime)||0,t=Math.max(c-n.startTime,0),o.largestContentfulPaint&&(s.l(o.largestContentfulPaint),e=[o.largestContentfulPaint])}r.firstHiddenTime>c&&(a.value=t,a.entries=e,o())}},f=["largest-contentful-paint"];e&&f.push("interaction-contentful-paint","soft-navigation");const v=E(f,u);if(v){o=p(t,a,$,n.reportAllChanges);const r=["keydown","click","visibilitychange"],s=t=>{if(t.isTrusted&&!i){const t=a.id;V(()=>{if(!i){if(!e){v.disconnect();for(const t of r)removeEventListener(t,s,{capture:!0})}t===a.id&&(i=!0,o(!0))}})}};for(const t of r)addEventListener(t,s,{capture:!0});b(e=>{c("back-forward-cache",a.navigationId,a.navigationInteractionId,a.navigationURL,m()),o=p(t,a,$,n.reportAllChanges),y(()=>{a.value=performance.now()-e.timeStamp,i=!0,o(!0)})})}})})(n=>{t((t=>{let n={timeToFirstByte:0,resourceLoadDelay:0,resourceLoadDuration:0,elementRenderDelay:t.value};if(t.entries.length){var o,r,a;const c=t.entries.at(-1),u=c.url&&(K.findLast(t=>t.name===c.url)||performance.getEntriesByType("resource").findLast(t=>t.name===c.url));let f;n.target=e.get(c),n.lcpEntry=c,c.url&&(n.url=c.url),u&&(n.lcpResourceEntry=u);let v=0,d=0;if("soft-navigation"!==t.navigationType?(f=l(),v=null!==(o=null==f?void 0:f.activationStart)&&void 0!==o?o:0,d=null!==(r=null==f?void 0:f.responseStart)&&void 0!==r?r:0):(v=t.navigationStartTime||0,f=null===(a=i.u)||void 0===a?void 0:a.get(t.navigationId)),f){const i=Math.max(0,d-v),e=Math.max(i,u?(u.requestStart||u.startTime)-v:0),o=Math.min(t.value,Math.max(e,u?u.responseEnd-v:0));n=s(s({},n),{},{timeToFirstByte:i,resourceLoadDelay:e-i,resourceLoadDuration:o-e,elementRenderDelay:t.value-o,navigationEntry:f})}}return Object.assign(t,{attribution:n})})(n))},n)},onCLS(t,n={}){const i=h(n=Object.assign({},n),c),e=new WeakMap;i.t=t=>{var i;if(null==t||null===(i=t.sources)||void 0===i?void 0:i.length){const i=B(t.sources),a=null==i?void 0:i.node;if(a){var o,r;const t=null!==(o=null===(r=n.generateTarget)||void 0===r?void 0:r.call(n,a))&&void 0!==o?o:v(a);e.set(i,t)}}},((t,n={})=>{const i=k();A(j(()=>{let e,o=P("CLS",0);const r=h(n,c),a=(i,a,s,c,l)=>{o=P("CLS",0,i,a,s,c,l),r.o=0,e=p(t,o,q,n.reportAllChanges)},s=(t=!1)=>{r.o>o.value&&(o.value=r.o,o.entries=r.i),e(t)},l=t=>{s(!0),a("soft-navigation",t.navigationId,t.interactionId,t.name,t.startTime)},u=t=>{for(const n of t)"soft-navigation"!==n.entryType?r.l(n):l(n);s()},f=["layout-shift"];C(n)&&f.push("soft-navigation");const v=E(f,u);v&&(e=p(t,o,q,n.reportAllChanges),i.onHidden(()=>{u(v.takeRecords()),e(!0)}),b(()=>{a("back-forward-cache",o.navigationId,o.navigationInteractionId,o.navigationURL,m()),y(e)}),setTimeout(e))}))})(n=>{t((t=>{let n={};if(t.entries.length){var i;const o=t.entries.reduce((t,n)=>t.value>n.value?t:n);if(null==o||null===(i=o.sources)||void 0===i?void 0:i.length){const t=B(o.sources);t&&(n={largestShiftTarget:e.get(t),largestShiftTime:o.startTime,largestShiftValue:o.value,largestShiftSource:t,largestShiftEntry:o,loadState:u(o.startTime)})}}return Object.assign(t,{attribution:n})})(n))},n)},onFCP(t,n={}){const i=h(n=Object.assign({},n),F);C(n)&&(i.u=new Map),A(n=>{t((t=>{let n={timeToFirstByte:0,firstByteToFCP:t.value,loadState:u(m())};if("soft-navigation"!==t.navigationType){if(t.entries.length){const i=l(),e=t.entries.at(-1);if(i){const o=Math.max(0,i.responseStart-(i.activationStart||0));n={timeToFirstByte:o,firstByteToFCP:t.value-o,loadState:u(t.entries[0].startTime),navigationEntry:i,fcpEntry:e}}}}else{var e;const o=null===(e=i.u)||void 0===e?void 0:e.get(t.navigationId);o&&(n={timeToFirstByte:0,firstByteToFCP:t.value,loadState:"complete",navigationEntry:o})}return Object.assign(t,{attribution:n})})(n))},n)},onINP(t,n={}){const i=h(n=Object.assign({},n),x);let e=[],o=[],r=0;const a=new WeakMap,c=new WeakMap;let l=!1;const f=()=>{l||(V(d),l=!0)},d=()=>{const t=new Set(i.v.map(t=>a.get(t.entries[0]))),n=o.length-10;o=o.filter((i,e)=>e>=n||t.has(i));const s=new Set;for(const t of o){const n=g(t.startTime,t.processingEnd);for(const t of n)s.add(t)}e=e.filter(t=>t.startTime>r||s.has(t)),l=!1};i.m=t=>{const i=t.startTime+t.duration;let e;r=Math.max(r,t.processingEnd);for(let r=o.length-1;r>=0;r--){const a=o[r];if(8>=Math.abs(i-a.renderTime)){e=a,e.startTime=Math.min(t.startTime,e.startTime),e.processingStart=Math.min(t.processingStart,e.processingStart),e.processingEnd=Math.max(t.processingEnd,e.processingEnd),n.includeProcessedEventEntries&&e.entries.push(t);break}}e||(e={startTime:t.startTime,processingStart:t.processingStart,processingEnd:t.processingEnd,renderTime:i,entries:n.includeProcessedEventEntries?[t]:[]},o.push(e)),t.interactionId&&a.set(t,e),f()},i.M=t=>{if(!c.get(t)){var i;const a=null===(i=t.entries.find(t=>t.target))||void 0===i?void 0:i.target;if(a){var e,o;const i=null!==(e=null===(o=n.generateTarget)||void 0===o?void 0:o.call(n,a))&&void 0!==e?e:v(a);c.set(t,i)}else{var r;const n=null===(r=t.entries.find(t=>t.targetSelector))||void 0===r?void 0:r.targetSelector;n&&c.set(t,n)}}};const g=(t,n)=>{const i=[];for(const o of e)if(o.startTime+o.duration>=t){if(o.startTime>n)break;i.push(o)}return i};E(["long-animation-frame"],t=>{e=e.concat(t),f()},n),((t,n={})=>{if(!globalThis.PerformanceEventTiming||!("interactionId"in PerformanceEventTiming.prototype))return;const i=k();D(()=>{var e;"interactionCount"in performance||U||(U=E(["event"],R,{durationThreshold:0}));let o,r=P("INP");const a=h(n,x),c=(i,e,s,c,l)=>{a.D(),r=P("INP",-1,i,e,s,c,l),o=p(t,r,z,n.reportAllChanges)},l=()=>{const t=a.S(r.navigationType);t&&t.k!==r.value&&(r.value=t.k,r.entries=t.entries,o())},u=t=>{l(),o(!0),c("soft-navigation",t.navigationId,t.interactionId,t.name,t.startTime)},f=(t,n=!1)=>{V(()=>{for(const n of t)"soft-navigation"!==n.entryType?a.l(n):u(n);l(),n&&o(!0)})},v=["event","first-input"];C(n)&&v.push("soft-navigation");const d=E(v,f,s(s({},n),{},{durationThreshold:null!==(e=n.durationThreshold)&&void 0!==e?e:40}));o=p(t,r,z,n.reportAllChanges),d&&(i.onHidden(()=>{f(d.takeRecords(),!0)}),b(()=>{c("back-forward-cache",r.navigationId,r.navigationInteractionId,r.navigationURL,m())}))})})(n=>{t((t=>{if(0===t.entries.length){const n={processedEventEntries:[],longAnimationFrameEntries:[],inputDelay:0,processingDuration:0,presentationDelay:t.value,loadState:u(t.navigationStartTime||0)};return Object.assign(t,{attribution:n})}const n=t.entries[0],e=a.get(n),o=Math.max(e.processingStart,n.startTime),r=Math.max(n.startTime+n.duration,o),s=Math.min(e.processingEnd,r),l=e.entries.sort((t,n)=>t.processingStart-n.processingStart),f=g(n.startTime,s),v=i.p.get(n.interactionId),d={interactionTarget:c.get(v),interactionType:n.name.startsWith("key")?"keyboard":"pointer",interactionTime:n.startTime,nextPaintTime:r,processedEventEntries:l,longAnimationFrameEntries:f,inputDelay:o-n.startTime,processingDuration:s-o,presentationDelay:r-s,loadState:u(n.startTime),longestScript:void 0,totalScriptDuration:void 0,totalStyleAndLayoutDuration:void 0,totalPaintDuration:void 0,totalUnattributedDuration:void 0};return(t=>{var n;const i=t.interactionTime,e=t.nextPaintTime;if(!(null===(n=t.longAnimationFrameEntries)||void 0===n?void 0:n.length)||!i||!e)return;const o=t.inputDelay,r=t.processingDuration;let a,s,c=0,l=0,u=0,f=0;for(const n of t.longAnimationFrameEntries){l=l+n.startTime+n.duration-n.styleAndLayoutStart;for(const t of n.scripts){const n=t.startTime+t.duration;if(i>n)continue;const e=n-Math.max(i,t.startTime),u=t.duration?e/t.duration*t.forcedStyleAndLayoutDuration:0;c+=e-u,l+=u,e>f&&(s=i+o>t.startTime?"input-delay":i+o+r>t.startTime?"processing-duration":"presentation-delay",a=t,f=e)}}const v=t.longAnimationFrameEntries.at(-1),d=v?v.startTime+v.duration:0;d>=i+o+r&&(u=e-d),a&&s&&(t.longestScript={entry:a,subpart:s,intersectingDuration:f}),t.totalScriptDuration=c,t.totalStyleAndLayoutDuration=l,t.totalPaintDuration=u,t.totalUnattributedDuration=e-i-c-l-u})(d),Object.assign(t,{attribution:d})})(n))},n)},withoutAttribution:{onLCP(t,n={}){let i=!1;const e=dt(n);bt(()=>{let o,r=st(),a=ct("LCP");const s=ut(n,jt),c=(e,s,c,l,u)=>{a=ct("LCP",-1,e,s,c,l,u),o=Z(t,a,Ft,n.reportAllChanges),i=!1,"soft-navigation"===e&&(r=st(!0))},l=t=>{var n;s.l&&t.navigationId&&ht(s.l,t),i||o(!0),c("soft-navigation",t.navigationId,t.interactionId,t.name,t.startTime);const e=null===(n=t.getLargestInteractionContentfulPaint)||void 0===n?void 0:n.call(t);e&&u([e])},u=t=>{n.reportAllChanges||e||(t=t.slice(-1));for(const n of t){if(!n)continue;if("soft-navigation"===n.entryType){l(n);continue}let t=0,e=[],c=n.startTime;if("largest-contentful-paint"===n.entryType)t=Math.max(n.startTime-it(),0),s.h(n),e=[n];else if("interaction-contentful-paint"===n.entryType){var i;const o=n;if(!a.navigationId)continue;if("interactionId"in o&&o.interactionId!=a.navigationInteractionId)continue;c=(null===(i=o.largestContentfulPaint)||void 0===i?void 0:i.renderTime)||0,t=Math.max(c-n.startTime,0),o.largestContentfulPaint&&(s.h(o.largestContentfulPaint),e=[o.largestContentfulPaint])}r.firstHiddenTime>c&&(a.value=t,a.entries=e,o())}},f=["largest-contentful-paint"];e&&f.push("interaction-contentful-paint","soft-navigation");const v=vt(f,u);if(v){o=Z(t,a,Ft,n.reportAllChanges);const r=["keydown","click","visibilitychange"],s=t=>{if(t.isTrusted&&!i){const t=a.id;Ct(()=>{if(!i){if(!e){v.disconnect();for(const t of r)removeEventListener(t,s,{capture:!0})}t===a.id&&(i=!0,o(!0))}})}};for(const t of r)addEventListener(t,s,{capture:!0});Y(e=>{c("back-forward-cache",a.navigationId,a.navigationInteractionId,a.navigationURL,X()),o=Z(t,a,Ft,n.reportAllChanges),tt(()=>{a.value=performance.now()-e.timeStamp,i=!0,o(!0)})})}})},onCLS(t,n={}){const i=st();yt(gt(()=>{let e,o=ct("CLS",0);const r=ut(n,ft),a=(i,a,s,c,l)=>{o=ct("CLS",0,i,a,s,c,l),r.i=0,e=Z(t,o,Tt,n.reportAllChanges)},s=(t=!1)=>{r.i>o.value&&(o.value=r.i,o.entries=r.o),e(t)},c=t=>{s(!0),a("soft-navigation",t.navigationId,t.interactionId,t.name,t.startTime)},l=t=>{for(const n of t)"soft-navigation"!==n.entryType?r.h(n):c(n);s()},u=["layout-shift"];dt(n)&&u.push("soft-navigation");const f=vt(u,l);f&&(e=Z(t,o,Tt,n.reportAllChanges),i.onHidden(()=>{l(f.takeRecords()),e(!0)}),Y(()=>{a("back-forward-cache",o.navigationId,o.navigationInteractionId,o.navigationURL,X()),tt(e)}),setTimeout(e))}))},onFCP:yt,onINP(t,n={}){if(!globalThis.PerformanceEventTiming||!("interactionId"in PerformanceEventTiming.prototype))return;const i=st();bt(()=>{var e;"interactionCount"in performance||kt||(kt=vt(["event"],St,{durationThreshold:0}));let o,r=ct("INP");const a=ut(n,Et),c=(i,e,s,c,l)=>{a.M(),r=ct("INP",-1,i,e,s,c,l),o=Z(t,r,Ot,n.reportAllChanges)},l=()=>{const t=a.L(r.navigationType);t&&t.P!==r.value&&(r.value=t.P,r.entries=t.entries,o())},u=t=>{l(),o(!0),c("soft-navigation",t.navigationId,t.interactionId,t.name,t.startTime)},f=(t,n=!1)=>{Ct(()=>{for(const n of t)"soft-navigation"!==n.entryType?a.h(n):u(n);l(),n&&o(!0)})},v=["event","first-input"];dt(n)&&v.push("soft-navigation");const d=vt(v,f,s(s({},n),{},{durationThreshold:null!==(e=n.durationThreshold)&&void 0!==e?e:40}));o=Z(t,r,Ot,n.reportAllChanges),d&&(i.onHidden(()=>{f(d.takeRecords(),!0)}),Y(()=>{c("back-forward-cache",r.navigationId,r.navigationInteractionId,r.navigationURL,X())}))})}}};e.__PosthogExtensions__=e.__PosthogExtensions__||{},e.__PosthogExtensions__.postHogWebVitalsCallbacksByFlavor=e.__PosthogExtensions__.postHogWebVitalsCallbacksByFlavor||{},e.__PosthogExtensions__.postHogWebVitalsCallbacksByFlavor["web-vitals-with-attribution-soft-navs"]=Dt,e.__PosthogExtensions__.postHogWebVitalsCallbacks=Dt,e.postHogWebVitalsCallbacks=Dt}();
//# sourceMappingURL=web-vitals-with-attribution-soft-navs.js.map