@glyphhq/nodeon the server — route handlers, server actions, and webhooks. Put payments, subscription changes, and other critical events here because delivery does not depend on a browser session.@glyphhq/browseron the client — in-product actions and page views that only exist client-side.
Environment variables
.env.local
glyph_test_... keys in development and glyph_pk_... in production. Create separate named keys for the server and browser. A browser key is publicly visible, so separation lets you rotate it without changing server deployments.
Server side
Create one shared client at module scope. Each server process gets one instance, allowing it to batch messages across requests:lib/glyph.ts
Route handlers and server actions
Serverless runtimes can freeze the moment a response is sent, so flush before returning:app/api/projects/route.ts
await glyph.flush(), return.
Use the Node.js runtime (the default) for routes that send to Glyph. If a route opts into another runtime, verify it supports the timer and
fetch APIs the SDK relies on before shipping.Webhooks
Billing webhooks are a reliable place to capture payment and subscription events:app/api/webhooks/stripe/route.ts
Profile on signup
Send the profile from the server when signup completes, such as in an auth callback or server action:Client side
Manage the singleton in a client component near the root and initialize it only for signed-in users. Glyph only tracks known customers. Reinitializing or resetting disposes the previous client, clears its queue, and removes its timer and browser listeners:components/glyph-provider.tsx
Page views
App Router navigation doesn’t reload the page, so track route changes withusePathname:
components/glyph-pageview.tsx
Checklist
- Separate server and browser keys set through
GLYPH_WRITE_KEYandNEXT_PUBLIC_GLYPH_WRITE_KEYin both.env.localand your deployment’s environment. - Shared
GlyphNodeinlib/glyph.ts, withonErrorlogging. await glyph.flush()before every response in route handlers, server actions, and webhooks.profilesent server-side at signup, withemail.- Client singleton initialized only for signed-in users;
reset()on logout. - Verified with a
glyph_test_...key in the test environment before switching production toglyph_pk_....