React Integration
Use Signal JS with React using the @signal-js/react package. It provides a provider, hooks, and components for session replay, event tracking, and user identity. The package includes the browser SDK automatically—you don’t need to install@signal-js/browser separately.
Quick start
1. InstallSignalProvider in your root (e.g. main.tsx or App.tsx). Pass options with your API key and project ID. The endpoint is optional and defaults to https://api.trysignal.ai/:
useSignalCapture() or useSignal():
useSignalIdentify(). See Identify for details.
Recording starts automatically when the provider mounts. For full setup (env vars, provider props), see Initialization.
When to use React integration
Use @signal-js/react when:- You’re building a React application (Create React App, Vite, Next.js client components, etc.)
- You want hooks-based API for better React integration
- You prefer automatic session management via a provider
- You want type-safe hooks with TypeScript
Features
- Session replay — rrweb-based session replay out of the box; configure masking via Configuration.
- Event tracking — Capture custom events with
useSignalCapture()oruseSignal(); events are batched and sent with session and identity context. - User identity — Identify users with
useSignalIdentify(); supportsidentify,distinctId, andreset(e.g. on logout). - User properties — Update user properties with
setPersonProperties()andsetPersonPropertiesOnce()viauseSignal(). - Groups — Associate users with groups (e.g. company, organization) via
useSignalGroup(). - Super properties — Register properties included with every event using
register(),registerOnce(), andunregister(). - Alias — Link aliases to users with
alias()to merge anonymous and identified events. - Page view tracking — Track page views on mount with
usePageView()or get a typed capture withuseTrackEvent()for SPAs. - Hooks-first API — All SDK access via React hooks; no need to pass the SDK down or import it in every file.
- Session and recording controls — Use
useSignal()forstartRecording,stopRecording,pauseRecording,resumeRecording,flush, and session info (useSignalSession()). - Opt-out support — Control user opt-out with
optOut(),optIn(), andhasOptedOut(). - Privacy masking — Use CSS classes (
signal-no-capture,signal-mask,signal-ignore-input) or Configuration options to mask sensitive UI in replays. - Network capture — Automatically capture fetch/XHR requests in session replays (configurable via Configuration).
- Console capture — Capture console logs, errors, and unhandled promise rejections in session replays.
Sub-pages
| Page | Description |
|---|---|
| Initialization | Install, Provider setup, provider props |
| Capture | Track custom events with useSignal, useSignalCapture |
| Identify | Identify users with useSignalIdentify |
| Set person properties | Update user properties with setPersonProperties, setPersonPropertiesOnce |
| Group | Associate users with groups with useSignalGroup |
| Super properties | Register properties included with every event (register, registerOnce, unregister) |
| Alias | Link aliases to users with signal.alias() |
| Recording control | Control recording with startRecording, stopRecording, pauseRecording, resumeRecording, flush |
| Opt-out | Control user opt-out with optOut, optIn, hasOptedOut |
| Page views | Track page views with usePageView, useTrackEvent |
| Configuration | SignalProvider and browser SDK options |
Available hooks
| Hook | Description |
|---|---|
useSignal() | Full SDK access: capture, identify, setPersonProperties, setPersonPropertiesOnce, group, register, registerOnce, unregister, alias, reset, optOut, optIn, hasOptedOut, recording controls, flush |
useSignalCapture() | Memoized function to capture events |
useSignalIdentify() | { identify, distinctId, reset } for user identity |
useSignalGroup() | { group, getGroups } for group association |
useSignalSession() | Session info: sessionId, windowId, sessionDuration, isRecording |
usePageView(pageName?, properties?) | Track pageview_<name>) on mount |
useTrackEvent(eventName) | Returns a typed capture function for that event |
withSignal(Component) | HOC that injects signal and isSignalInitialized |
Best practices
- Wrap your app with
SignalProviderat the root level — PlaceSignalProviderin your root component (e.g.main.tsx,App.tsx, or_app.tsx). - Use hooks instead of importing the SDK directly — Use hooks (
useSignal,useSignalCapture, etc.) instead of importing the SDK directly in components for better React integration. - Use environment variables — Store credentials (
endpoint,apiKey,projectId) in environment variables (e.g..env.localfor Create React App,.envfor Vite). - Track page views with
usePageView— UseusePageView()for automatic page view tracking on component mount in SPAs. - Identify users when they log in — Call
identify()fromuseSignalIdentify()when users log in to associate events with their identity. - Use sessionRecordingMasking for sensitive UI — Add CSS classes (
signal-no-capture,signal-mask,signal-ignore-input) or configure masking options inSignalProviderto protect sensitive data. - Use super properties for common attributes — Register properties that apply to all events (e.g. app version, environment) with
register()orregisterOnce(). - Handle opt-out for privacy compliance — Use
optOut(),optIn(), andhasOptedOut()to respect user privacy preferences (e.g. GDPR compliance). - Flush events before navigation — Call
flush()fromuseSignal()before page unload or navigation to ensure events are sent. - Use
useSignalSession()for session info — Access session information (sessionId,windowId,sessionDuration,isRecording) for debugging or conditional logic.
