MCPcopy
hub / github.com/Zizzamia/perfume.js / reportPerf

Function reportPerf

src/reportPerf.ts:10–43  ·  view source on GitHub ↗
(
  measureName: string,
  data: any,
  rating: IVitalsScore,
  attribution: object,
  navigationType?: INavigationType,
)

Source from the content-addressed store, hash-verified

8 * Sends the User timing measure to analyticsTracker
9 */
10export const reportPerf = (
11 measureName: string,
12 data: any,
13 rating: IVitalsScore,
14 attribution: object,
15 navigationType?: INavigationType,
16): void => {
17 const reportTask = () => {
18 if (!config.analyticsTracker) {
19 return;
20 }
21 // Doesn't send timing when page is hidden
22 if (visibility.isHidden && !['CLS', 'INP'].includes(measureName)) {
23 return;
24 }
25 // Send metric to custom Analytics service
26 config.analyticsTracker({
27 attribution,
28 metricName: measureName,
29 data,
30 navigatorInformation: getNavigatorInfo(),
31 rating,
32 navigationType,
33 });
34 };
35
36 // Send CLS and INP metrics immediately,
37 // because this metrics are reported when page is hidden or closed
38 if (['CLS', 'INP'].includes(measureName)) {
39 reportTask();
40 } else {
41 pushTask(reportTask);
42 }
43};

Callers 4

logDataFunction · 0.90
logMetricFunction · 0.90
measureStepFunction · 0.90
reportPerf.spec.tsFile · 0.90

Calls 2

pushTaskFunction · 0.90
reportTaskFunction · 0.85

Tested by

no test coverage detected