fix: try to improve analytics by reducing reporting delay on page load - #53
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aims to reduce Google Analytics (GA4) reporting latency on page load by moving GA initialization earlier in the runtime (before React mounts) while still integrating with Google Consent Mode v2 and live consent updates.
Changes:
- Introduces a framework-agnostic
bootstrapGoogleAnalyticshelper that seeds consent defaults from stored cookie preferences and loads GA once. - Calls GA bootstrap synchronously in the Sphinx React injection entry point to avoid post-hydration
useEffectdelays. - Reduces Consent Mode
wait_for_updateto 100ms and updates/extends tests accordingly.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| sphinx-ui/react/src/injectNav.tsx | Bootstraps GA before mounting React to reduce first page_view delay. |
| documentation-ui/src/custom/docs/components/analytics/index.ts | Re-exports the new bootstrap helper from the analytics barrel. |
| documentation-ui/src/custom/docs/components/analytics/GoogleAnalyticsWithConsent.tsx | Delegates GA initialization to the new bootstrap helper; keeps consent updates in effect. |
| documentation-ui/src/custom/docs/components/analytics/GoogleAnalyticsWithConsent.test.tsx | Updates tests to mock/validate bootstrap behavior instead of direct GA load calls. |
| documentation-ui/src/custom/docs/components/analytics/consent-mode.ts | Adds hasGoogleAnalyticsScript helper and reduces wait_for_update. |
| documentation-ui/src/custom/docs/components/analytics/consent-mode.test.ts | Updates expected wait_for_update value in tests. |
| documentation-ui/src/custom/docs/components/analytics/bootstrap.ts | Adds the new bootstrap implementation (cookie-seeded consent default + GA load). |
| documentation-ui/src/custom/docs/components/analytics/bootstrap.test.ts | Adds unit tests covering bootstrap behavior and ordering guarantees. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
No description provided.