adobe / theblog

Apache License 2.0
7 stars 14 forks source link

feat(cwv): improve CWV persistence #688

Closed kptdobe closed 3 years ago

kptdobe commented 3 years ago

Sending the data on visibility change is not optimal because the LCP and CLS events might be fired only on page unload, i.e. after the last visibility change - data are then missing, we can observe a lot of empty entries in the logs.

Only viable solution is to send the data when events are fired, which means multiple requests and then multiple log entries. To be able to reconcile the data, I added an id (url hash + timestamp + generated number, probability this is not unique is almost null).

I also added a "page view" entry so that we can observe if the CWV metrics are always persisted or not (might be cases where they are missing). We also get an estimate of the page views (unique ids * 100).

I also added support for ?cwv=on request parameter so that we can skip the weight computation (useful for testing).