Skip to main content

Next.js — Initialization

Install the Next.js integration and set up both the client provider and the server SDK so you can track events from the browser and from API routes or Server Actions.

Installation

@signal-js/nextjs includes the browser SDK and the Node SDK. You do not need to install @signal-js/browser or @signal-js/node separately.

Client setup (App Router)

Create a client providers file and wrap your app with SignalNextProvider:
Wrap the root layout with your providers:

Server setup (App Router)

Create a shared server client and a helper to read tracing headers from requests:
Use signal and getSessionInfo in API routes, Server Actions, and (for Pages Router) in getServerSideProps and API route handlers.

Environment variables

Create .env.local:
Use NEXT_PUBLIC_ only for values needed in the browser. Keep server credentials without the prefix.

Next steps