GoogleChrome / web-vitals

Essential metrics for a healthy site.
https://web.dev/vitals
Apache License 2.0
7.47k stars 410 forks source link

Using `performance.eventCounts` instead of `performance.interactionCount` #491

Closed ekremney closed 3 months ago

ekremney commented 3 months ago

I couldn't find any reference to performance.interactionCount on web (except one W3 document). Also, both Google Chrome and Firefox don't seem to have it -> both returns undefined.

Suggesting to use the performance.eventCounts property instead of interactionCount to getInteractionCount.

mmocny commented 3 months ago

The one w3 document I assume is the Event Timing spec?

Chrome has implemented this feature, but it is still behind a feature flag in Stable (or via experimental web platform features). We expect to ship it in stable.

eventCounts is not possible to use as a way to estimate interactionCount (and its the reason Event Timing added interactionCount). (You can also find lots of discussion in the Web Perf WG for this feature).


The single biggest flaw of eventCount is that it does not differentiate when e.g. pointer events actually become a scroll, or how keyboard events might trigger clicks, or how accessibility or IME interfaces might dispatch events in different orders...

You could try to approximate interactionCount but using something like the count of clicks - count of pointerCancel, and an earlier version of web-vitals.js actually tried that (especially since this is supported on Firefox). Unfortunately it was off and unreliable on all browsers.

ekremney commented 3 months ago

that's a very clear explanation, thanks @mmocny!