Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/performance/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -58,7 +58,7 @@ class TracePerf {
private perfInfo = {};
private coreWebMetrics: Record<string, unknown> = {};
private resources: {name: string, duration: number, size: number, protocol: string, resourceType: string}[] = [];
private inpList: Record<string, string|number>[] = [];
private inpList: INPListItem[] = [];
public getPerf(options: CustomOptionsType) {
this.options = options;
this.perfInfo = {
Expand Down Expand Up @@ -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);
}
};
Expand Down Expand Up @@ -214,7 +214,7 @@ class TracePerf {
const param = {
inpTime: interaction.latency,
...this.perfInfo,
};
} as INPListItem;
this.inpList.push(param);
}
})
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/performance/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,10 @@ export interface CLSMetric {
name: 'CLS';
entries: LayoutShift[];
}

export interface INPListItem {
inpTime: number;
service: string;
serviceVersion: string;
pagePath: string;
}
Loading