By default, an app generated from enact create with Enact CLI includes a performance relayer that allows you to measure and analyze
the performance of your application using different metrics.
To measure any of the supported metrics, you only need to pass a function into the reportWebVitals
function in index.js:
reportWebVitals(console.log);
This function is fired when the final values for any of the metrics have finished calculating on the
page. You can use it to log any of the results to the console or send to a particular endpoint.
Web Vitals are a set of useful metrics that aim to capture the user
experience of a web page. In Create React App, a third-party library is used to measure these
metrics (web-vitals).
To understand more about the object returned to the function when a metric value is calculated,
refer to the documentation. The Browser
Support section also explains which browsers are supported.
With the reportWebVitals function, you can send any of results to an analytics endpoint to measure and track real user performance on your site. For example:
functionsendToAnalytics(metric) {
const body = JSON.stringify(metric);
const url = 'https://example.com/analytics';
// Use `navigator.sendBeacon()` if available, falling back to `fetch()`