useConsentManager
useConsentManager() is the primary hook for interacting with the consent system. It returns the complete consent store state and all action methods.
Warning
Must be used within a ConsentManagerProvider. Throws an error if used outside the provider.
State Properties
Warning: ExtractedTypeTable: Could not extract "StoreRuntimeState" from "./packages/core/src/store/type.ts" using base path "/vercel/path0/apps/c15t-docs/.leadtype/c15t". Verify the path/name and that the file is included by your tsconfig.
Action Methods
Warning: ExtractedTypeTable: Could not extract "StoreActions" from "./packages/core/src/store/type.ts" using base path "/vercel/path0/apps/c15t-docs/.leadtype/c15t". Verify the path/name and that the file is included by your tsconfig.
User Identification
You can link a consent subject to your own internal user ID or a non-secret anonymous visitor ID. c15t stores the identifier in the subject row's externalId field. Consent records remain associated with that subject through subjectId, so your backend can find the subject and its related consent records by external ID for GDPR Article 15 exports.
1. Providing the Current User ID
When using Clerk, prefer the Clerk userId whenever the visitor is signed in. Before sign-in, you can fall back to a non-secret visitor ID stored in a first-party cookie:
Warning
ConsentManagerProvider runs on the client. Values passed through
options.user are therefore available to client-side JavaScript, even when
they were read from an HttpOnly cookie on the server. Pass only a non-secret
identifier, such as a Clerk userId or an opaque visitor ID. Never pass a
Clerk session token or a value returned by getToken().
Info
Clerk's auth() helper requires clerkMiddleware() to be configured. This
example also uses the asynchronous cookies() API from Next.js 15+. For
Next.js 14 and earlier, use const cookieStore = cookies(); without
await. Keep the layout asynchronous because Clerk's auth() is
asynchronous.
2. Synchronizing Clerk Sign-ins
Clerk can complete a sign-in without reloading the page. Add a client component inside ConsentManagerProvider to update the current consent subject as soon as Clerk exposes the authenticated userId:
identifyUser() replaces the subject's current externalId; it does not retain the anonymous ID as an alias. Once a visitor is linked to Clerk, stop supplying the former visitor ID. The example clears its client-readable cookie only after identifyUser() succeeds so a later render cannot change the subject back to the anonymous ID.
Info
Backend subject identification requires hosted mode (mode: 'hosted'). In
offline mode, identifyUser() cannot update a backend subject. Identifiers
supplied through options.user can still be held in client state and
persisted with locally stored consent, so do not place sensitive values
there.
Key Types
ConsentState
ConsentStateA record mapping consent category names to their boolean values:
ConsentInfo
ConsentInfoMetadata about when and how consent was recorded:
LocationInfo
LocationInfoDetected geographic location from the c15t backend:
Model
ModelThe active consent model:
'opt-in'— Explicit consent required before tracking (GDPR)'opt-out'— Tracking allowed by default, user can opt out (CCPA)'iab'— IAB TCF 2.3 compliance modenull— No jurisdiction detected yet