-
Notifications
You must be signed in to change notification settings - Fork 22.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
--- | ||
title: EventCounts | ||
slug: Web/API/EventCounts | ||
page-type: web-api-interface | ||
tags: | ||
- API | ||
- Reference | ||
- Interface | ||
- Maplike | ||
browser-compat: api.EventCounts | ||
--- | ||
|
||
{{APIRef("Event Timing")}} | ||
|
||
The **`EventCounts`** interface is a read-only map where the keys are event types and the values are the number of events that have been dispatched for that event type. | ||
|
||
As a read-only map, `EventCounts` is similar to a {{jsxref("Map")}}, however, it doesn't implement the `clear()`, `delete()`, and `set()` methods. | ||
|
||
## Constructor | ||
|
||
This interface has no constructor. You typically get an instance of this object using the {{domxref("performance.eventCounts")}} property. | ||
|
||
## Instance properties | ||
|
||
- `size` | ||
- : See {{jsxref("Map.prototype.size")}} for details. | ||
|
||
## Instance methods | ||
|
||
- `entries()` | ||
- : See {{jsxref("Map.prototype.entries()")}} for details. | ||
- `forEach()` | ||
- : See {{jsxref("Map.prototype.forEach()")}} for details. | ||
- `get()` | ||
- : See {{jsxref("Map.prototype.get()")}} for details. | ||
- `has()` | ||
- : See {{jsxref("Map.prototype.has()")}} for details. | ||
- `keys()` | ||
- : See {{jsxref("Map.prototype.keys()")}} for details. | ||
- `values()` | ||
- : See {{jsxref("Map.prototype.values()")}} for details. | ||
|
||
## Examples | ||
|
||
### Working with EventCount maps | ||
|
||
Below are a few examples to get information from an `EventCounts` map. Note that the map is read-only and the `clear()`, `delete()`, and `set()` methods aren't available. | ||
|
||
```js | ||
for (entry of performance.eventCounts.entries()) { | ||
const type = entry[0]; | ||
const count = entry[1]; | ||
} | ||
|
||
const clickCount = performance.eventCounts.get("click"); | ||
|
||
const isExposed = performance.eventCounts.has("mousemove"); | ||
const exposedEventsCount = performance.eventCounts.size; | ||
const exposedEventsList = [...performance.eventCounts.keys()]; | ||
``` | ||
|
||
## Specifications | ||
|
||
{{Specifications}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} | ||
|
||
## See also | ||
|
||
- {{domxref("performance.eventCounts")}} | ||
- {{domxref("PerformanceEventTiming")}} | ||
- {{jsxref("Map")}} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
--- | ||
title: Performance.eventCounts | ||
slug: Web/API/Performance/eventCounts | ||
page-type: web-api-instance-property | ||
browser-compat: api.Performance.eventCounts | ||
tags: | ||
- Property | ||
--- | ||
|
||
{{APIRef("Event Timing")}} | ||
|
||
The read-only `performance.eventCounts` property is an {{domxref("EventCounts")}} map containing the number of events which have been dispatched per event type. | ||
|
||
Not all event types are exposed. You can only get counts for event types supported by the {{domxref("PerformanceEventTiming")}} interface. | ||
|
||
## Value | ||
|
||
An {{domxref("EventCounts")}} map. | ||
(A read-only {{jsxref("Map")}} without the `clear()`, `delete()`, and `set()` methods). | ||
|
||
## Examples | ||
|
||
### Reporting event types and their counts | ||
|
||
If you like to send event counts to your analytics, you may want to implement a function like `sendToEventAnalytics` which takes the event counts from the `performance.eventCounts` map and then uses the [Fetch API](/en-US/docs/Web/API/Fetch_API) to post the data to your endpoint. | ||
|
||
```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 | ||
``` | ||
|
||
## Specifications | ||
|
||
{{Specifications}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} | ||
|
||
## See also | ||
|
||
- {{domxref("EventCounts")}} | ||
- {{domxref("PerformanceEventTiming")}} | ||
- {{jsxref("Map")}} |
This file contains 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