Skip to content

fix: try to improve analytics by reducing reporting delay on page load - #53

Merged
sburton84 merged 2 commits into
mainfrom
reduce-analytics-wait
Aug 21, 2026
Merged

fix: try to improve analytics by reducing reporting delay on page load#53
sburton84 merged 2 commits into
mainfrom
reduce-analytics-wait

Conversation

@sburton84

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 bootstrapGoogleAnalytics helper 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 useEffect delays.
  • Reduces Consent Mode wait_for_update to 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.

Comment thread documentation-ui/src/custom/docs/components/analytics/bootstrap.ts
Comment thread documentation-ui/src/custom/docs/components/analytics/consent-mode.ts Outdated
@sburton84
sburton84 merged commit 13b3a0a into main Aug 21, 2026
8 checks passed
@sburton84
sburton84 deleted the reduce-analytics-wait branch August 21, 2026 15:04
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

Successfully merging this pull request may close these issues.

2 participants