大网数据广告活动
Web 标准与前端开发

PerformanceEventTiming: interactionId property

· 52CE 我爱测

The read-only **`interactionId`** property of the PerformanceEventTiming interface returns an ID that uniquely identifies a user interaction which triggered a series of associated events.

Performance API

The read-only interactionId property of the PerformanceEventTiming interface returns an ID that uniquely identifies a user interaction which triggered a series of associated events.

Value

A number. For event types where an interaction ID is not calculated the value is 0.

Description

When a user interacts with a web page, a user interaction (for example a click) usually triggers a sequence of events, such as pointerdown, pointerup, and click events. To measure the latency of this series of events, the events share the same interactionId.

An interactionId is only computed for the following event types belonging to a user interaction. It is 0 otherwise.

Event types User interaction
Element/pointerdown_event, Element/pointerup_event, Element/click_event click / tap / drag
Element/contextmenu_event context menu
Element/input_event IME composition input
Element/keydown_event, Element/keyup_event key press

The interactionId is also needed to calculate the Interaction to next paint metric, which helps analyze responsiveness to user interaction over the lifetime of a page.

Examples

Using interactionId

The following example groups the durations of observed events by interaction ID. By default, only events with a duration of at least 104 milliseconds are reported. The eventLatencies map can then be used to find events with maximum duration for a user interaction, for example.

// The key is the interaction ID.
const eventLatencies = new Map();

const observer = new PerformanceObserver((list) => {
  list.getEntries().forEach((entry) => {
    if (entry.interactionId > 0) {
      const interactionId = entry.interactionId;
      if (!eventLatencies.has(interactionId)) {
        eventLatencies.set(interactionId, []);
      }
      eventLatencies.get(interactionId).push(entry.duration);
    }
  });

  // Log the maximum observed event duration for each interaction.
  eventLatencies.forEach((durations, interactionId) => {
    console.log(interactionId, Math.max(...durations));
  });
});

observer.observe({ type: "event", buffered: true });

Specifications

Browser compatibility

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。