Next.js — Server tracking
Track events from the server so they appear in the same session as client events. Use your sharedsignal client and pass sessionId and windowId from request headers into every signal.capture() or signal.identify() call.
App Router: API routes
UsegetSessionInfo(request) with the route’s Request:
App Router: Server Actions
Read headers withheaders() from next/headers and pass the same identifiers:
Pages Router: API routes
Usereq.headers and a small helper:
Pages Router: getServerSideProps
Read headers fromcontext.req and pass them into signal.capture():
Enabling tracing headers on the client
For the server to receivex-signal-session-id, x-signal-window-id, and x-signal-distinct-id, the client must send them. Set addTracingHeaders: true (or an array of hostnames) in your SignalNextProvider options when you use server-side tracking. See Configuration.
Advanced server helpers
The server package also exports:- trackServerEvent(options) — Convenience that uses the singleton from
createSignalServerto capture one event (e.g. in a one-off handler). Options:distinctId,event,properties. - getSignalServerSideProps(getServerSidePropsFunc, options) — Wraps your
getServerSidePropsto inject Signal props (e.g.distinctId,sessionId) fromgetDistinctId/getSessionIdcallbacks. Use when you want Signal context in page props. - withSignalConfig(nextConfig) — Wraps your Next.js config to inject Signal env vars (
NEXT_PUBLIC_SIGNAL_ENDPOINT,NEXT_PUBLIC_SIGNAL_PROJECT_ID). Use if you prefer config over.env.local.
See also
- Capture — capture() options
- Initialization — lib/signal-server setup
