Skip to content

feat: @hostess/browser insights core + Analytics/SpeedInsights components (#1, #2) - #4

Merged
immanuel-peter merged 2 commits into
mainfrom
nextjs-analytics
Jul 19, 2026
Merged

feat: @hostess/browser insights core + Analytics/SpeedInsights components (#1, #2)#4
immanuel-peter merged 2 commits into
mainfrom
nextjs-analytics

Conversation

@immanuel-peter

Copy link
Copy Markdown
Contributor

Summary

Implements the RUM client side of the analytics track:

Breaking change (0.2.0)

register/onRequestError move from the package root to the @hostess/nextjs/server subpath. One entry point can't serve both "use client" components and server-only OTel registration under the Pages Router (proven via next build). Migration:

-export { register, onRequestError } from "@hostess/nextjs";
+export { register, onRequestError } from "@hostess/nextjs/server";

Docs-site instrumentation snippets must be updated when this publishes.

Verified

  • pnpm build / typecheck / test green (27 tests).
  • End-to-end on the kind cluster via tarball installs in hostess tests/apps/test-app-26/web-helper: beacons flow through the generated /_hostess/rum ingress 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.tgz tarballs currently vendored in the test app.

Closes #1. Closes #2.

🤖 Generated with Claude Code

immanuel-peter and others added 2 commits July 19, 2026 03:03
)

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>
@cursor

cursor Bot commented Jul 19, 2026

Copy link
Copy Markdown

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.

@immanuel-peter
immanuel-peter merged commit 9d98c8a into main Jul 19, 2026
1 check passed
@immanuel-peter
immanuel-peter deleted the nextjs-analytics branch July 19, 2026 21:47

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment on lines +28 to +30
const appPathname = usePathname();
const appParams = useParams();
const isApp = appPathname != null;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

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.

Add <HostessAnalytics /> and <HostessSpeedInsights /> to @hostess/nextjs Add framework-agnostic browser insights core (@hostess/browser)

1 participant