---
title: useConsentManager
description: The primary hook for accessing consent state and actions. Returns the full consent store including all state properties and action methods.
---
`useConsentManager()` is the primary hook for interacting with the consent system. It returns the complete consent store state and all action methods.

```tsx
import { useConsentManager } from '@c15t/nextjs';

function MyComponent() {
  const {
    consents,
    model,
    has,
    saveConsents,
    // ... all state and actions
  } = useConsentManager();
}
```

> ℹ️ **Info:**
> Must be used within a ConsentManagerProvider. Throws an error if used outside the provider.

## State Properties

| Property                    | Type                     | Description                                                                                                                                                                                                                                                                                                                                                       | Default |  Required  |
| :-------------------------- | :----------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------ | :--------: |
| branding                    | Branding                 | Whether to show the branding. "consent" is a deprecated alias for "inth".                                                                                                                                                                                                                                                                                         | -       | ✅ Required |
| consents                    | ConsentState             | Current consent states for all consent types                                                                                                                                                                                                                                                                                                                      | -       | ✅ Required |
| selectedConsents            | ConsentState             | Selected consents (Not Saved) - use saveConsents to save                                                                                                                                                                                                                                                                                                          | -       | ✅ Required |
| consentInfo                 | ConsentInfo \| null      | Information about when and how consent was given                                                                                                                                                                                                                                                                                                                  | -       | ✅ Required |
| activeUI                    | ActiveUI                 | Which consent UI component is currently visible.                                                                                                                                                                                                                                                                                                                  | -       | ✅ Required |
| isLoadingConsentInfo        | boolean                  | Whether consent banner information is currently being loaded                                                                                                                                                                                                                                                                                                      | -       | ✅ Required |
| hasFetchedBanner            | boolean                  | Whether consent banner information has been successfully fetched                                                                                                                                                                                                                                                                                                  | -       | ✅ Required |
| lastBannerFetchData         | any                      | Last consent banner fetch data for callback replay                                                                                                                                                                                                                                                                                                                | -       | ✅ Required |
| debug                       | boolean                  | Whether debug logging is enabled                                                                                                                                                                                                                                                                                                                                  | -       | ✅ Required |
| consentCategories           | AllConsentNames\[]       | Active consent categories                                                                                                                                                                                                                                                                                                                                         | -       | ✅ Required |
| locationInfo                | LocationInfo \| null     | Subject's location information                                                                                                                                                                                                                                                                                                                                    | -       | ✅ Required |
| includeNonDisplayedConsents | boolean                  | Whether to include non-displayed consents in operations                                                                                                                                                                                                                                                                                                           | -       | ✅ Required |
| consentTypes                | ConsentType\[]           | Available consent type configurations                                                                                                                                                                                                                                                                                                                             | -       | ✅ Required |
| iframeBlockerConfig         | IframeBlockerConfig      | Configuration for the iframe blocker                                                                                                                                                                                                                                                                                                                              | -       | ✅ Required |
| loadedScripts               | Record\<string, boolean> | Map of currently loaded script IDs to a boolean loaded-state                                                                                                                                                                                                                                                                                                      | -       | ✅ Required |
| scriptIdMap                 | Record\<string, string>  | Map of anonymized script IDs to their original IDs                                                                                                                                                                                                                                                                                                                | -       | ✅ Required |
| model                       | Model                    | What type of consent model to use for the consent manager.&#xA;&#xA;- 'opt-in' - Requires explicit consent before non-essential cookies or tracking. (GDPR Style)&#xA;- 'opt-out' - Allows processing until the user exercises a right to opt out. (CCPA Style)&#xA;- 'iab' - IAB TCF 2.3 mode for programmatic advertising compliance. (GDPR jurisdictions only) | -       | ✅ Required |
| policyBanner                | PolicySurfaceState       | Policy-driven UI hints for the consent banner surface.                                                                                                                                                                                                                                                                                                            | -       | ✅ Required |
| policyDialog                | PolicySurfaceState       | Policy-driven UI hints for the consent dialog surface.                                                                                                                                                                                                                                                                                                            | -       | ✅ Required |
| policyCategories            | string\[] \| null        | Active runtime policy category scope from \`/init\`.                                                                                                                                                                                                                                                                                                              | -       | ✅ Required |
| policyScopeMode             | any                      | Runtime policy scope mode from \`/init\`.&#xA;Controls whether out-of-scope categories are treated as permissive at runtime.                                                                                                                                                                                                                                      | -       | ✅ Required |
| initDataSource              | InitDataSource \| null   | Source that provided the most recent \`/init\` payload used to hydrate runtime state.                                                                                                                                                                                                                                                                             | -       | ✅ Required |
| initDataSourceDetail        | string \| null           | Optional source detail for diagnostics (for example, cache header values).                                                                                                                                                                                                                                                                                        | -       | ✅ Required |
| iab                         | IABManager \| null       | IAB TCF 2.3 state and actions (null when not configured or not in IAB mode).                                                                                                                                                                                                                                                                                      | -       | ✅ Required |
| reloadOnConsentRevoked      | boolean                  | Whether to reload the page when consent is revoked.                                                                                                                                                                                                                                                                                                               | -       | ✅ Required |
| ssrDataUsed                 | boolean                  | Whether SSR data was successfully used for initialization.                                                                                                                                                                                                                                                                                                        | -       | ✅ Required |
| ssrSkippedReason            | SSRSkippedReason         | Reason SSR data was skipped, if applicable.                                                                                                                                                                                                                                                                                                                       | -       | ✅ Required |

## Action Methods

| Property                      | Type                                                                                                                                                                                           | Description                                                                                                                                                 | Default |  Required  |
| :---------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------- | :------ | :--------: |
| setTranslationConfig          | (config: TranslationConfig) => void                                                                                                                                                            | Updates the translation configuration.                                                                                                                      | -       | ✅ Required |
| setOverrides                  | (overrides: Overrides \| undefined) => Promise\<any>                                                                                                                                           | Sets the overrides for the consent manager.&#xA;&#xA;Automatically attempts to fetch the consent manager again with the new overrides.                      | -       | ✅ Required |
| setLanguage                   | (language: string) => Promise\<any>                                                                                                                                                            | Set the language override for the consent manager. This will override the language detected from the browser and re-fetch the consent banner information.   | -       | ✅ Required |
| identifyUser                  | (user: User) => Promise\<void>                                                                                                                                                                 | Identifies the user by setting the external ID.                                                                                                             | -       | ✅ Required |
| unstable\_acceptPolicyConsent | (input: UnstablePolicyConsentInput) => Promise\<PostSubjectOutput>                                                                                                                             | Writes a policy-based consent such as terms and conditions.                                                                                                 | -       | ✅ Required |
| setSelectedConsent            | (name: AllConsentNames, value: boolean) => void                                                                                                                                                | Updates the selected consent state for a specific consent type.                                                                                             | -       | ✅ Required |
| saveConsents                  | (type: "necessary" \| "custom" \| "all", options?: \{ uiSource?: string \| undefined; } \| undefined) => Promise\<void>                                                                        | Saves the user's consent preferences.                                                                                                                       | -       | ✅ Required |
| setConsent                    | (name: AllConsentNames, value: boolean) => void                                                                                                                                                | Updates the consent state for a specific consent type & automatically save the consent.                                                                     | -       | ✅ Required |
| resetConsents                 | () => void                                                                                                                                                                                     | Resets all consent preferences to their default values                                                                                                      | -       | ✅ Required |
| setActiveUI                   | (ui: ActiveUI, options?: \{ force?: boolean \| undefined; } \| undefined) => void                                                                                                              | Sets the active consent UI component.                                                                                                                       | -       | ✅ Required |
| setConsentCategories          | (types: AllConsentNames\[]) => void                                                                                                                                                            | Updates the active GDPR consent types.                                                                                                                      | -       | ✅ Required |
| setCallback                   | (name: keyof Callbacks, callback: Callback\<OnBannerFetchedPayload> \| Callback\<OnConsentSetPayload> \| Callback\<OnConsentChangedPayload> \| Callback\<OnErrorPayload> \| undefined) => void | Sets a callback for a specific consent event.                                                                                                               | -       | ✅ Required |
| subscribeToConsentChanges     | (listener: (payload: OnConsentChangedPayload) => void) => () => void                                                                                                                           | Subscribes to change-only consent saves.                                                                                                                    | -       | ✅ Required |
| setLocationInfo               | (location: LocationInfo \| null) => void                                                                                                                                                       | Updates the user's location information.                                                                                                                    | -       | ✅ Required |
| initConsentManager            | () => Promise\<any>                                                                                                                                                                            | Initializes the consent manager by fetching jurisdiction, location, translations, and branding information.                                                 | -       | ✅ Required |
| getDisplayedConsents          | () => ConsentType\[]                                                                                                                                                                           | Retrieves the list of consent types that should be displayed                                                                                                | -       | ✅ Required |
| hasConsented                  | () => boolean                                                                                                                                                                                  | Checks if the user has provided any form of consent                                                                                                         | -       | ✅ Required |
| has                           | \<CategoryType extends AllConsentNames>(condition: HasCondition\<CategoryType>) => boolean                                                                                                     | Evaluates whether current consent state satisfies the given condition.                                                                                      | -       | ✅ Required |
| setScripts                    | (scripts: Script\[]) => void                                                                                                                                                                   | Sets multiple script configurations to the store.                                                                                                           | -       | ✅ Required |
| removeScript                  | (scriptId: string) => void                                                                                                                                                                     | Removes a script configuration from the store.                                                                                                              | -       | ✅ Required |
| updateScripts                 | () => \{ loaded: string\[]; unloaded: string\[]; }                                                                                                                                             | Updates scripts based on current consent state.&#xA;Loads scripts that have consent and aren't loaded yet.&#xA;Unloads scripts that no longer have consent. | -       | ✅ Required |
| isScriptLoaded                | (scriptId: string) => boolean                                                                                                                                                                  | Checks if a script is currently loaded.                                                                                                                     | -       | ✅ Required |
| getLoadedScriptIds            | () => string\[]                                                                                                                                                                                | Gets all currently loaded script IDs.                                                                                                                       | -       | ✅ Required |
| initializeIframeBlocker       | () => void                                                                                                                                                                                     | Initializes the iframe blocker instance.                                                                                                                    | -       | ✅ Required |
| updateIframeConsents          | () => void                                                                                                                                                                                     | Updates the active consents used by the iframe blocker.                                                                                                     | -       | ✅ Required |
| destroyIframeBlocker          | () => void                                                                                                                                                                                     | Destroys the iframe blocker instance and cleans up resources.                                                                                               | -       | ✅ Required |
| initializeNetworkBlocker      | () => void                                                                                                                                                                                     | Initializes the network blocker instance.                                                                                                                   | -       | ✅ Required |
| updateNetworkBlockerConsents  | () => void                                                                                                                                                                                     | Updates the consent snapshot used by the network blocker.                                                                                                   | -       | ✅ Required |
| setNetworkBlocker             | (config: NetworkBlockerConfig \| undefined) => void                                                                                                                                            | Updates the network blocker configuration at runtime.                                                                                                       | -       | ✅ Required |
| destroyNetworkBlocker         | () => void                                                                                                                                                                                     | Destroys the network blocker instance and cleans up resources.                                                                                              | -       | ✅ Required |
| updateConsentCategories       | (newCategories: AllConsentNames\[]) => void                                                                                                                                                    | Extends the active GDPR consent categories with any categories used by&#xA;configured scripts.                                                              | -       | ✅ Required |

## identifyUser

The `identifyUser()` method links anonymous consent records to an authenticated user. Call it after a user logs in to associate their consent preferences with their account.

```tsx
import { useConsentManager } from '@c15t/nextjs';

function LoginForm() {
  const { identifyUser } = useConsentManager();

  async function handleLogin(email: string) {
    // ... your login logic
    const user = await api.login(email);

    // Link consent to the authenticated user
    await identifyUser({
      id: user.id,
      identityProvider: 'your-auth-provider', // e.g. 'clerk', 'auth0'
    });
  }

  return (
    <form onSubmit={(e) => {
      e.preventDefault();
      handleLogin(new FormData(e.currentTarget).get('email') as string);
    }}>
      <input name="email" type="email" placeholder="Email" />
      <button type="submit">Log in</button>
    </form>
  );
}
```

> ℹ️ **Info:**
> identifyUser sends the user data to the c15t backend. It works in hosted mode, including the legacy alias mode: 'c15t'. In mode: 'offline', the call is a no-op.

## Key Types

<details>
  <summary>`ConsentState`</summary>

  A record mapping consent category names to their boolean values:

  ```ts
  type ConsentState = Record<AllConsentNames, boolean>;
  // Example: { necessary: true, measurement: true, marketing: false }
  ```
</details>

<details>
  <summary>`ConsentInfo`</summary>

  Metadata about when and how consent was recorded:

  ```ts
  interface ConsentInfo {
    time: number;                    // Epoch timestamp when consent was recorded
    subjectId?: string;              // Client-generated subject ID (sub_xxx format)
    externalId?: string;             // External user ID linked via identifyUser()
    identityProvider?: string;       // Identity provider (e.g. 'clerk', 'auth0')
  }
  ```
</details>

<details>
  <summary>`LocationInfo`</summary>

  Detected geographic location from the c15t backend:

  ```ts
  interface LocationInfo {
    countryCode: string;     // ISO 3166-1 alpha-2 (e.g. 'DE')
    regionCode: string;      // Region/state code (e.g. 'BY')
    jurisdiction: string;    // Applicable jurisdiction (e.g. 'GDPR', 'CCPA')
  }
  ```
</details>

<details>
  <summary>`Model`</summary>

  The active consent model:

  ```ts
  type Model = 'opt-in' | 'opt-out' | 'iab' | null;
  ```

  * `'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 mode
  * `null` — No jurisdiction detected yet
</details>
