gatsby-plugin-web-vitals
gatsby-plugin-web-vitals copied to clipboard
CLS event values sent to GA lose meaning due to rounding
This plugin converts all of the event values to integers before sending to GA, here:
// Google Analytics metrics must be integers, so the value is rounded.
ev: parseInt(delta),
Considering the key range for the CLS metric is 0 to 0.25 (with anything above that being "Poor"), the rounded values are meaningless.
The documentation for web-vitals suggests multiplying the value by 1000, or a larger multiplier for greater precision.
// Google Analytics metrics must be integers, so the value is rounded.
// For CLS the value is first multiplied by 1000 for greater precision
// (note: increase the multiplier for greater precision if needed).
eventValue: Math.round(name === 'CLS' ? delta * 1000 : delta),
Without the multiplier, 0.22145
is 0
. With the multiplier, it is 221
, which will be resolved as 0.221
by dividing the value by 1000 in our reports.
I'll submit a pull request shortly.