Skip to content

Commit 9548e82

Browse files
tunethewebchrisdavidmillssideshowbarkergithub-actions[bot]
authored
Add interactionCount docs (mdn#42646)
* Add interactionCount docs * Apply suggestions from code review Co-authored-by: Chris Mills <chrisdavidmills@gmail.com> * More review feedback * Update files/en-us/web/api/performance/interactioncount/index.md * Update files/en-us/glossary/interaction_to_next_paint/index.md * Update files/en-us/web/api/performance/interactioncount/index.md Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Small fix * Couple of small fixes --------- Co-authored-by: Chris Mills <chrisdavidmills@gmail.com> Co-authored-by: sideshowbarker <mike@w3.org> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 9c27111 commit 9548e82

File tree

4 files changed

+51
-5
lines changed

4 files changed

+51
-5
lines changed

files/en-us/glossary/interaction_to_next_paint/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ INP was designed by Google as one of the [Core Web Vital](https://web.dev/articl
1414

1515
INP measures the worst length of time (minus some outliers), in milliseconds, between the user interaction on a web page and the next frame presentation after that interaction is processed. Scrolling and zooming are not included in this metric. INP is calculated using the [Event Timing API](/en-US/docs/Web/API/PerformanceEventTiming). Asynchronous operations such as network fetches or file reads usually do not delay INP as painting can occur while such operations are handled.
1616

17-
All eligible interactions throughout the page lifetime are considered. For highly interactive pages of 50 or more interactions, the 98th percentile is used to exclude some extreme outliers that are not reflective of overall page responsiveness.
17+
All eligible interactions throughout the page lifetime are considered. For highly interactive pages of 50 or more interactions, the 98th percentile is used to exclude extreme outliers that are not reflective of overall page responsiveness. The {{domxref("Performance.interactionCount")}} value can be used to query the interaction count to determine when a large number of interactions have happened on a page.
1818

1919
The longer the delay, the worse the user experience. The [Long Animation Frames API](/en-US/docs/Web/API/Performance_API/Long_animation_frame_timing) can help identify causes of high INP.
2020

2121
## See also
2222

2323
- [Long animation frame timing](/en-US/docs/Web/API/Performance_API/Long_animation_frame_timing)
2424
- [PerformanceEventTiming](/en-US/docs/Web/API/PerformanceEventTiming)
25+
- {{domxref("Performance.interactionCount")}}
2526
- [INP](https://web.dev/articles/inp) on web.dev (2023)
2627
- [Optimize Interaction to Next Paint](https://web.dev/articles/optimize-inp) on web.dev (2023)
2728
- [Interaction to Next Paint is officially a Core Web Vital](https://web.dev/blog/inp-cwv-launch) on web.dev (2024)

files/en-us/web/api/performance/eventcounts/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ browser-compat: api.Performance.eventCounts
88

99
{{APIRef("Performance API")}}
1010

11-
The read-only `performance.eventCounts` property is an {{domxref("EventCounts")}} map containing the number of events which have been dispatched per event type.
11+
The read-only `performance.eventCounts` property is an {{domxref("EventCounts")}} map containing the number of events which have been dispatched per event type since the page was loaded.
1212

1313
Not all event types are exposed. You can only get counts for event types supported by the {{domxref("PerformanceEventTiming")}} interface.
1414

files/en-us/web/api/performance/index.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@ _The `Performance` interface doesn't inherit any properties._
1919

2020
- {{domxref("Performance.eventCounts")}} {{ReadOnlyInline}}
2121
- : An {{domxref("EventCounts")}} map containing the number of events which have been dispatched per event type.
22-
22+
- {{domxref("Performance.interactionCount")}} {{ReadOnlyInline}}
23+
- : The number of real-user interactions that have occurred on the page, which is useful when calculating {{Glossary("Interaction_to_next_paint", "Interaction to Next Paint (INP)")}}.
2324
- {{domxref("Performance.navigation")}} {{ReadOnlyInline}} {{Deprecated_Inline}}
2425
- : A legacy {{domxref("PerformanceNavigation")}} object that provides useful context about the operations included in the times listed in `timing`, including whether the page was a load or a refresh, how many redirections occurred, and so forth.
25-
2626
- {{domxref("Performance.timing")}} {{ReadOnlyInline}} {{Deprecated_Inline}}
2727
- : A legacy {{domxref("PerformanceTiming")}} object containing latency-related performance information.
28-
2928
- {{domxref("Performance.memory")}} {{ReadOnlyInline}} {{Non-standard_Inline}} {{Deprecated_Inline}}
3029
- : A _non-standard_ extension added in Chrome, this property provides an object with basic memory usage information. _You **should not use** this non-standard API._
3130
- {{domxref("Performance.timeOrigin")}} {{ReadOnlyInline}}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
title: "Performance: interactionCount property"
3+
short-title: interactionCount
4+
slug: Web/API/Performance/interactionCount
5+
page-type: web-api-instance-property
6+
browser-compat: api.Performance.interactionCount
7+
---
8+
9+
{{APIRef("Performance API")}}
10+
11+
The read-only `performance.interactionCount` property represents the number of real-user interactions that have occurred on the page since it was loaded.
12+
13+
Only discrete interactions with an {{domxref("PerformanceEventTiming.interactionId", "interactionId")}} — such as clicks and key events — are counted. Other interactions, such as scroll interactions, are excluded.
14+
15+
This is useful when calculating {{Glossary("Interaction_to_next_paint", "Interaction to Next Paint (INP)")}}, and in particular to exclude outliers for long-lived pages. INP takes the 98th percentile of interactions for a page and so excludes 1 in every 50 interactions as "outliers" that are not reflective of overall page responsiveness.
16+
17+
## Value
18+
19+
A number, which is initially `0`, and increments by `1` with each discrete interaction as measured by {{domxref("PerformanceEventTiming")}}, where an {{domxref("PerformanceEventTiming.interactionId")}} is assigned.
20+
21+
## Examples
22+
23+
### Checking the number of interactions to accurately calculate INP
24+
25+
For pages with a large number of interactions, you can recalculate INP after
26+
excluding 1 out of every 50 outliers using the following pattern:
27+
28+
```js
29+
if (performance.interactionCount >= 50) {
30+
recalculateINP(); // Actual calculation is complex and is not shown here
31+
}
32+
```
33+
34+
## Specifications
35+
36+
{{Specifications}}
37+
38+
## Browser compatibility
39+
40+
{{Compat}}
41+
42+
## See also
43+
44+
- {{domxref("PerformanceEventTiming")}}
45+
- {{domxref("PerformanceEventTiming.interactionId")}}
46+
- {{Glossary("Interaction_to_next_paint", "Interaction to Next Paint (INP)")}}

0 commit comments

Comments
 (0)