feat(web-vitals): restrict reporting to production, make endpoint configurable#582
Merged
Merged
Conversation
…configurable Guard all Core Web Vitals reporting behind NODE_ENV === 'production' so local development and test runs never send outbound requests to the analytics pipeline. Replace the hardcoded /api/v1/analytics/events URL with NEXT_PUBLIC_ANALYTICS_ENDPOINT so the destination is externally configurable per environment. In non-production environments a console.warn is emitted when the endpoint env var is absent, making the disabled state explicit rather than silent. In production a missing endpoint is handled gracefully (silent skip) and network failures continue to be swallowed so analytics never affects user-facing stability.
|
@Petah1 is attempting to deploy a commit to the paul joseph's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@Petah1 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #556
Summary
Production-only reporting — all Core Web Vitals reporting is now guarded behind
process.env.NODE_ENV === 'production'. InWebVitalsInit.tsxtheuseEffectreturns early in non-production environments so noweb-vitalslisteners are registered and no visibility-change handler is attached. InwebVitalsReporter.tstheshipfunction has the same guard as a defence-in-depth measure, ensuring the reporter never makes outbound requests even if it is called directly outside of the component.Configurable analytics endpoint — the hardcoded
/api/v1/analytics/eventsURL has been replaced withprocess.env.NEXT_PUBLIC_ANALYTICS_ENDPOINT. ThecreateWebVitalsReporterfactory resolves the endpoint in priority order:options.endpoint(for tests/overrides) →NEXT_PUBLIC_ANALYTICS_ENDPOINT→ empty string. The explicitoptions.endpointescape-hatch keeps existing unit tests working without env-var changes.Clear dev warning — when
NODE_ENV !== 'production'andNEXT_PUBLIC_ANALYTICS_ENDPOINTis not set,WebVitalsInitemitsconsole.warn('[WebVitals] Core Web Vitals reporting is disabled: NEXT_PUBLIC_ANALYTICS_ENDPOINT is not set.')so the absence of reporting is explicit rather than silent.Graceful production degradation — if
NEXT_PUBLIC_ANALYTICS_ENDPOINTis missing or empty in a production build,shipskips the fetch without throwing. Network failures continue to be caught and silently discarded, so analytics outages never surface as user-visible errors.Files changed
frontend/src/lib/webVitalsReporter.tsIS_PRODUCTIONconstant; swapped hardcoded URL forNEXT_PUBLIC_ANALYTICS_ENDPOINT; added production guard and empty-endpoint guard inshipfrontend/src/components/providers/WebVitalsInit.tsxconsole.warnat the top ofuseEffect; registration block only runs in productionBehaviour matrix
NEXT_PUBLIC_ANALYTICS_ENDPOINTset?console.warnemitted; no listeners registered; no network callsconsole.warnnot emitted; still no listeners registered; no network callsshipskips silently; no network call, no errorTest plan
npm run dev) withNEXT_PUBLIC_ANALYTICS_ENDPOINTunset — confirmconsole.warnappears in the browser console and no outbound requests are made to any analytics URLNEXT_PUBLIC_ANALYTICS_ENDPOINT=http://localhost:9999/testset — confirm the warning is absent and still no network requests are made (non-production guard holds)webVitalsReporterunit tests — confirm they pass (tests passoptions.endpointexplicitly so env-var default is bypassed)NODE_ENV=production) withNEXT_PUBLIC_ANALYTICS_ENDPOINTset — confirm metrics reach the endpointNEXT_PUBLIC_ANALYTICS_ENDPOINT— confirm no unhandled errors and no network calls