Adding the script
The fastest way to add Userplane is the CDN embed. Add these two tags to the<head> of your root layout:
npm SDK
Use the npm SDK when you need programmatic control — triggering recordings from a button, attaching user metadata, or reading recording state.Installation
Initialization
Create a client component that initializes the SDK and mount it in your root layout.The
'use client' boundary is required because useEffect only runs in the browser. The dynamic
import() is a bundle-size optimization — a static import {initialize} from '@userplane/sdk' at
the top of the file also works since the SDK is SSR-safe.URL parameters
Next.js middleware and route guards may redirect users before the SDK reads theuserplane-token and userplane-action query parameters. If your app redirects unauthenticated users to a login page, preserve userplane- prefixed parameters through the redirect.
Add USERPLANE_URL_PARAMS to your middleware allowlist so those params survive the redirect:
Sensitive data
Adddata-userplane-blur to any element you want blurred in recordings. See Sensitive Data Redaction for the full reference.
Metadata
Callset() after initialize() to attach user context to recordings:
SSR
@userplane/sdk is SSR-safe to import — it does not reference window or document at module evaluation time. A static import at the top of a 'use client' file will not cause a server-side error.
The initialize() call must run client-side. Calling it inside useEffect (or a dynamic import()) guarantees it runs only in the browser.
Example app
A complete Next.js example is available at github.com/userplanehq/userplane-sdk-examples/tree/main/examples/nextjs.
Example app
Related articles
- Installation — CDN script placement, CSP, and redirect handling.
- Web SDK — full SDK API reference.
- Metadata SDK — attach user context to recordings.
- Sensitive Data Redaction — blur sensitive content in recordings.