Update CLS metric to match newest CWV standard#36147
Merged
jridgewell merged 8 commits intoampproject:mainfrom Sep 24, 2021
Merged
Update CLS metric to match newest CWV standard#36147jridgewell merged 8 commits intoampproject:mainfrom
jridgewell merged 8 commits intoampproject:mainfrom
Conversation
rcebulko
approved these changes
Sep 23, 2021
rcebulko
reviewed
Sep 23, 2021
samouri
reviewed
Sep 23, 2021
Member
samouri
left a comment
There was a problem hiding this comment.
How often do you want cls to be ticked? AFAICT this could happen many times in a single session
| } | ||
| entries.push(entry); | ||
| // Ensure we report the CLS when the session closes. We're not guaranteed | ||
| // to get more LayoutShift entires, so we need some setTimeout magic to |
Member
There was a problem hiding this comment.
Suggested change
| // to get more LayoutShift entires, so we need some setTimeout magic to | |
| // to get more LayoutShift entries, so we need some setTimeout magic to |
| // We'll record the largest windowed CLS. | ||
| this.metrics_.reset(TickLabel.CUMULATIVE_LAYOUT_SHIFT); | ||
| this.metrics_.reset(TickLabel.CUMULATIVE_LAYOUT_SHIFT_TYPE_UNION); | ||
| this.tickDelta(TickLabel.CUMULATIVE_LAYOUT_SHIFT, sum); |
Member
There was a problem hiding this comment.
Should calling tick on an already reported metric automatically reset it? I.e. so you don't need to do so here as well.
The CLS metric used to be a sum of the shifts over the entire lifetime of the page. However, Google has changed this so that it's now defined as the largest sum over a windowed session (see https://web.dev/evolving-cls/). We're still going to record the old value, but it's now called `cls-1`. Regular `cls` will now be the windowed session value. Additionally, we'll record the types of nodes that contribute to the CLS (as `clstu`, standing for CLS-Type Union), so that we can better understand what's causing it.
erwinmombay
approved these changes
Sep 24, 2021
samouri
reviewed
Sep 24, 2021
| | Layout Jank, first exit | `lj` | The aggregate jank score when the user leaves the page (navigation, tab switching, dismissing application) for the first time. See https://gist.github.com/skobes/2f296da1b0a88cc785a4bf10a42bca07 | | ||
| | Layout Jank, second exit | `lj-2` | The aggregate jank score when the user leaves the page (navigation, tab switching, dismissing application) for the second time. | | ||
| | Cumulative Layout Shift, first exit | `cls` | The aggregate layout shift score when the user leaves the page (navigation, tab switching, dismissing application) for the first time. See https://web.dev/layout-instability-api | | ||
| | Cumulative Layout Shift | `cls` | The current maximum layout shift score with 5s windows and a 1s session gap. See https://web.dev/layout-instability-api | |
| * @private {Array<LayoutShift>} | ||
| */ | ||
| this.layoutShifts_ = []; | ||
| this.layoutShiftEntires_ = []; |
jridgewell
added a commit
to jridgewell/amphtml
that referenced
this pull request
Oct 8, 2021
In ampproject#36147, we switched to the new windowed CLS metric. This new algorithm can send multiple CLS scores, where each new score is larger than the last. Because of this multiple-sends-which-are-larger-than-the-last behavior, our CLS scores have gone up marginally. The p95 is considering every CLS score sent by the page, instead of just the most recent. In order to determine which is the most recent, we'll add a random `eventid` to our `sendCsi` message, which can then be used when aggregating.
jridgewell
added a commit
to jridgewell/amphtml
that referenced
this pull request
Oct 8, 2021
In ampproject#36147, we switched to the new windowed CLS metric. This new algorithm can send multiple CLS scores, where each new score is larger than the last. Because of this multiple-sends-which-are-larger-than-the-last behavior, our CLS scores have gone up marginally. The p95 is considering every CLS score sent by the page, instead of just the most recent. In order to determine which is the most recent, we'll add a random `eventid` to our `sendCsi` message, which can then be used when aggregating.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The CLS metric used to be a sum of the shifts over the entire lifetime of the page. However, Google has changed this so that it's now defined as the largest sum over a windowed session (see https://web.dev/evolving-cls/).
We're still going to record the old value, but it's now called
cls-1. Regularclswill now be the windowed session value. Additionally, we'll record the types of nodes that contribute to the CLS (asclstu, standing for CLS-Type Union), so that we can better understand what's causing it.