( measureName: string, data: any, rating: IVitalsScore, attribution: object, navigationType?: INavigationType, )
| 8 | * Sends the User timing measure to analyticsTracker |
| 9 | */ |
| 10 | export 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 | }; |
no test coverage detected