diff --git a/src/performance/index.ts b/src/performance/index.ts index 0901bd8..cda620d 100644 --- a/src/performance/index.ts +++ b/src/performance/index.ts @@ -21,7 +21,7 @@ import {prerenderChangeListener, onHidden, runOnce, idlePeriod} from '../service import pagePerf from './perf'; import FMP from './fmp'; import {observe} from '../services/observe'; -import {LCPMetric, INPMetric, CLSMetric} from './type'; +import {LCPMetric, INPMetric, CLSMetric, INPListItem} from './type'; import {LayoutShift} from '../services/types'; import {getVisibilityObserver} from '../services/getVisibilityObserver'; import {getActivationStart, getResourceEntry} from '../services/getEntries'; @@ -58,7 +58,7 @@ class TracePerf { private perfInfo = {}; private coreWebMetrics: Record = {}; private resources: {name: string, duration: number, size: number, protocol: string, resourceType: string}[] = []; - private inpList: Record[] = []; + private inpList: INPListItem[] = []; public getPerf(options: CustomOptionsType) { this.options = options; this.perfInfo = { @@ -152,7 +152,7 @@ class TracePerf { }); if (partValue > 0) { setTimeout(() => { - this.coreWebMetrics.clsTime = partValue; + this.coreWebMetrics.clsTime = partValue > 1 ? Math.floor(partValue) : Math.round(partValue); }, 3000); } }; @@ -214,7 +214,7 @@ class TracePerf { const param = { inpTime: interaction.latency, ...this.perfInfo, - }; + } as INPListItem; this.inpList.push(param); } }) @@ -242,8 +242,11 @@ class TracePerf { if (!this.inpList.length) { return; } - - new Report('WEBINTERACTIONS', this.options.collector).sendByBeacon(this.inpList); + const inpList = this.inpList.map((item: INPListItem) => ({ + ...item, + inpTime: item.inpTime > 1 ? Math.floor(item.inpTime) : Math.round(item.inpTime), + })); + new Report('WEBINTERACTIONS', this.options.collector).sendByBeacon(inpList); } private getBasicPerf() { // auto report pv and perf data diff --git a/src/performance/type.ts b/src/performance/type.ts index a6ef5c0..87c2aba 100644 --- a/src/performance/type.ts +++ b/src/performance/type.ts @@ -54,3 +54,10 @@ export interface CLSMetric { name: 'CLS'; entries: LayoutShift[]; } + +export interface INPListItem { + inpTime: number; + service: string; + serviceVersion: string; + pagePath: string; +} \ No newline at end of file