效能:eventCounts 屬性
只讀的 performance.eventCounts 屬性是一個 EventCounts 對映,其中包含按事件型別分派的事件數量。
並非所有事件型別都已公開。您只能獲取由 PerformanceEventTiming 介面支援的事件型別的計數。
值
一個 EventCounts 對映。(一個只讀的 Map,不包含 clear()、delete() 和 set() 方法)。
示例
報告事件型別及其計數
如果您想將事件計數傳送到您的分析系統,您可能需要實現一個像 sendToEventAnalytics 這樣的函式,該函式從 performance.eventCounts 對映中獲取事件計數,然後使用 Fetch API 將資料釋出到您的端點。
js
// Report all exposed events
for (entry of performance.eventCounts.entries()) {
const type = entry[0];
const count = entry[1];
// sendToEventAnalytics(type, count);
}
// Report a specific event
const clickCount = performance.eventCounts.get("click");
// sendToEventAnalytics("click", clickCount);
// Check if an event count is exposed for a type
const isExposed = performance.eventCounts.has("mousemove"); // false
規範
| 規範 |
|---|
| 事件計時 API # dom-performance-eventcounts |
瀏覽器相容性
載入中…