-
Notifications
You must be signed in to change notification settings - Fork 56
feat: Switch web vitals library to attribution build #919
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 12 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
53751f5
Convert onCls to attribution
cwli24 5c9c756
Convert onFCP to attribution
cwli24 84e2307
Rectify cls jest tests
cwli24 7750cc8
Convert onFID and block cls node gen if not triggered
cwli24 002c5f6
Add metric id to CLS node
cwli24 efa3394
Merge commit '91b1f96efafe19f7b1b3fd4f39b9af1136b0a3a8' into cwv-attr…
cwli24 8257458
Fix tests not applying to android versions properly
cwli24 c5522ba
Convert onINP to attribution
cwli24 63b3ba7
Convert onLCP to attribution
cwli24 d8f23c7
Correct report once test cases for FCP, FID, LCP
cwli24 db067d3
Add ttfb as attribute to FCP, LCP
cwli24 c3fdfd9
Exclude cls node for now
cwli24 963aa8f
Merge commit 'fb4e36bedd2fd2961817cfb0ac427d736acce740' into cwv-attr…
cwli24 cb8a908
Switch onTTFB to attribution
cwli24 888a826
Eliminate entries from vital metrics
cwli24 f05227a
PR comment
cwli24 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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, | ||
metal-messiah marked this conversation as resolved.
Show resolved
Hide resolved
|
||
largestShiftTarget: attribution.largestShiftTarget, | ||
largestShiftTime: attribution.largestShiftTime, | ||
largestShiftValue: attribution.largestShiftValue, | ||
loadState: attribution.loadState | ||
} | ||
cumulativeLayoutShift.update({ value, attrs }) | ||
}, { reportAllChanges: true }) | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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, | ||
cwli24 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
attrs: { type: entries[0].name, fid: Math.round(value) } | ||
value: attribution.eventTime, | ||
attrs | ||
}) | ||
}) | ||
} |
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.