Next.js Integration
Use Signal JS with Next.js using the @signal-js/nextjs package. It provides client components (SignalNextProvider, hooks) and server utilities (createSignalServer). You add a getSessionInfo() helper inlib/signal-server.ts (see Initialization) to read tracing headers for session correlation.
Quick start
- Install —
npm install @signal-js/nextjs - Client — Wrap your app with
SignalNextProviderin a client providers file and add it to your root layout. See Initialization. - Server — Create a shared
signalclient withcreateSignalServerand agetSessionInfo()helper inlib/signal-server.ts. See Initialization. - Track events — Use hooks on the client and
signal.capture()on the server with session identifiers. See Capture and Server tracking.
Sub-pages
| Page | Description |
|---|---|
| Initialization | Install, client provider, server setup, environment variables |
| Capture | Track events from client (hooks) and server (API routes, Server Actions) |
| Identify | Identify users on client and server |
| Set person properties | Update user properties with setPersonProperties, setPersonPropertiesOnce (client and server) |
| Group | Associate users with groups (client and server) |
| Super properties | Register properties included with every event (client only) |
| Alias | Link aliases to users (client and server) |
| Recording control | Control recording with startRecording, stopRecording, pauseRecording, resumeRecording, flush (client only) |
| Opt-out | Control user opt-out with optOut, optIn, hasOptedOut (client only) |
| Flush and shutdown | Flush queued events and graceful shutdown (server only) |
| Server tracking | API routes, Server Actions, Pages Router, getServerSideProps |
| Page views | Automatic and manual page view tracking |
| Configuration | SignalNextProvider and createSignalServer options |
Features
- App Router support — Full support for Next.js 13+ App Router
- Pages Router support — Compatible with Pages Router
- Server-side tracking — Track events from API routes and server actions
- Session correlation — Link client and server events using tracing headers
- Page view tracking — Automatic page view tracking on route changes
Best practices
- Use environment variables — Store credentials in
.env.local. - Use addTracingHeaders only when needed — Set in
optionsonly if you track server-side events and want correlation. - Track server events — Pass
sessionIdandwindowIdfrom request headers tosignal.capture()so events link to the same session replay. - Separate client/server configs — Use
NEXT_PUBLIC_prefix for client-side variables. - Use sessionRecordingMasking — Add
signal-no-capture,signal-mask, orsignal-ignore-inputclasses to sensitive UI.
