Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLS event values sent to GA lose meaning due to rounding #3

Open
laradevitt opened this issue Jun 8, 2021 · 0 comments
Open

CLS event values sent to GA lose meaning due to rounding #3

laradevitt opened this issue Jun 8, 2021 · 0 comments

Comments

@laradevitt
Copy link

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.

laradevitt added a commit to laradevitt/gatsby-plugin-web-vitals that referenced this issue Jun 8, 2021
@laradevitt laradevitt changed the title CLS event values sent to GA aren't useful CLS event values sent to GA lose meaning due to rounding Jun 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant