Skip to content

Conversation

cemms1
Copy link
Contributor

@cemms1 cemms1 commented Aug 29, 2025

What does this change?

Renames bypassSampling to recordMetrics as this better represents what this value means.

Introduces another value isInSample to replace willRecordCoreWebVitals since this is used for both commercial metrics and core web vitals, and represents whether the request is in the sample or not.

Additionally takes this value isInSample out of the bypassSampling decision seeing as these are two distinct things - in order to record metrics, you should either be in the sample or if not, the sampling should be bypassed in order to record all metrics

Why?

Making the code more easy to understand for future developers


const sampling = 1 / 100;
/** defining this here allows to share this with other metrics */
const willRecordCoreWebVitals = Math.random() < sampling;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used for both CWV and commercial metrics so better to have a value that covers both. Additionally, this is not the only reason the metrics might be recorded; this simply represents whether the page view is in the sample or not

if (isUndefined(pageViewId)) return;

const bypassSampling = shouldBypassSampling(abTestApi);
const recordMetrics = isInSample || shouldBypassSampling(abTestApi);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic determining whether metrics will be recorded is:

  • is the page view in the sample?
  • should the sampling be bypassed? ie should metrics be collected for all page views for a particular scenario?

Copy link

github-actions bot commented Oct 3, 2025

"This PR is stale because it has been open 30 days with no activity. Unless a comment is added or the “stale” label removed, this will be closed in 3 days"

@github-actions github-actions bot added the Stale label Oct 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant