Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@financial-times/n-tracking

Package Overview
Dependencies
Maintainers
8
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@financial-times/n-tracking - npm Package Compare versions

Comparing version 4.3.0 to 4.3.1

6

dist/browser.js

@@ -129,3 +129,3 @@ import oTracking from '@financial-times/o-tracking';

var n={t:!1,i:!1,o:3e4},e=window,t=e.console,i=document,r=e.navigator,o=e.performance,u=function(){return r.deviceMemory},c=function(){return r.hardwareConcurrency},a=function(){return o&&!!o.getEntriesByType&&!!o.now&&!!o.mark},f="4g",s=!1,l=function(){return !!(c()&&c()<=4)||!!(u()&&u()<=4)},m=function(n,e){switch(n){case"slow-2g":case"2g":case"3g":return !0;default:return l()||e}},v={u:!1},d=function(n){i.hidden&&(n(),v.u=i.hidden);},p=function(n){return parseFloat(n.toFixed(4))},g=function(n){return "number"!=typeof n?null:p(n/Math.pow(1024,2))},h=[2e3,4e3],k=[2500,4e3],y=[.1,.25],T={ttfb:[200,500],fp:h,fcp:h,lcp:k,lcpFinal:k,fid:[100,300],cls:y,clsFinal:y,tbt:[300,600]},b=function(n,e){return T[n]?e<=T[n][0]?"good":e<=T[n][1]?"needsImprovement":"poor":null},w=function(t,i,o){var a;a=function(){v.u&&t.indexOf("Final")<0||!n.analyticsTracker||n.analyticsTracker({metricName:t,data:i,eventProperties:o||{},navigatorInformation:r?{deviceMemory:u()||0,hardwareConcurrency:c()||0,serviceWorkerStatus:"serviceWorker"in r?r.serviceWorker.controller?"controlled":"supported":"unsupported",isLowEndDevice:l(),isLowEndExperience:m(f,s)}:{},vitalsScore:b(t,i)});},"requestIdleCallback"in e?e.requestIdleCallback(a,{timeout:3e3}):a();},_=function(n,e,t){Object.keys(e).forEach((function(n){"number"==typeof e[n]&&(e[n]=p(e[n]));})),w(n,e,t);},F=function(e,t,i){var r=p(e);r<=n.o&&r>=0&&w(t,r,i);},E={},x={value:0},D={value:0},I={value:0},P={value:{beacon:0,css:0,fetch:0,img:0,other:0,script:0,total:0,xmlhttprequest:0}},j={value:0},q=function(n){var e=n.pop();e&&!e.s&&e.value&&(x.value+=e.value);},C={},L=function(n,e){try{var i=new PerformanceObserver((function(n){e(n.getEntries());}));return i.observe({type:n,buffered:!0}),i}catch(n){t.warn("Perfume.js:",n);}return null},O=function(n){C[n]&&C[n].disconnect(),delete C[n];},S=function(n){var e=n.pop();e&&F(e.processingStart-e.startTime,"fid",{performanceEntry:e}),O(1),F(I.value,"lcp"),C[3]&&"function"==typeof C[3].takeRecords&&C[3].takeRecords(),F(x.value,"cls"),setTimeout((function(){F(j.value,"tbt"),_("dataConsumption",P.value);}),1e4);},W=function(n){n.forEach((function(n){if(!("self"!==n.name||n.startTime<D.value)){var e=n.duration-50;e>0&&(j.value+=e);}}));},B=function(n){n.forEach((function(n){"first-paint"===n.name?F(n.startTime,"fp"):"first-contentful-paint"===n.name&&(D.value=n.startTime,F(D.value,"fcp"),C[4]=L("longtask",W),O(0));}));},M=function(n){var e=n.pop();e&&(I.value=e.renderTime||e.loadTime);},z=function(n){n.forEach((function(n){n.identifier&&F(n.startTime,n.identifier);}));},H=function(e){e.forEach((function(e){if(n.t&&_("resourceTiming",e),e.decodedBodySize&&e.initiatorType){var t=e.decodedBodySize/1e3;P.value[e.initiatorType]+=t,P.value.total+=t;}}));},N=function(){C[2]&&(F(I.value,"lcpFinal"),O(2)),C[3]&&("function"==typeof C[3].takeRecords&&C[3].takeRecords(),F(x.value,"clsFinal"),O(3));},R=function(n){var e="usageDetails"in n?n.usageDetails:{};_("storageEstimate",{quota:g(n.quota),usage:g(n.usage),caches:g(e.caches),indexedDB:g(e.indexedDB),serviceWorker:g(e.serviceWorkerRegistrations)});},A=function(){function t(t){if(void 0===t&&(t={}),this.l="6.2.0",n.analyticsTracker=t.analyticsTracker,n.t=!!t.resourceTiming,n.i=!!t.elementTiming,n.o=t.maxMeasureTime||n.o,a()){"PerformanceObserver"in e&&(C[0]=L("paint",B),C[1]=L("first-input",S),C[2]=L("largest-contentful-paint",M),n.t&&L("resource",H),C[3]=L("layout-shift",q),n.i&&L("element",z)),void 0!==i.hidden&&i.addEventListener("visibilitychange",d.bind(this,N));var u=function(){if(!a())return {};var n=o.getEntriesByType("navigation")[0];if(!n)return {};var e=n.responseStart,t=n.responseEnd;return {fetchTime:t-n.fetchStart,workerTime:n.workerStart>0?t-n.workerStart:0,totalTime:t-n.requestStart,downloadTime:t-e,timeToFirstByte:e-n.requestStart,headerSize:n.transferSize-n.encodedBodySize||0,dnsLookupTime:n.domainLookupEnd-n.domainLookupStart,redirectTime:n.redirectEnd-n.redirectStart}}();_("navigationTiming",u),u.timeToFirstByte&&F(u.timeToFirstByte,"ttfb"),_("networkInformation",function(){if("connection"in r){var n=r.connection;return "object"!=typeof n?{}:(f=n.effectiveType,s=!!n.saveData,{downlink:n.downlink,effectiveType:n.effectiveType,rtt:n.rtt,saveData:!!n.saveData})}return {}}()),r&&r.storage&&"function"==typeof r.storage.estimate&&r.storage.estimate().then(R);}}return t.prototype.start=function(n){a()&&!E[n]&&(E[n]=!0,o.mark("mark_"+n+"_start"),v.u=!1);},t.prototype.end=function(n,e){void 0===e&&(e={}),a()&&E[n]&&(o.mark("mark_"+n+"_end"),delete E[n],_(n,p(function(n){o.measure(n,"mark_"+n+"_start","mark_"+n+"_end");var e=o.getEntriesByName(n).pop();return e&&"measure"===e.entryType?e.duration:-1}(n)),e));},t.prototype.endPaint=function(n,e){var t=this;setTimeout((function(){t.end(n,e);}));},t.prototype.clear=function(n){delete E[n],o.clearMarks&&(o.clearMarks("mark_"+n+"_start"),o.clearMarks("mark_"+n+"_end"));},t}();
var n={t:!1,i:!1,o:3e4},t=window,e=t.console,i=document,r=t.navigator,o=t.performance,u=function(){return r.deviceMemory},c=function(){return r.hardwareConcurrency},a=function(){return o&&!!o.getEntriesByType&&!!o.now&&!!o.mark},f="4g",s=!1,l=function(){return !!(c()&&c()<=4)||!!(u()&&u()<=4)},m=function(n,t){switch(n){case"slow-2g":case"2g":case"3g":return !0;default:return l()||t}},v={u:!1},d=function(n){i.hidden&&(n(),v.u=i.hidden);},p=function(n){return parseFloat(n.toFixed(4))},g=function(n){return "number"!=typeof n?null:p(n/Math.pow(1024,2))},b=[2e3,4e3],h=[2500,4e3],T=[.1,.25],k={ttfb:[200,500],fp:b,fcp:b,lcp:h,lcpFinal:h,fid:[100,300],cls:T,clsFinal:T,tbt:[300,600],ntbt:[400,600]},y=function(n,t){return k[n]?t<=k[n][0]?"good":t<=k[n][1]?"needsImprovement":"poor":null},w=function(e,i,o){var a;a=function(){v.u&&e.indexOf("Final")<0||!n.analyticsTracker||n.analyticsTracker({metricName:e,data:i,eventProperties:o||{},navigatorInformation:r?{deviceMemory:u()||0,hardwareConcurrency:c()||0,serviceWorkerStatus:"serviceWorker"in r?r.serviceWorker.controller?"controlled":"supported":"unsupported",isLowEndDevice:l(),isLowEndExperience:m(f,s)}:{},vitalsScore:y(e,i)});},"requestIdleCallback"in t?t.requestIdleCallback(a,{timeout:3e3}):a();},_=function(n,t,e){Object.keys(t).forEach((function(n){"number"==typeof t[n]&&(t[n]=p(t[n]));})),w(n,t,e);},F=function(t,e,i){var r=p(t);r<=n.o&&r>=0&&w(e,r,i);},E={},x={value:0},D={value:0},I={value:0},P={value:{beacon:0,css:0,fetch:0,img:0,other:0,script:0,total:0,xmlhttprequest:0}},j={value:0},q={value:0},C=function(n){var t=n.pop();t&&!t.s&&t.value&&(x.value+=t.value);},L={},O=function(n,t){try{var i=new PerformanceObserver((function(n){t(n.getEntries());}));return i.observe({type:n,buffered:!0}),i}catch(n){e.warn("Perfume.js:",n);}return null},S=function(n){L[n]&&L[n].disconnect(),delete L[n];},W=function(n){var t=n.pop();t&&F(t.processingStart-t.startTime,"fid",{performanceEntry:t}),S(1),F(I.value,"lcp"),L[3]&&"function"==typeof L[3].takeRecords&&L[3].takeRecords(),F(x.value,"cls"),setTimeout((function(){F(j.value,"tbt"),_("dataConsumption",P.value);}),1e4);},B=function(n){n.forEach((function(n){if(!("self"!==n.name||n.startTime<D.value)){var t=n.duration-50;t>0&&(j.value+=t,q.value+=t);}}));},M=function(n){n.forEach((function(n){"first-paint"===n.name?F(n.startTime,"fp"):"first-contentful-paint"===n.name&&(D.value=n.startTime,F(D.value,"fcp"),L[4]=O("longtask",B),S(0));}));},z=function(n){var t=n.pop();t&&(I.value=t.renderTime||t.loadTime);},H=function(n){n.forEach((function(n){n.identifier&&F(n.startTime,n.identifier);}));},N=function(t){t.forEach((function(t){if(n.t&&_("resourceTiming",t),t.decodedBodySize&&t.initiatorType){var e=t.decodedBodySize/1e3;P.value[t.initiatorType]+=e,P.value.total+=e;}}));},R=function(){L[2]&&(F(I.value,"lcpFinal"),S(2)),L[3]&&("function"==typeof L[3].takeRecords&&L[3].takeRecords(),F(x.value,"clsFinal"),S(3));},A=function(n){var t="usageDetails"in n?n.usageDetails:{};_("storageEstimate",{quota:g(n.quota),usage:g(n.usage),caches:g(t.caches),indexedDB:g(t.indexedDB),serviceWorker:g(t.serviceWorkerRegistrations)});},G=0,J=function(){function e(e){if(void 0===e&&(e={}),this.l="6.4.0",n.analyticsTracker=e.analyticsTracker,n.t=!!e.resourceTiming,n.i=!!e.elementTiming,n.o=e.maxMeasureTime||n.o,a()){"PerformanceObserver"in t&&(L[0]=O("paint",M),L[1]=O("first-input",W),L[2]=O("largest-contentful-paint",z),n.t&&O("resource",N),L[3]=O("layout-shift",C),n.i&&O("element",H)),void 0!==i.hidden&&i.addEventListener("visibilitychange",d.bind(this,R));var u=function(){if(!a())return {};var n=o.getEntriesByType("navigation")[0];if(!n)return {};var t=n.responseStart,e=n.responseEnd;return {fetchTime:e-n.fetchStart,workerTime:n.workerStart>0?e-n.workerStart:0,totalTime:e-n.requestStart,downloadTime:e-t,timeToFirstByte:t-n.requestStart,headerSize:n.transferSize-n.encodedBodySize||0,dnsLookupTime:n.domainLookupEnd-n.domainLookupStart,redirectTime:n.redirectEnd-n.redirectStart}}();_("navigationTiming",u),u.timeToFirstByte&&F(u.timeToFirstByte,"ttfb"),_("networkInformation",function(){if("connection"in r){var n=r.connection;return "object"!=typeof n?{}:(f=n.effectiveType,s=!!n.saveData,{downlink:n.downlink,effectiveType:n.effectiveType,rtt:n.rtt,saveData:!!n.saveData})}return {}}()),r&&r.storage&&"function"==typeof r.storage.estimate&&r.storage.estimate().then(A);}}return e.prototype.start=function(n){a()&&!E[n]&&(E[n]=!0,o.mark("mark_"+n+"_start"),v.u=!1);},e.prototype.end=function(n,t,e){if(void 0===t&&(t={}),void 0===e&&(e=!0),a()&&E[n]){o.mark("mark_"+n+"_end"),delete E[n];var i=function(n){o.measure(n,"mark_"+n+"_start","mark_"+n+"_end");var t=o.getEntriesByName(n).pop();return t&&"measure"===t.entryType?t.duration:-1}(n);e&&_(n,p(i),t);}},e.prototype.endPaint=function(n,t){var e=this;setTimeout((function(){e.end(n,t);}));},e.prototype.clear=function(n){delete E[n],o.clearMarks&&(o.clearMarks("mark_"+n+"_start"),o.clearMarks("mark_"+n+"_end"));},e.prototype.markNTBT=function(){var n=this;this.start("ntbt"),q.value=0,clearTimeout(G),G=setTimeout((function(){n.end("ntbt",{},!1),F(q.value,"ntbt"),q.value=0;}),2e3);},e}();

@@ -397,2 +397,4 @@ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};

context.url = window.document.location.href || null;
if (isContextComplete(context)) {

@@ -411,3 +413,3 @@ console.log({ performanceMetrics: context }); // eslint-disable-line no-console

new A({
new J({
analyticsTracker,

@@ -414,0 +416,0 @@ logging: false

@@ -6,3 +6,3 @@ {

"browser": "dist/browser.js",
"version": "4.3.0",
"version": "4.3.1",
"license": "MIT",

@@ -9,0 +9,0 @@ "repository": "Financial-Times/n-tracking.git",

@@ -81,2 +81,4 @@ import Perfume from 'perfume.js';

context.url = window.document.location.href || null;
if (isContextComplete(context)) {

@@ -83,0 +85,0 @@ console.log({ performanceMetrics: context }); // eslint-disable-line no-console

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc