Skip to content

feat: privacy-first analytics swap and legal page rewrite#566

Merged
berry-13 merged 3 commits into
mainfrom
privacy-analytics-overhaul
Apr 26, 2026
Merged

feat: privacy-first analytics swap and legal page rewrite#566
berry-13 merged 3 commits into
mainfrom
privacy-analytics-overhaul

Conversation

@berry-13
Copy link
Copy Markdown
Member

@berry-13 berry-13 commented Apr 26, 2026

Summary

  • Replace Vercel telemetry (@vercel/analytics + @vercel/speed-insights) with a self-hosted, cookieless analytics stack: Plausible at plausible.librechat.ai plus a React 18-compatible Core Web Vitals collector powered by web-vitals.
  • Rewrite /tos, /privacy, and /cookie so the public legal pages accurately disclose Plausible, Core Web Vitals, Scarf, local browser storage, operational logs, and no-cookie/no-banner posture.
  • Migrate TrackedLink custom events (card_click, link_click) from Vercel track() to window.plausible(...).
  • Merge the latest origin/main and preserve the new OPENROUTER_API_KEY gate for AskAILoader.

Analytics changes

Removed

  • @vercel/analytics package, imports, <Analytics />, and track() calls.
  • @vercel/speed-insights package, imports, and <SpeedInsights />.
  • next-cwv-monitor after review found the published App Router bundle imports React.use, which is unavailable in the repo's current react@18.3.1.

Added

  • Plausible script in app/layout.tsx using the actual hosted script:
    <script async src="https://plausible.librechat.ai/js/pa-AxQn4zbc0KTWDDkxjlFGs.js"></script>
  • Inline Plausible bootstrap/init matching the provided snippet.
  • components/analytics/CoreWebVitalsMonitor.ts, a small App Router client collector that:
    • uses web-vitals directly for LCP, INP, CLS, FCP, and TTFB;
    • emits payloads compatible with the next-cwv-monitor /api/ingest contract;
    • rotates in-memory session IDs on every page navigation;
    • never writes cookies, localStorage, or sessionStorage;
    • samples metric events with NEXT_PUBLIC_CWV_SAMPLE_RATE while always sending $page_view events when enabled.

Configuration

  • NEXT_PUBLIC_CWV_PROJECT_ID defaults/documented as 64ddab45-756f-474b-a8c9-266d264c93d8.
  • NEXT_PUBLIC_CWV_SAMPLE_RATE defaults/documented as 0.5.
  • NEXT_PUBLIC_CWV_ENDPOINT is intentionally required before CWV renders; the current site does not serve /api/ingest, so this avoids noisy 404s until the self-hosted CWV backend endpoint is provisioned.

Privacy posture

  • No cookies. Plausible, CWV monitoring, and Scarf disclosures all state that no cookies or persistent client identifiers are used.
  • Plausible visitor de-dup is disclosed as transient IP/User-Agent processing with no retained IP address.
  • CWV monitoring is disclosed as route/path + Web Vitals metrics with a per-navigation in-memory session ID.
  • Local browser storage disclosure is limited to non-identifying usability state such as theme and documentation navigation state.
  • Privacy wording now avoids overclaiming "no personal data" where transient server logs or request metadata may exist under GDPR definitions.

Legal pages

Three full rewrites at the docs site root:

  • /privacy — 17 sections covering controller/contact, Plausible, CWV, Scarf, server logs, lawful basis, retention, sub-processors, user rights, browser controls, local storage, children's privacy, security, external links, OSS transparency, and contact.
  • /cookie — 8 sections covering no cookies, cookieless analytics, CWV monitoring, local browser storage, third-party links/content, browser controls, changes, and contact.
  • /tos — 18 sections covering site scope, demo/app separation, open-source licensing, acceptable use, privacy incorporation, third-party links, user contributions, IP, warranty/liability, indemnification, availability, governing-law fallback, severability, and contact.

Footer label fix: "Terms of services" → "Terms of Service" in components/FooterMenu.tsx.

Verification

  • eslint --no-cache app/layout.tsx components/analytics/CoreWebVitalsMonitor.ts components/TrackedLink.tsx app/privacy/page.tsx app/cookie/page.tsx app/tos/page.tsx
  • tsc --noEmit --pretty false
  • pnpm build
  • git diff --check origin/main...HEAD
  • Verified the Plausible script URL returns 200 application/javascript.
  • Checked the live /api/ingest route and kept CWV endpoint-gated because it is not currently served by this app.

Test plan

  • Confirm branch builds after merging latest origin/main.
  • Confirm no remaining source references to Vercel Analytics/Speed Insights or next-cwv-monitor.
  • Confirm policy/cookie/TOS pages disclose the actual analytics implementation and no-cookie posture.
  • Set NEXT_PUBLIC_CWV_ENDPOINT in production to the deployed self-hosted CWV backend and confirm Web Vitals events appear.
  • Verify the Plausible dashboard receives page views from plausible.librechat.ai after deploy.
  • Click a TrackedLink card and outbound link after deploy and confirm card_click / link_click events appear in Plausible.

- Remove @vercel/analytics and @vercel/speed-insights entirely
- Add self-hosted Plausible (analytics.librechat.ai) using the
  outbound-links + tagged-events + hash combined script variant
- Add env-gated next-cwv-monitor for Core Web Vitals (LCP, INP,
  CLS, FCP, TTFB), driven by NEXT_PUBLIC_CWV_PROJECT_ID and
  NEXT_PUBLIC_CWV_ENDPOINT, with optional NEXT_PUBLIC_CWV_SAMPLE_RATE
- Migrate TrackedLink card_click and link_click events from
  Vercel track() to window.plausible(...) with a Window.plausible
  global declaration; outbound-link auto-tracking complements them
- Rewrite /tos, /privacy, /cookie as enterprise-grade, GDPR/CCPA
  aware policies that accurately disclose the new cookieless
  analytics stack, lawful basis, retention, sub-processors, and
  data-subject rights; the site remains banner-free under
  ePrivacy 5(3) since no terminal-equipment storage is used
- Fix footer label: "Terms of services" -> "Terms of Service"
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
librechat-ai Ready Ready Preview, Comment Apr 26, 2026 5:34pm

Request Review

@berry-13 berry-13 marked this pull request as draft April 26, 2026 02:26
@github-actions
Copy link
Copy Markdown

📦 Next.js Bundle Analysis for librechat.ai

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

@berry-13 berry-13 marked this pull request as ready for review April 26, 2026 17:35
@berry-13 berry-13 merged commit 257c309 into main Apr 26, 2026
3 checks passed
@berry-13 berry-13 deleted the privacy-analytics-overhaul branch April 26, 2026 19:09
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.

1 participant