diff --git a/README.md b/README.md index bfa8f47..c340e7a 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,10 @@ All contributions are welcome! Please create [an issue](https://github.com/xwp/s ### Changelog +#### 1.1.5 - March 17, 2022 + +- Adding TTFB. + #### 1.1.4 - March 10, 2022 - Improve performance by loading and executing the script in quiter periods. diff --git a/gulpfile.js b/gulpfile.js index 59254e2..be0d83b 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -13,6 +13,7 @@ function zipBundle() { 'README.md', 'css/**/*.css', 'js/dist/**/*.js', + 'js/dist/**/*.php', 'php/**/*.php', ], { diff --git a/js/dist/module/web-vitals-analytics.8f75cb271429178c9035de39e1f2f8d8.js b/js/dist/module/web-vitals-analytics.8f75cb271429178c9035de39e1f2f8d8.js new file mode 100644 index 0000000..8a46c21 --- /dev/null +++ b/js/dist/module/web-vitals-analytics.8f75cb271429178c9035de39e1f2f8d8.js @@ -0,0 +1 @@ +(()=>{"use strict";const e={CLS:[.1,.25],FCP:[1800,3e3],FID:[100,300],LCP:[2500,4e3],TTFB:[501,1500]},t=window.webVitalsAnalyticsData[0].measurementVersion?window.webVitalsAnalyticsData[0].measurementVersion:"dimension1",n=window.webVitalsAnalyticsData[0].eventMeta?window.webVitalsAnalyticsData[0].eventMeta:"dimension2",i=window.webVitalsAnalyticsData[0].eventDebug?window.webVitalsAnalyticsData[0].eventDebug:"dimension3";let a=!1;function r(e){return window[e]||console.log}function o(e,t){return e>t[1]?"poor":e>t[0]?"ni":"good"}function c(e){try{let t=e.nodeName.toLowerCase();return"body"===t?"html>body":e.id?`${t}#${e.id}`:(e.className&&e.className.length&&(t+=`.${[...e.classList.values()].join(".")}`),`${c(e.parentElement)}>${t}`)}catch(e){return"(error)"}}function u(e,t){void 0===t&&(t=[]);const n=t[0],i=t[t.length-1];switch(e){case"LCP":if(i)return c(i.element);break;case"FID":if(n){const{name:e}=n;return`${e}(${c(n.target)})`}break;case"CLS":if(t.length){const e=t.reduce(((e,t)=>e&&e.value>t.value?e:t));if(e&&e.sources){const t=e.sources.reduce(((e,t)=>e.node&&e.previousRect.width*e.previousRect.height>t.previousRect.width*t.previousRect.height?e:t));if(t)return c(t.node)}}break;default:return"(not set)"}}function s(c){let{name:s,value:d,delta:f,id:v,entries:m}=c;const l=window.webVitalsAnalyticsData[0];l&&l.gtag_id&&(a||(!function(e){"gtag"in window&>ag("config",e,{send_page_view:!1,transport_type:"beacon",measurement_version:"6",custom_map:{[t]:"measurement_version",[n]:"event_meta",[i]:"event_debug"}})}(l.gtag_id),a=!0),r("gtag")("event",s,{event_category:"Web Vitals",event_label:v,value:Math.round("CLS"===s?1e3*f:f),non_interaction:!0,event_meta:o(d,e[s]),event_debug:u(s,m)})),l&&l.ga_id&&r("ga")("send","event",{eventCategory:"Web Vitals",eventAction:s,eventLabel:v,eventValue:Math.round("CLS"===s?1e3*f:f),nonInteraction:!0,transport:"beacon",[n]:o(d,e[s]),[i]:u(s,m),[t]:"6"}),l&&l.ga4_id&&r("gtag")("event",s,{value:f,metric_id:v,metric_value:Math.round("CLS"===s?1e3*f:f),event_meta:o(d,e[s]),event_debug:u(s,m),measurement_version:"6"})}var d,f,v,m,l=function(e,t){return{name:e,value:void 0===t?-1:t,delta:0,entries:[],id:"v2-".concat(Date.now(),"-").concat(Math.floor(8999999999999*Math.random())+1e12)}},p=function(e,t){try{if(PerformanceObserver.supportedEntryTypes.includes(e)){if("first-input"===e&&!("PerformanceEventTiming"in self))return;var n=new PerformanceObserver((function(e){return e.getEntries().map(t)}));return n.observe({type:e,buffered:!0}),n}}catch(e){}},g=function(e,t){var n=function n(i){"pagehide"!==i.type&&"hidden"!==document.visibilityState||(e(i),t&&(removeEventListener("visibilitychange",n,!0),removeEventListener("pagehide",n,!0)))};addEventListener("visibilitychange",n,!0),addEventListener("pagehide",n,!0)},w=function(e){addEventListener("pageshow",(function(t){t.persisted&&e(t)}),!0)},h=function(e,t,n){var i;return function(a){t.value>=0&&(a||n)&&(t.delta=t.value-(i||0),(t.delta||void 0===i)&&(i=t.value,e(t)))}},y=-1,b=function(){return"hidden"===document.visibilityState?0:1/0},L=function(){g((function(e){var t=e.timeStamp;y=t}),!0)},T=function(){return y<0&&(y=b(),L(),w((function(){setTimeout((function(){y=b(),L()}),0)}))),{get firstHiddenTime(){return y}}},E=function(e,t){var n,i=T(),a=l("FCP"),r=function(e){"first-contentful-paint"===e.name&&(c&&c.disconnect(),e.startTime=0&&f1e12?new Date:performance.now())-e.timeStamp;"pointerdown"==e.type?function(e,t){var n=function(){A(e,t),a()},i=function(){a()},a=function(){removeEventListener("pointerup",n,C),removeEventListener("pointercancel",i,C)};addEventListener("pointerup",n,C),addEventListener("pointercancel",i,C)}(t,e):A(t,e)}},k=function(e){["mousedown","keydown","touchstart","pointerdown"].forEach((function(t){return e(t,V,C)}))},P={};function I(){!function(e,t){S||(E((function(e){_=e.value})),S=!0);var n,i=function(t){_>-1&&e(t)},a=l("CLS",0),r=0,o=[],c=function(e){if(!e.hadRecentInput){var t=o[0],i=o[o.length-1];r&&e.startTime-i.startTime<1e3&&e.startTime-t.startTime<5e3?(r+=e.value,o.push(e)):(r=e.value,o=[e]),r>a.value&&(a.value=r,a.entries=o,n())}},u=p("layout-shift",c);u&&(n=h(i,a,t),g((function(){u.takeRecords().map(c),n(!0)})),w((function(){r=0,_=-1,a=l("CLS",0),n=h(i,a,t)})))}(s),E(s),function(e,t){var n,i=T(),a=l("FID"),r=function(e){e.startTimeperformance.now())return;n.entries=[t],e(n)}catch(e){}},"complete"===document.readyState?setTimeout(t,0):addEventListener("load",(function(){return setTimeout(t,0)}))}(s)}"requestIdleCallback"in window&&"object"==typeof window.webVitalsAnalyticsData&&window.requestIdleCallback(I)})(); \ No newline at end of file diff --git a/js/dist/module/web-vitals-analytics.asset.php b/js/dist/module/web-vitals-analytics.asset.php index faf40c5..69a0477 100644 --- a/js/dist/module/web-vitals-analytics.asset.php +++ b/js/dist/module/web-vitals-analytics.asset.php @@ -1 +1 @@ - array(), 'version' => 'cf1c2747697c8b76d7b0f75ae6382e16'); \ No newline at end of file + array(), 'version' => '8f75cb271429178c9035de39e1f2f8d8'); \ No newline at end of file diff --git a/js/dist/module/web-vitals-analytics.cf1c2747697c8b76d7b0f75ae6382e16.js b/js/dist/module/web-vitals-analytics.cf1c2747697c8b76d7b0f75ae6382e16.js deleted file mode 100644 index 04f67a4..0000000 --- a/js/dist/module/web-vitals-analytics.cf1c2747697c8b76d7b0f75ae6382e16.js +++ /dev/null @@ -1 +0,0 @@ -(()=>{"use strict";const e={CLS:[.1,.25],FCP:[1800,3e3],FID:[100,300],LCP:[2500,4e3]},t=window.webVitalsAnalyticsData[0].measurementVersion?window.webVitalsAnalyticsData[0].measurementVersion:"dimension1",n=window.webVitalsAnalyticsData[0].eventMeta?window.webVitalsAnalyticsData[0].eventMeta:"dimension2",i=window.webVitalsAnalyticsData[0].eventDebug?window.webVitalsAnalyticsData[0].eventDebug:"dimension3";let a=!1;function r(e){return window[e]||console.log}function o(e,t){return e>t[1]?"poor":e>t[0]?"ni":"good"}function c(e){try{let t=e.nodeName.toLowerCase();return"body"===t?"html>body":e.id?`${t}#${e.id}`:(e.className&&e.className.length&&(t+=`.${[...e.classList.values()].join(".")}`),`${c(e.parentElement)}>${t}`)}catch(e){return"(error)"}}function u(e,t){void 0===t&&(t=[]);const n=t[0],i=t[t.length-1];switch(e){case"LCP":if(i)return c(i.element);break;case"FID":if(n){const{name:e}=n;return`${e}(${c(n.target)})`}break;case"CLS":if(t.length){const e=t.reduce(((e,t)=>e&&e.value>t.value?e:t));if(e&&e.sources){const t=e.sources.reduce(((e,t)=>e.node&&e.previousRect.width*e.previousRect.height>t.previousRect.width*t.previousRect.height?e:t));if(t)return c(t.node)}}break;default:return"(not set)"}}function s(c){let{name:s,value:d,delta:f,id:l,entries:v}=c;const m=window.webVitalsAnalyticsData[0];m&&m.gtag_id&&(a||(!function(e){"gtag"in window&>ag("config",e,{send_page_view:!1,transport_type:"beacon",measurement_version:"6",custom_map:{[t]:"measurement_version",[n]:"event_meta",[i]:"event_debug"}})}(m.gtag_id),a=!0),r("gtag")("event",s,{event_category:"Web Vitals",event_label:l,value:Math.round("CLS"===s?1e3*f:f),non_interaction:!0,event_meta:o(d,e[s]),event_debug:u(s,v)})),m&&m.ga_id&&r("ga")("send","event",{eventCategory:"Web Vitals",eventAction:s,eventLabel:l,eventValue:Math.round("CLS"===s?1e3*f:f),nonInteraction:!0,transport:"beacon",[n]:o(d,e[s]),[i]:u(s,v),[t]:"6"}),m&&m.ga4_id&&r("gtag")("event",s,{value:f,metric_id:l,metric_value:Math.round("CLS"===s?1e3*f:f),event_meta:o(d,e[s]),event_debug:u(s,v),measurement_version:"6"})}var d,f,l,v,m=function(e,t){return{name:e,value:void 0===t?-1:t,delta:0,entries:[],id:"v2-".concat(Date.now(),"-").concat(Math.floor(8999999999999*Math.random())+1e12)}},p=function(e,t){try{if(PerformanceObserver.supportedEntryTypes.includes(e)){if("first-input"===e&&!("PerformanceEventTiming"in self))return;var n=new PerformanceObserver((function(e){return e.getEntries().map(t)}));return n.observe({type:e,buffered:!0}),n}}catch(e){}},w=function(e,t){var n=function n(i){"pagehide"!==i.type&&"hidden"!==document.visibilityState||(e(i),t&&(removeEventListener("visibilitychange",n,!0),removeEventListener("pagehide",n,!0)))};addEventListener("visibilitychange",n,!0),addEventListener("pagehide",n,!0)},g=function(e){addEventListener("pageshow",(function(t){t.persisted&&e(t)}),!0)},b=function(e,t,n){var i;return function(a){t.value>=0&&(a||n)&&(t.delta=t.value-(i||0),(t.delta||void 0===i)&&(i=t.value,e(t)))}},h=-1,y=function(){return"hidden"===document.visibilityState?0:1/0},L=function(){w((function(e){var t=e.timeStamp;h=t}),!0)},_=function(){return h<0&&(h=y(),L(),g((function(){setTimeout((function(){h=y(),L()}),0)}))),{get firstHiddenTime(){return h}}},E=function(e,t){var n,i=_(),a=m("FCP"),r=function(e){"first-contentful-paint"===e.name&&(c&&c.disconnect(),e.startTime=0&&f1e12?new Date:performance.now())-e.timeStamp;"pointerdown"==e.type?function(e,t){var n=function(){A(e,t),a()},i=function(){a()},a=function(){removeEventListener("pointerup",n,S),removeEventListener("pointercancel",i,S)};addEventListener("pointerup",n,S),addEventListener("pointercancel",i,S)}(t,e):A(t,e)}},F=function(e){["mousedown","keydown","touchstart","pointerdown"].forEach((function(t){return e(t,k,S)}))},P={};function I(){!function(e,t){C||(E((function(e){D=e.value})),C=!0);var n,i=function(t){D>-1&&e(t)},a=m("CLS",0),r=0,o=[],c=function(e){if(!e.hadRecentInput){var t=o[0],i=o[o.length-1];r&&e.startTime-i.startTime<1e3&&e.startTime-t.startTime<5e3?(r+=e.value,o.push(e)):(r=e.value,o=[e]),r>a.value&&(a.value=r,a.entries=o,n())}},u=p("layout-shift",c);u&&(n=b(i,a,t),w((function(){u.takeRecords().map(c),n(!0)})),g((function(){r=0,D=-1,a=m("CLS",0),n=b(i,a,t)})))}(s),E(s),function(e,t){var n,i=_(),a=m("FID"),r=function(e){e.startTime