diff --git a/sdk/consent.mdx b/sdk/consent.mdx index cb89492..7700e0a 100644 --- a/sdk/consent.mdx +++ b/sdk/consent.mdx @@ -1,35 +1,65 @@ --- title: "Consent" -description: "Connect capture categories to your app’s privacy choices." +description: "Set browser capture permissions before startup and update them when visitors choose." icon: "/icons/ui/shield.svg" --- -For Next.js, Vite + React, and TanStack Start, configure browser consent on `InterfereProvider`. These settings do not control server telemetry. If you omit the `consent` prop, all categories are allowed. +For Next.js, Vite + React, and TanStack Start, consent controls browser analytics and replay. These settings do not control server telemetry. -## Set the initial choice +Without a `consent` option, the SDK runs with its configured defaults. To wait for a visitor's choice before starting analytics or replay, pass `false` to `init()`: -Pass consent from the provider's first render. With the object below, analytics and replay stay disabled while error and log capture remain active. +```ts instrumentation-client.ts +import { init } from "@interfere/next/instrumentation-client"; -```tsx -{children} +await init({ consent: false }); ``` -| Category | Capture | Behavior | -| ----------- | ------------------------------------------------ | --------------------- | -| `necessary` | Errors and logs | Always on | -| `analytics` | Page events, rage clicks, and device information | Controlled by consent | -| `replay` | Session recording | Controlled by consent | +For Vite + React and TanStack Start, import `init` from `@interfere/vite/init` in the browser entry point. + +Set this before React renders. Passing consent only to the provider leaves a gap between initialization and the first render. + +Consent describes what the visitor allows **right now**. The same values work in `init()`, the provider's `consent` prop, and `consent.set()`: + +| Value | What it allows | +| ------------------------------------ | ---------------------------- | +| `false` | Neither analytics nor replay | +| `true` | Both analytics and replay | +| `{ analytics: true, replay: false }` | Analytics only | + +| Category | What it covers | +| ----------- | ------------------------------------- | +| `analytics` | Page events, rage clicks, device info | +| `replay` | Session replay | ## Update consent -Map the choices from your consent manager to these categories. You can update the provider prop or call `consent.set()` from a component inside the provider. +Import `useInterfere` from `@interfere/next/provider` or `@interfere/vite/provider`. Update the decision when the visitor accepts, declines, or changes their preferences: ```tsx const { consent } = useInterfere(); +consent.set(true); +``` + +Use `consent.set(false)` to withdraw both permissions, or pass an object for separate choices: + +```tsx consent.set({ analytics: true, replay: false }); ``` -Import `useInterfere` from `@interfere/next/provider` or `@interfere/vite/provider`. Calling `consent.set()` without arguments grants all categories. +Each update replaces the previous decision. Omitted categories are allowed, so include both booleans when mapping choices from a consent platform such as c15t, CookieYes, or OneTrust. + +You can also keep the decision synchronized through the provider: + +```tsx +{children} +``` + +Omitting the provider's `consent` prop preserves the decision supplied to `init()` or updated at runtime. Calling `consent.set()` without a value removes consent restrictions; it does not record the visitor's acceptance. + + + Consent controls analytics and replay. It does not disable errors, logs, tracing, or session + storage, and granting consent does not enable plugins disabled in configuration. + -To disable a capture feature regardless of consent, use the provider's [plugin configuration](/sdk/configuration#capture-features). Configure [masking](/sdk/replay-privacy) separately for content that must not appear in recordings. +Configure [masking](/sdk/replay-privacy) separately for content that must not appear in recordings.