mirror of
https://github.com/hanzoai/ui.git
synced 2026-11-20 20:07:34 +00:00
Removing Vercel analytics left the site posting to /v1/event with no
credential, and every batch came back 403 — telemetry replaced with
telemetry that ingests nothing.
The door does not trust the request Host on purpose, because a Host
header is spoofable, so a static page proves its org by carrying a
publishable key. pk_ keys are write-only and HMAC-verified with no
database hop, which is what makes one safe inside a public bundle. The
build supplies it, so each deployment reports as the org that built it,
and a build without one stays inert instead of posting rejects.
Verified against prod: POST /v1/event with a pk_ returns
{"accepted":1,"dropped":0} on both the header and beacon paths.
19 lines
1017 B
TypeScript
19 lines
1017 B
TypeScript
import { createAnalytics } from "@hanzo/event"
|
|
|
|
// One client for the whole site. Pageviews (components/analytics.tsx) and
|
|
// product events (lib/events.ts) share it, so there is a single place that
|
|
// knows where telemetry goes — call sites only name what happened. Host
|
|
// defaults to the one edge (api.hanzo.ai), which is what a static site wants.
|
|
//
|
|
// /v1/event is authed, and deliberately does not trust the request Host — a Host
|
|
// header is spoofable, so a static page proves which org it belongs to by
|
|
// carrying a publishable key. `pk_` keys are write-only and HMAC-verified with no
|
|
// database hop, which is what makes them safe to ship inside a public bundle (the
|
|
// same reason a Sentry DSN is public). The build supplies it, so each deployment
|
|
// reports as the org that deployed it; without one the client stays inert rather
|
|
// than posting events that would only be rejected.
|
|
export const analytics = createAnalytics({
|
|
product: "site",
|
|
ingestKey: process.env.NEXT_PUBLIC_HANZO_INGEST_KEY,
|
|
})
|