feat: @hostess/browser insights core + Analytics/SpeedInsights components (#1, #2) - #4
Conversation
) Zero-config pageview and Core Web Vitals collection speaking beacon schema v1 (howl-cloud/hostess#32): inject() and injectSpeedInsights() batch beacons same-origin to /_hostess/rum via an observable-first transport (fetch keepalive probe, then sendBeacon steady-state) with hidden-flush for late-finalizing CLS/INP and backoff-and-stop on a disabled endpoint. Framework adapters plug in only through the RouteProvider seam; the default provider tracks history for bare SPAs. Privacy hard lines enforced: no cookies, no storage, no query strings, referrer origin only, silent in development. track() ships as a reserved no-op until phase 2. Analytics entry is 1.65 KB gz and tree-shakes free of web-vitals. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…y moves to /server (#2) <Analytics /> and <SpeedInsights /> are "use client" leaves over @hostess/browser whose real work is the Next-specific RouteProvider: App Router route templates reconstructed from usePathname()+useParams() (catch-all and encoded/slash param values included), Pages Router via the Router singleton, search-param navigations deduped, StrictMode-safe. BREAKING: the root entry is now the client components; instrumentation imports move to @hostess/nextjs/server. One entry cannot serve both — the Pages Router build resolves a single entry per pass and returns empty exports for a server module re-exporting "use client" components (verified with next build). The split is enforced by real example apps for both routers, built in CI. Bumps @hostess/nextjs to 0.2.0. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 012bf9b682
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const appPathname = usePathname(); | ||
| const appParams = useParams(); | ||
| const isApp = appPathname != null; |
There was a problem hiding this comment.
Detect the Pages Router without usePathname
usePathname() is also supported in the Pages Router and becomes non-null once its router is ready, so this condition changes a Pages Router mount into the App Router branch. In particular, Pages Router pathname is the route template (for example /blog/[slug]), so navigating between /blog/a and /blog/b leaves both appPathname and appRoute unchanged and the App Router effect never emits a page view; the Pages routeChangeComplete subscription is removed when isApp flips. This makes dynamic Pages Router navigations silently untracked despite the advertised support.
Useful? React with 👍 / 👎.
Summary
Implements the RUM client side of the analytics track:
@hostess/browser0.1.0 (Add framework-agnostic browser insights core (@hostess/browser) #1, new package): framework-agnostic insights core — beacon queue (flushes at 20 beacons or onvisibilitychange -> hidden), web-vitals collection (LCP/INP/CLS/FCP/TTFB), pageview tracking, coarsedeviceClass()from UA-CH with UA-string fallback, beacons disabled underNODE_ENV=development. Ships against beacon schema v1 (frozen in howl-cloud/hostess#32).@hostess/nextjs0.2.0 (Add <HostessAnalytics /> and <HostessSpeedInsights /> to @hostess/nextjs #2): adds<Analytics />and<SpeedInsights />client components (route-aware via App/Pages Router hooks) wrapping the browser core.Breaking change (0.2.0)
register/onRequestErrormove from the package root to the@hostess/nextjs/serversubpath. One entry point can't serve both"use client"components and server-only OTel registration under the Pages Router (proven vianext build). Migration:Docs-site instrumentation snippets must be updated when this publishes.
Verified
pnpm build/typecheck/testgreen (27 tests).tests/apps/test-app-26/web-helper: beacons flow through the generated/_hostess/rumingress route to rum-ingest, and Studio's Audience Analytics + Speed Insights tabs populate correctly (~1.1K synthetic page views; device/route splits match expectations; RES scoring and per-route sample floors behave as designed).Merging this unblocks installing from the repo instead of the
hostess-browser-0.1.0.tgz/hostess-nextjs-0.2.0.tgztarballs currently vendored in the test app.Closes #1. Closes #2.
🤖 Generated with Claude Code