Skip to main content

Next.js — Opt-out

Allow users to opt out of tracking. When opted out, no events are captured. Note: Opt-out is client-side only.

Client: useSignal

Get opt-out methods from useSignal():

optOut()

Disable tracking for the current user. No events will be captured while opted out. The opt-out preference is persisted in localStorage. When to use: When the user requests to disable tracking (e.g. privacy settings, GDPR compliance).

optIn()

Re-enable tracking for the current user. Events will be captured again. When to use: When the user requests to re-enable tracking.

hasOptedOut()

Check if the user has opted out. Returns boolean. When to use: To conditionally show UI or check tracking status.

Example: Privacy settings

Persistence

The opt-out preference is stored in localStorage with the key signal_opt_out. It persists across page reloads and browser sessions.

See also