-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Switch web vitals library to attribution build (#919)
- Loading branch information
Showing
26 changed files
with
323 additions
and
237 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
import { onCLS } from 'web-vitals' | ||
import { onCLS } from 'web-vitals/attribution' | ||
import { VITAL_NAMES } from './constants' | ||
import { VitalMetric } from './vital-metric' | ||
import { isBrowserScope } from '../constants/runtime' | ||
|
||
export const cumulativeLayoutShift = new VitalMetric(VITAL_NAMES.CUMULATIVE_LAYOUT_SHIFT, (x) => x) | ||
|
||
if (isBrowserScope) { | ||
onCLS(({ value, entries }) => { | ||
if (cumulativeLayoutShift.roundingMethod(value) === cumulativeLayoutShift.current.value) return | ||
cumulativeLayoutShift.update({ value, entries }) | ||
onCLS(({ value, attribution, id }) => { | ||
const attrs = { | ||
metricId: id, | ||
largestShiftTarget: attribution.largestShiftTarget, | ||
largestShiftTime: attribution.largestShiftTime, | ||
largestShiftValue: attribution.largestShiftValue, | ||
loadState: attribution.loadState | ||
} | ||
cumulativeLayoutShift.update({ value, attrs }) | ||
}, { reportAllChanges: true }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,24 @@ | ||
import { onFID } from 'web-vitals' | ||
import { onFID } from 'web-vitals/attribution' | ||
import { VitalMetric } from './vital-metric' | ||
import { VITAL_NAMES } from './constants' | ||
import { initiallyHidden, isBrowserScope } from '../constants/runtime' | ||
|
||
export const firstInputDelay = new VitalMetric(VITAL_NAMES.FIRST_INPUT_DELAY) | ||
|
||
if (isBrowserScope) { | ||
onFID(({ value, entries }) => { | ||
if (initiallyHidden || firstInputDelay.isValid || entries.length === 0) return | ||
onFID(({ value, attribution }) => { | ||
if (initiallyHidden || firstInputDelay.isValid) return | ||
const attrs = { | ||
type: attribution.eventType, | ||
fid: Math.round(value), | ||
eventTarget: attribution.eventTarget, | ||
loadState: attribution.loadState | ||
} | ||
|
||
// CWV will only report one (THE) first-input entry to us; fid isn't reported if there are no user interactions occurs before the *first* page hiding. | ||
firstInputDelay.update({ | ||
value: entries[0].startTime, | ||
entries, | ||
attrs: { type: entries[0].name, fid: Math.round(value) } | ||
value: attribution.eventTime, | ||
attrs | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.