@c15t/nextjs 2.0.0-rc.4 → 2.0.0-rc.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/dist/headless.cjs +1 -1
  2. package/dist/iab/styles.css +1 -0
  3. package/dist/index.cjs +1 -1
  4. package/dist/index.js +1 -1
  5. package/dist/libs/browser-initial-data.cjs +1 -0
  6. package/dist/libs/browser-initial-data.js +1 -0
  7. package/dist/libs/initial-data.cjs +1 -1
  8. package/dist/libs/initial-data.js +1 -1
  9. package/dist/styles.css +1 -0
  10. package/dist/types.cjs +1 -1
  11. package/dist/version.cjs +1 -1
  12. package/dist/version.js +1 -1
  13. package/dist-types/headless.d.ts +1 -0
  14. package/{dist → dist-types}/index.d.ts +4 -3
  15. package/dist-types/libs/browser-initial-data.d.ts +9 -0
  16. package/{dist → dist-types}/libs/initial-data.d.ts +1 -2
  17. package/dist-types/types.d.ts +38 -0
  18. package/dist-types/version.d.ts +1 -0
  19. package/docs/README.md +73 -0
  20. package/docs/building-headless-components.md +250 -0
  21. package/docs/callbacks.md +117 -0
  22. package/docs/components/consent-banner.md +174 -0
  23. package/docs/components/consent-dialog-link.md +59 -0
  24. package/docs/components/consent-dialog-trigger.md +103 -0
  25. package/docs/components/consent-dialog.md +137 -0
  26. package/docs/components/consent-manager-provider.md +423 -0
  27. package/docs/components/consent-widget.md +78 -0
  28. package/docs/components/dev-tools.md +63 -0
  29. package/docs/components/frame.md +73 -0
  30. package/docs/concepts/client-modes.md +163 -0
  31. package/docs/concepts/consent-categories.md +97 -0
  32. package/docs/concepts/consent-models.md +116 -0
  33. package/docs/concepts/cookie-management.md +122 -0
  34. package/docs/concepts/glossary.md +23 -0
  35. package/docs/concepts/initialization-flow.md +141 -0
  36. package/docs/concepts/policy-packs.md +229 -0
  37. package/docs/headless.md +184 -0
  38. package/docs/hooks/use-color-scheme.md +40 -0
  39. package/docs/hooks/use-consent-manager/checking-consent.md +94 -0
  40. package/docs/hooks/use-consent-manager/location-info.md +95 -0
  41. package/docs/hooks/use-consent-manager/overview.md +390 -0
  42. package/docs/hooks/use-consent-manager/setting-consent.md +92 -0
  43. package/docs/hooks/use-draggable.md +57 -0
  44. package/docs/hooks/use-focus-trap.md +41 -0
  45. package/docs/hooks/use-reduced-motion.md +35 -0
  46. package/docs/hooks/use-ssr-status.md +31 -0
  47. package/docs/hooks/use-text-direction.md +49 -0
  48. package/docs/hooks/use-translations.md +117 -0
  49. package/docs/iab/consent-banner.md +95 -0
  50. package/docs/iab/consent-dialog.md +135 -0
  51. package/docs/iab/overview.md +119 -0
  52. package/docs/iab/use-gvl-data.md +208 -0
  53. package/docs/iframe-blocking.md +107 -0
  54. package/docs/integrations/databuddy.md +186 -0
  55. package/docs/integrations/google-tag-manager.md +153 -0
  56. package/docs/integrations/google-tag.md +149 -0
  57. package/docs/integrations/linkedin-insights.md +109 -0
  58. package/docs/integrations/meta-pixel.md +342 -0
  59. package/docs/integrations/microsoft-uet.md +112 -0
  60. package/docs/integrations/overview.md +89 -0
  61. package/docs/integrations/posthog.md +177 -0
  62. package/docs/integrations/tiktok-pixel.md +113 -0
  63. package/docs/integrations/x-pixel.md +143 -0
  64. package/docs/internationalization.md +197 -0
  65. package/docs/network-blocker.md +178 -0
  66. package/docs/optimization.md +156 -0
  67. package/docs/policy-packs.md +246 -0
  68. package/docs/quickstart.md +155 -0
  69. package/docs/script-loader.md +300 -0
  70. package/docs/server-side.md +171 -0
  71. package/docs/styling/classnames.md +84 -0
  72. package/docs/styling/color-scheme.md +82 -0
  73. package/docs/styling/css-variables.md +92 -0
  74. package/docs/styling/overview.md +312 -0
  75. package/docs/styling/slots.md +93 -0
  76. package/docs/styling/tailwind.md +115 -0
  77. package/docs/styling/tokens.md +214 -0
  78. package/docs/troubleshooting.md +146 -0
  79. package/package.json +20 -13
  80. package/dist/headless.d.ts +0 -2
  81. package/dist/headless.d.ts.map +0 -1
  82. package/dist/index.d.ts.map +0 -1
  83. package/dist/libs/initial-data.d.ts.map +0 -1
  84. package/dist/types.d.ts +0 -16
  85. package/dist/types.d.ts.map +0 -1
  86. package/dist/version.d.ts +0 -2
  87. package/dist/version.d.ts.map +0 -1
@@ -0,0 +1,390 @@
1
+ ---
2
+ title: useConsentManager
3
+ description: The primary hook for accessing consent state and actions. Returns the full consent store including all state properties and action methods.
4
+ ---
5
+ `useConsentManager()` is the primary hook for interacting with the consent system. It returns the complete consent store state and all action methods.
6
+
7
+ ```tsx
8
+ import { useConsentManager } from '@c15t/nextjs';
9
+
10
+ function MyComponent() {
11
+ const {
12
+ consents,
13
+ model,
14
+ has,
15
+ saveConsents,
16
+ // ... all state and actions
17
+ } = useConsentManager();
18
+ }
19
+ ```
20
+
21
+ > ℹ️ **Info:**
22
+ > Must be used within a ConsentManagerProvider. Throws an error if used outside the provider.
23
+
24
+ ## State Properties
25
+
26
+ ### StoreRuntimeState
27
+
28
+ |Property|Type|Description|Default|Required|
29
+ |:--|:--|:--|:--|:--:|
30
+ |branding|"c15t" \|"consent" \|"none"|Whether to show the branding|-|✅ Required|
31
+ |consents|ConsentState|Current consent states for all consent types|-|✅ Required|
32
+ |selectedConsents|ConsentState|Selected consents (Not Saved) - use saveConsents to save|-|✅ Required|
33
+ |consentInfo|ConsentInfo \|null|Information about when and how consent was given|-|✅ Required|
34
+ |activeUI|ActiveUI|Which consent UI component is currently visible.|-|✅ Required|
35
+ |isLoadingConsentInfo|boolean|Whether consent banner information is currently being loaded|-|✅ Required|
36
+ |hasFetchedBanner|boolean|Whether consent banner information has been successfully fetched|-|✅ Required|
37
+ |lastBannerFetchData|Object \|undefined \|null|Last consent banner fetch data for callback replay|-|✅ Required|
38
+ |debug|boolean|Whether debug logging is enabled|-|✅ Required|
39
+ |consentCategories|AllConsentNames|Active consent categories|-|✅ Required|
40
+ |locationInfo|LocationInfo \|null|Subject's location information|-|✅ Required|
41
+ |includeNonDisplayedConsents|boolean|Whether to include non-displayed consents in operations|-|✅ Required|
42
+ |consentTypes|ConsentType|Available consent type configurations|-|✅ Required|
43
+ |iframeBlockerConfig|IframeBlockerConfig|Configuration for the iframe blocker|-|✅ Required|
44
+ |loadedScripts|Record\<string, boolean>|Map of currently loaded script IDs to a boolean loaded-state|-|✅ Required|
45
+ |scriptIdMap|Record\<string, string>|Map of anonymized script IDs to their original IDs|-|✅ Required|
46
+ |model|Model|What type of consent model to use for the consent manager.|-|✅ Required|
47
+ |policyBanner|PolicySurfaceState|Policy-driven UI hints for the consent banner surface.|-|✅ Required|
48
+ |policyDialog|PolicySurfaceState|Policy-driven UI hints for the consent dialog surface.|-|✅ Required|
49
+ |policyCategories|string\[] \|null|Active runtime policy category scope from \`/init\`.|-|✅ Required|
50
+ |policyScopeMode|PolicyScopeMode \|null|Runtime policy scope mode from \`/init\`. Controls whether out-of-scope categories are treated as permissive at runtime.|-|✅ Required|
51
+ |initDataSource|InitDataSource \|null|Source that provided the most recent \`/init\` payload used to hydrate runtime state.|-|✅ Required|
52
+ |initDataSourceDetail|string \|null|Optional source detail for diagnostics (for example, cache header values).|-|✅ Required|
53
+ |iab|IABManager \|null|IAB TCF 2.3 state and actions (null when not configured or not in IAB mode).|-|✅ Required|
54
+ |reloadOnConsentRevoked|boolean|Whether to reload the page when consent is revoked.|-|✅ Required|
55
+ |ssrDataUsed|boolean|Whether SSR data was successfully used for initialization.|-|✅ Required|
56
+ |ssrSkippedReason|"no\_data" \|"fetch\_failed" \|null|Reason SSR data was skipped, if applicable.|-|✅ Required|
57
+
58
+ #### `consents` ConsentState
59
+
60
+ Current consent states for all consent types
61
+
62
+ |Property|Type|Description|Default|Required|
63
+ |:--|:--|:--|:--|:--:|
64
+ |experience|boolean|-|-|✅ Required|
65
+ |functionality|boolean|-|-|✅ Required|
66
+ |marketing|boolean|-|-|✅ Required|
67
+ |measurement|boolean|-|-|✅ Required|
68
+ |necessary|boolean|-|-|✅ Required|
69
+
70
+ #### `selectedConsents` ConsentState
71
+
72
+ Selected consents (Not Saved) - use saveConsents to save
73
+
74
+ |Property|Type|Description|Default|Required|
75
+ |:--|:--|:--|:--|:--:|
76
+ |experience|boolean|-|-|✅ Required|
77
+ |functionality|boolean|-|-|✅ Required|
78
+ |marketing|boolean|-|-|✅ Required|
79
+ |measurement|boolean|-|-|✅ Required|
80
+ |necessary|boolean|-|-|✅ Required|
81
+
82
+ #### `consentInfo` ConsentInfo
83
+
84
+ Information about when and how consent was given
85
+
86
+ |Property|Type|Description|Default|Required|
87
+ |:--|:--|:--|:--|:--:|
88
+ |time|number|The epoch timestamp of when the consent was recorded|-|✅ Required|
89
+ |subjectId|string \|undefined|The client-generated subject ID in sub\_xxx format|-|Optional|
90
+ |id|string \|undefined|-|-|Optional|
91
+ |externalId|string \|undefined|The external user ID linked to this subject|-|Optional|
92
+ |materialPolicyFingerprint|string \|undefined|Material fingerprint of the active policy when this consent was accepted.|-|Optional|
93
+ |identityProvider|string \|undefined|The identity provider that provided the external ID|-|Optional|
94
+
95
+ #### `locationInfo` LocationInfo
96
+
97
+ Subject's location information
98
+
99
+ |Property|Type|Description|Default|Required|
100
+ |:--|:--|:--|:--|:--:|
101
+ |countryCode|string \|null|ISO country code (e.g., 'US', 'GB', 'DE')|-|✅ Required|
102
+ |regionCode|string \|null|Region or state code within the country (e.g., 'CA', 'ENG')|-|✅ Required|
103
+ |jurisdiction|Object \|null|Jurisdiction code (e.g. 'GDPR')|-|✅ Required|
104
+
105
+ #### `consentTypes` ConsentType
106
+
107
+ Available consent type configurations
108
+
109
+ |Property|Type|Description|Default|Required|
110
+ |:--|:--|:--|:--|:--:|
111
+ |defaultValue|boolean|Whether consent is granted by default|-|✅ Required|
112
+ |description|string|Subject-friendly description of what this consent enables|-|✅ Required|
113
+ |disabled|boolean \|undefined|Whether users can modify this consent setting|-|Optional|
114
+ |display|boolean|Whether to show this consent option in the UI|-|✅ Required|
115
+ |gdprType|number|GDPR category identifier (1-5)|-|✅ Required|
116
+ |name|AllConsentNames|The consent category name|-|✅ Required|
117
+
118
+ #### `iframeBlockerConfig` IframeBlockerConfig
119
+
120
+ Configuration for the iframe blocker
121
+
122
+ |Property|Type|Description|Default|Required|
123
+ |:--|:--|:--|:--|:--:|
124
+ |disableAutomaticBlocking|boolean \|undefined|Whether to disable automatic iframe blocking (defaults to false)|-|Optional|
125
+
126
+ #### `policyBanner` PolicySurfaceState
127
+
128
+ Policy-driven UI hints for the consent banner surface.
129
+
130
+ |Property|Type|Description|Default|Required|
131
+ |:--|:--|:--|:--|:--:|
132
+ |allowedActions|PolicyUiAction \|undefined|Allowed actions for this surface derived from backend runtime policy.|-|Optional|
133
+ |primaryActions|PolicyUiAction \|undefined|Preferred primary action hints from backend runtime policy.|-|Optional|
134
+ |layout|PolicyUiActionGroup \|undefined|Explicit grouped action layout hint from backend runtime policy.|-|Optional|
135
+ |direction|PolicyUiActionDirection \|undefined|Direction hint for the grouped action layout.|-|Optional|
136
+ |uiProfile|PolicyUiProfile \|undefined|Presentation profile hint from backend runtime policy.|-|Optional|
137
+ |scrollLock|boolean \|undefined|Scroll lock hint from backend runtime policy.|-|Optional|
138
+
139
+ #### `policyDialog` PolicySurfaceState
140
+
141
+ Policy-driven UI hints for the consent dialog surface.
142
+
143
+ |Property|Type|Description|Default|Required|
144
+ |:--|:--|:--|:--|:--:|
145
+ |allowedActions|PolicyUiAction \|undefined|Allowed actions for this surface derived from backend runtime policy.|-|Optional|
146
+ |primaryActions|PolicyUiAction \|undefined|Preferred primary action hints from backend runtime policy.|-|Optional|
147
+ |layout|PolicyUiActionGroup \|undefined|Explicit grouped action layout hint from backend runtime policy.|-|Optional|
148
+ |direction|PolicyUiActionDirection \|undefined|Direction hint for the grouped action layout.|-|Optional|
149
+ |uiProfile|PolicyUiProfile \|undefined|Presentation profile hint from backend runtime policy.|-|Optional|
150
+ |scrollLock|boolean \|undefined|Scroll lock hint from backend runtime policy.|-|Optional|
151
+
152
+ #### `iab` IABManager
153
+
154
+ IAB TCF 2.3 state and actions (null when not configured or not in IAB mode).
155
+
156
+ |Property|Type|Description|Default|Required|
157
+ |:--|:--|:--|:--|:--:|
158
+ |config|IABConfig|IAB TCF configuration|-|✅ Required|
159
+ |gvl|Object \|undefined \|null|Global Vendor List data (null when not yet fetched or in non-IAB region)|-|✅ Required|
160
+ |isLoadingGVL|boolean|Whether GVL is currently being fetched|-|✅ Required|
161
+ |nonIABVendors|NonIABVendor|Non-IAB vendors configured by the publisher|-|✅ Required|
162
+ |tcString|string \|null|IAB TCF consent string (TC String)|-|✅ Required|
163
+ |vendorConsents|Record\<string, boolean>|Per-vendor consent state (keyed by vendor ID)|-|✅ Required|
164
+ |vendorLegitimateInterests|Record\<string, boolean>|Per-vendor legitimate interest state|-|✅ Required|
165
+ |purposeConsents|Record\<number, boolean>|Per-purpose consent state (IAB purposes 1-11)|-|✅ Required|
166
+ |purposeLegitimateInterests|Record\<number, boolean>|Per-purpose legitimate interest state|-|✅ Required|
167
+ |specialFeatureOptIns|Record\<number, boolean>|Special feature opt-ins (e.g., precise geolocation)|-|✅ Required|
168
+ |vendorsDisclosed|Record\<number, boolean>|Vendors disclosed to the user in the CMP UI (TCF 2.3 requirement). This tracks which vendors were shown to the user, regardless of whether consent was given. Required for TC String generation.|-|✅ Required|
169
+ |cmpApi|CMPApi \|null|CMP API controls (manages \_\_tcfapi)|-|✅ Required|
170
+ |preferenceCenterTab|"purposes" \|"vendors"|Active tab for the IAB preference center UI|-|✅ Required|
171
+ |setPurposeConsent|(purposeId: number, value: boolean) => void|Sets IAB purpose consent.|-|✅ Required|
172
+ |setPurposeLegitimateInterest|(purposeId: number, value: boolean) => void|Sets IAB purpose legitimate interest.|-|✅ Required|
173
+ |setVendorConsent|(vendorId: string \|number, value: boolean) => void|Sets IAB vendor consent.|-|✅ Required|
174
+ |setVendorLegitimateInterest|(vendorId: string \|number, value: boolean) => void|Sets IAB vendor legitimate interest.|-|✅ Required|
175
+ |setSpecialFeatureOptIn|(featureId: number, value: boolean) => void|Sets special feature opt-in.|-|✅ Required|
176
+ |setPreferenceCenterTab|(tab: "purposes" \|"vendors") => void|Sets the active tab for the IAB preference center.|-|✅ Required|
177
+ |acceptAll|() => void|Accepts all IAB purposes, vendors, and special features.|-|✅ Required|
178
+ |rejectAll|() => void|Rejects all IAB purposes (except necessary/Purpose 1) and vendors.|-|✅ Required|
179
+ |save|() => Promise\<void>|Saves IAB consents and generates TC String.|-|✅ Required|
180
+ |\_updateState|(updates: Partial\<IABState>) => void|Updates IAB state (internal use).|-|✅ Required|
181
+
182
+ ## Action Methods
183
+
184
+ ### StoreActions
185
+
186
+ |Property|Type|Description|Default|Required|
187
+ |:--|:--|:--|:--|:--:|
188
+ |setTranslationConfig|Object|Updates the translation configuration.|-|✅ Required|
189
+ |setOverrides|Object \|undefined \|null|Sets the overrides for the consent manager. Automatically attempts to fetch the consent manager again with the new overrides.|-|✅ Required|
190
+ |setLanguage|Object \|undefined \|null|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|
191
+ |identifyUser|Object|Identifies the user by setting the external ID.|-|✅ Required|
192
+ |setSelectedConsent|(name: AllConsentNames, value: boolean) => void|Updates the selected consent state for a specific consent type.|-|✅ Required|
193
+ |saveConsents|Object \|undefined|Saves the user's consent preferences.|-|✅ Required|
194
+ |setConsent|(name: AllConsentNames, value: boolean) => void|Updates the consent state for a specific consent type & automatically save the consent.|-|✅ Required|
195
+ |resetConsents|() => void|Resets all consent preferences to their default values|-|✅ Required|
196
+ |setActiveUI|(ui: ActiveUI, options?: \{ force?: boolean \|undefined; } \|undefined) => void|Sets the active consent UI component.|-|✅ Required|
197
+ |setConsentCategories|(types: AllConsentNames\[]) => void|Updates the active GDPR consent types.|-|✅ Required|
198
+ |setCallback|Object \|undefined|Sets a callback for a specific consent event.|-|✅ Required|
199
+ |setLocationInfo|Object \|null|Updates the user's location information.|-|✅ Required|
200
+ |initConsentManager|Object \|undefined \|null|Initializes the consent manager by fetching jurisdiction, location, translations, and branding information.|-|✅ Required|
201
+ |getDisplayedConsents|ConsentType|Retrieves the list of consent types that should be displayed|-|✅ Required|
202
+ |hasConsented|() => boolean|Checks if the user has provided any form of consent|-|✅ Required|
203
+ |has|Object|Evaluates whether current consent state satisfies the given condition.|-|✅ Required|
204
+ |setScripts|Object|Sets multiple script configurations to the store.|-|✅ Required|
205
+ |removeScript|(scriptId: string) => void|Removes a script configuration from the store.|-|✅ Required|
206
+ |updateScripts|Object|Updates scripts based on current consent state. Loads scripts that have consent and aren't loaded yet. Unloads scripts that no longer have consent.|-|✅ Required|
207
+ |isScriptLoaded|(scriptId: string) => boolean|Checks if a script is currently loaded.|-|✅ Required|
208
+ |getLoadedScriptIds|() => string\[]|Gets all currently loaded script IDs.|-|✅ Required|
209
+ |initializeIframeBlocker|() => void|Initializes the iframe blocker instance.|-|✅ Required|
210
+ |updateIframeConsents|() => void|Updates the active consents used by the iframe blocker.|-|✅ Required|
211
+ |destroyIframeBlocker|() => void|Destroys the iframe blocker instance and cleans up resources.|-|✅ Required|
212
+ |initializeNetworkBlocker|() => void|Initializes the network blocker instance.|-|✅ Required|
213
+ |updateNetworkBlockerConsents|() => void|Updates the consent snapshot used by the network blocker.|-|✅ Required|
214
+ |setNetworkBlocker|Object \|undefined|Updates the network blocker configuration at runtime.|-|✅ Required|
215
+ |destroyNetworkBlocker|() => void|Destroys the network blocker instance and cleans up resources.|-|✅ Required|
216
+ |updateConsentCategories|(newCategories: AllConsentNames\[]) => void|Extends the active GDPR consent categories with any categories used by configured scripts.|-|✅ Required|
217
+
218
+ #### `setTranslationConfig`
219
+
220
+ Updates the translation configuration.
221
+
222
+ |Property|Type|Description|Default|Required|
223
+ |:--|:--|:--|:--|:--:|
224
+ |translations|Record\<string, Partial\<Translations>>|-|-|✅ Required|
225
+ |defaultLanguage|string \|undefined|-|-|Optional|
226
+ |disableAutoLanguageSwitch|boolean \|undefined|-|-|Optional|
227
+
228
+ #### `setOverrides`
229
+
230
+ Sets the overrides for the consent manager. Automatically attempts to fetch the consent manager again with the new overrides.
231
+
232
+ |Property|Type|Description|Default|Required|
233
+ |:--|:--|:--|:--|:--:|
234
+ |country|string \|undefined|Country code to forcefully set|-|Optional|
235
+ |region|string \|undefined|Region code to forcefully set|-|Optional|
236
+ |language|string \|undefined|Language code to forcefully set|-|Optional|
237
+ |gpc|boolean \|undefined|Override the Global Privacy Control (GPC) signal. When \`true\`, simulates GPC being active (opt-out of marketing/measurement). When \`false\`, suppresses the real browser GPC signal. When \`undefined\`, falls back to the browser's \`navigator.globalPrivacyControl\`.|-|Optional|
238
+
239
+ #### `identifyUser`
240
+
241
+ Identifies the user by setting the external ID.
242
+
243
+ |Property|Type|Description|Default|Required|
244
+ |:--|:--|:--|:--|:--:|
245
+ |id|string|Usually your own internal ID for the user from your auth provider|-|✅ Required|
246
+ |identityProvider|string \|undefined|The identity provider of the user. Usually the name of the identity provider e.g. 'clerk', 'auth0', 'custom', etc.|-|Optional|
247
+
248
+ #### `setLocationInfo`
249
+
250
+ Updates the user's location information.
251
+
252
+ |Property|Type|Description|Default|Required|
253
+ |:--|:--|:--|:--|:--:|
254
+ |countryCode|string \|null|ISO country code (e.g., 'US', 'GB', 'DE')|-|✅ Required|
255
+ |regionCode|string \|null|Region or state code within the country (e.g., 'CA', 'ENG')|-|✅ Required|
256
+ |jurisdiction|Object \|null|Jurisdiction code (e.g. 'GDPR')|-|✅ Required|
257
+
258
+ #### `setScripts`
259
+
260
+ Sets multiple script configurations to the store.
261
+
262
+ |Property|Type|Description|Default|Required|
263
+ |:--|:--|:--|:--|:--:|
264
+ |id|string|Unique identifier for the script|-|✅ Required|
265
+ |src|string \|undefined|URL of the script to load|-|Optional|
266
+ |textContent|string \|undefined|Inline JavaScript code to execute|-|Optional|
267
+ |category|HasCondition\<AllConsentNames>|Consent category or condition required to load this script|-|✅ Required|
268
+ |callbackOnly|boolean \|undefined|Whether this is a callback-only script that doesn't need to load an external resource. When true, no script tag will be added to the DOM, only callbacks will be executed.|-|Optional|
269
+ |persistAfterConsentRevoked|boolean \|undefined|Whether the script should persist after consent is revoked.|-|Optional|
270
+ |alwaysLoad|boolean \|undefined|Whether the script should always load regardless of consent state. This is useful for scripts like Google Tag Manager or PostHog that manage their own consent state internally. The script will load immediately and never be unloaded based on consent changes. Note: When using this option, you are responsible for ensuring the script itself respects user consent preferences through its own consent management.|-|Optional|
271
+ |fetchPriority|"high" \|"low" \|"auto" \|undefined|Priority hint for browser resource loading|-|Optional|
272
+ |attributes|Record\<string, string> \|undefined|Additional attributes to add to the script element|-|Optional|
273
+ |async|boolean \|undefined|Whether to use async loading|-|Optional|
274
+ |defer|boolean \|undefined|Whether to defer script loading|-|Optional|
275
+ |nonce|string \|undefined|Content Security Policy nonce|-|Optional|
276
+ |anonymizeId|boolean \|undefined|Whether to use an anonymized ID for the script element, this helps ensure the script is not blocked by ad blockers|-|Optional|
277
+ |target|"head" \|"body" \|undefined|Where to inject the script element in the DOM. Options: \`'head'\`: Scripts are appended to \`\<head>\` (default); \`'body'\`: Scripts are appended to \`\<body>\`|-|Optional|
278
+ |onBeforeLoad|((info: ScriptCallbackInfo) => void) \|undefined|Callback executed before the script is loaded|-|Optional|
279
+ |onLoad|((info: ScriptCallbackInfo) => void) \|undefined|Callback executed when the script loads successfully|-|Optional|
280
+ |onError|((info: ScriptCallbackInfo) => void) \|undefined|Callback executed if the script fails to load|-|Optional|
281
+ |onConsentChange|((info: ScriptCallbackInfo) => void) \|undefined|Callback executed whenever the consent store is changed. This callback only applies to scripts already loaded.|-|Optional|
282
+ |vendorId|string \|number \|undefined|IAB TCF vendor ID - links script to a registered vendor. When in IAB mode, the script will only load if this vendor has consent. Takes precedence over \`category\` when in IAB mode. Use custom vendor IDs (string or number) to gate non-IAB vendors too.|-|Optional|
283
+ |iabPurposes|number\[] \|undefined|IAB TCF purpose IDs this script requires consent for. When in IAB mode and no vendorId is set, the script will only load if ALL specified purposes have consent.|-|Optional|
284
+ |iabLegIntPurposes|number\[] \|undefined|IAB TCF legitimate interest purpose IDs. These purposes can operate under legitimate interest instead of consent. The script loads if all iabPurposes have consent OR all iabLegIntPurposes have legitimate interest established.|-|Optional|
285
+ |iabSpecialFeatures|number\[] \|undefined|IAB TCF special feature IDs this script requires. Options: 1: Use precise geolocation data; 2: Actively scan device characteristics for identification|-|Optional|
286
+
287
+ #### `setNetworkBlocker`
288
+
289
+ Updates the network blocker configuration at runtime.
290
+
291
+ |Property|Type|Description|Default|Required|
292
+ |:--|:--|:--|:--|:--:|
293
+ |enabled|boolean \|undefined|Whether the network blocker is enabled.|-|Optional|
294
+ |initialConsents|ConsentState \|undefined|The consent state snapshot that is currently used for blocking logic.|-|Optional|
295
+ |logBlockedRequests|boolean \|undefined|Whether to automatically log blocked requests to the console.|-|Optional|
296
+ |onRequestBlocked|((info: BlockedRequestInfo) => void) \|undefined|Callback invoked whenever a request is blocked.|-|Optional|
297
+ |rules|NetworkBlockerRule|Domain rules that determine which requests should be blocked.|-|✅ Required|
298
+
299
+ ## identifyUser
300
+
301
+ 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.
302
+
303
+ ```tsx
304
+ import { useConsentManager } from '@c15t/nextjs';
305
+
306
+ function LoginForm() {
307
+ const { identifyUser } = useConsentManager();
308
+
309
+ async function handleLogin(email: string) {
310
+ // ... your login logic
311
+ const user = await api.login(email);
312
+
313
+ // Link consent to the authenticated user
314
+ await identifyUser({
315
+ id: user.id,
316
+ identityProvider: 'your-auth-provider', // e.g. 'clerk', 'auth0'
317
+ });
318
+ }
319
+
320
+ return (
321
+ <form onSubmit={(e) => {
322
+ e.preventDefault();
323
+ handleLogin(new FormData(e.currentTarget).get('email') as string);
324
+ }}>
325
+ <input name="email" type="email" placeholder="Email" />
326
+ <button type="submit">Log in</button>
327
+ </form>
328
+ );
329
+ }
330
+ ```
331
+
332
+ > ℹ️ **Info:**
333
+ > identifyUser sends the user data to the c15t backend. It only works in 'c15t' mode — in 'offline' mode the call is a no-op.
334
+
335
+ ## Key Types
336
+
337
+ <details>
338
+ <summary>`ConsentState`</summary>
339
+
340
+ A record mapping consent category names to their boolean values:
341
+
342
+ ```ts
343
+ type ConsentState = Record<AllConsentNames, boolean>;
344
+ // Example: { necessary: true, measurement: true, marketing: false }
345
+ ```
346
+ </details>
347
+
348
+ <details>
349
+ <summary>`ConsentInfo`</summary>
350
+
351
+ Metadata about when and how consent was recorded:
352
+
353
+ ```ts
354
+ interface ConsentInfo {
355
+ time: number; // Epoch timestamp when consent was recorded
356
+ subjectId?: string; // Client-generated subject ID (sub_xxx format)
357
+ externalId?: string; // External user ID linked via identifyUser()
358
+ identityProvider?: string; // Identity provider (e.g. 'clerk', 'auth0')
359
+ }
360
+ ```
361
+ </details>
362
+
363
+ <details>
364
+ <summary>`LocationInfo`</summary>
365
+
366
+ Detected geographic location from the c15t backend:
367
+
368
+ ```ts
369
+ interface LocationInfo {
370
+ countryCode: string; // ISO 3166-1 alpha-2 (e.g. 'DE')
371
+ regionCode: string; // Region/state code (e.g. 'BY')
372
+ jurisdiction: string; // Applicable jurisdiction (e.g. 'GDPR', 'CCPA')
373
+ }
374
+ ```
375
+ </details>
376
+
377
+ <details>
378
+ <summary>`Model`</summary>
379
+
380
+ The active consent model:
381
+
382
+ ```ts
383
+ type Model = 'opt-in' | 'opt-out' | 'iab' | null;
384
+ ```
385
+
386
+ * `'opt-in'` — Explicit consent required before tracking (GDPR)
387
+ * `'opt-out'` — Tracking allowed by default, user can opt out (CCPA)
388
+ * `'iab'` — IAB TCF 2.3 compliance mode
389
+ * `null` — No jurisdiction detected yet
390
+ </details>
@@ -0,0 +1,92 @@
1
+ ---
2
+ title: Setting Consent
3
+ description: Save, update, and reset consent preferences with setConsent(), setSelectedConsent(), and saveConsents().
4
+ ---
5
+ ## saveConsents(type)
6
+
7
+ The primary way to persist consent. Accepts one of three strategies:
8
+
9
+ ```tsx
10
+ const { saveConsents } = useConsentManager();
11
+
12
+ // Accept all - sets every active category to true
13
+ await saveConsents('all');
14
+
15
+ // Reject all - only necessary stays true, everything else false
16
+ await saveConsents('necessary');
17
+
18
+ // Save current selections - persists whatever the user toggled
19
+ await saveConsents('custom');
20
+ ```
21
+
22
+ **What happens when you call saveConsents:**
23
+
24
+ 1. Consent state is updated in the store
25
+ 2. UI closes (activeUI → 'none')
26
+ 3. Consent is saved to localStorage and cookie
27
+ 4. If consent was revoked and `reloadOnConsentRevoked` is true, the page reloads
28
+ 5. Otherwise, scripts/iframes/network blocker are updated
29
+ 6. Consent is synced to the backend API
30
+
31
+ ## setConsent(name, value)
32
+
33
+ Updates a single consent category AND automatically saves it. Use this for simple one-off consent changes:
34
+
35
+ ```tsx
36
+ const { setConsent } = useConsentManager();
37
+
38
+ // Grant measurement consent immediately
39
+ setConsent('measurement', true);
40
+
41
+ // Revoke marketing consent immediately
42
+ setConsent('marketing', false);
43
+ ```
44
+
45
+ ## setSelectedConsent(name, value)
46
+
47
+ Updates the selection state without saving. This is what dialog toggles use - the user can flip toggles without committing until they click "Save":
48
+
49
+ ```tsx
50
+ const { setSelectedConsent, saveConsents } = useConsentManager();
51
+
52
+ // User toggles measurement on
53
+ setSelectedConsent('measurement', true);
54
+
55
+ // User toggles marketing off
56
+ setSelectedConsent('marketing', false);
57
+
58
+ // User clicks "Save" - now it persists
59
+ await saveConsents('custom');
60
+ ```
61
+
62
+ ## resetConsents()
63
+
64
+ Resets all consent preferences to their default values and clears stored consent:
65
+
66
+ ```tsx
67
+ const { resetConsents } = useConsentManager();
68
+
69
+ resetConsents();
70
+ // All consents back to defaults, consent info cleared
71
+ ```
72
+
73
+ ## Accept All / Reject All Patterns
74
+
75
+ Common patterns for banner buttons:
76
+
77
+ ```tsx
78
+ function ConsentActions() {
79
+ const { saveConsents } = useConsentManager();
80
+
81
+ return (
82
+ <div>
83
+ <button onClick={() => saveConsents('necessary')}>
84
+ Reject All
85
+ </button>
86
+ <button onClick={() => saveConsents('all')}>
87
+ Accept All
88
+ </button>
89
+ </div>
90
+ );
91
+ }
92
+ ```
@@ -0,0 +1,57 @@
1
+ ---
2
+ title: useDraggable
3
+ description: Make an element draggable between viewport corners with snapping, persistence, and animation support.
4
+ ---
5
+ `useDraggable()` provides drag-to-corner functionality. Used internally by `ConsentDialogTrigger`, this hook lets you build custom draggable elements that snap to viewport corners.
6
+
7
+ ```tsx
8
+ import { useDraggable } from '@c15t/nextjs';
9
+
10
+ function DraggableButton() {
11
+ const { corner, isDragging, handlers, dragStyle } = useDraggable({
12
+ defaultPosition: 'bottom-right',
13
+ persistPosition: true,
14
+ });
15
+
16
+ return (
17
+ <button
18
+ {...handlers}
19
+ style={{
20
+ ...dragStyle,
21
+ position: 'fixed',
22
+ // Position based on corner
23
+ ...(corner.includes('bottom') ? { bottom: 16 } : { top: 16 }),
24
+ ...(corner.includes('right') ? { right: 16 } : { left: 16 }),
25
+ }}
26
+ >
27
+ {isDragging ? 'Dragging...' : 'Drag me'}
28
+ </button>
29
+ );
30
+ }
31
+ ```
32
+
33
+ ## Options
34
+
35
+ |Option|Type|Default|Description|
36
+ |--|--|--|--|
37
+ |`defaultPosition`|`CornerPosition`|`'bottom-right'`|Initial corner position|
38
+ |`persistPosition`|`boolean`|`true`|Save position to localStorage|
39
+ |`onPositionChange`|`(position: CornerPosition) => void`|-|Callback on position change|
40
+
41
+ ## Return Value
42
+
43
+ |Property|Type|Description||||
44
+ |--|--|--|--|--|--|
45
+ |`corner`|`CornerPosition`|Current corner: `'top-left'`|`'top-right'`|`'bottom-left'`|`'bottom-right'`|
46
+ |`isDragging`|`boolean`|Whether the element is being dragged||||
47
+ |`isSnapping`|`boolean`|Whether the element is animating to a new corner||||
48
+ |`wasDragged`|`() => boolean`|Whether the last interaction was a drag (vs click)||||
49
+ |`handlers`|`object`|Pointer event handlers to spread onto the element||||
50
+ |`dragStyle`|`CSSProperties`|Transform style for drag offset||||
51
+
52
+ ## Behavior
53
+
54
+ * Drag starts on pointer down (left click / single touch)
55
+ * Movement threshold of 5px distinguishes drag from click
56
+ * On pointer up, element snaps to the nearest corner based on drag direction and velocity
57
+ * Position persists to localStorage by default
@@ -0,0 +1,41 @@
1
+ ---
2
+ title: useFocusTrap
3
+ description: Trap keyboard focus within a container for accessible modal dialogs.
4
+ ---
5
+ `useFocusTrap()` keeps keyboard focus within a container element while active. This is essential for accessibility - when a modal dialog is open, Tab and Shift+Tab should cycle through focusable elements inside the dialog, not escape to the page behind it.
6
+
7
+ ```tsx
8
+ import { useFocusTrap } from '@c15t/nextjs';
9
+ import { useRef } from 'react';
10
+
11
+ function AccessibleModal({ isOpen }: { isOpen: boolean }) {
12
+ const containerRef = useRef<HTMLDivElement>(null);
13
+ useFocusTrap(isOpen, containerRef);
14
+
15
+ if (!isOpen) return null;
16
+
17
+ return (
18
+ <div ref={containerRef} role="dialog" aria-modal="true">
19
+ <h2>Modal Title</h2>
20
+ <button>Action</button>
21
+ <button>Close</button>
22
+ </div>
23
+ );
24
+ }
25
+ ```
26
+
27
+ ## Parameters
28
+
29
+ |Parameter|Type|Description|
30
+ |--|--|--|
31
+ |`shouldTrap`|`boolean`|Whether focus should be trapped|
32
+ |`containerRef`|`RefObject<HTMLElement \|null> \|null`|Ref to the container element|
33
+
34
+ ## Behavior
35
+
36
+ * **Tab**: Moves focus to the next focusable element. Wraps to the first element when reaching the end.
37
+ * **Shift+Tab**: Moves focus to the previous focusable element. Wraps to the last element when reaching the start.
38
+ * Focus is restored to the previously focused element when the trap is deactivated.
39
+
40
+ > ℹ️ **Info:**
41
+ > ConsentBanner and ConsentDialog use useFocusTrap internally when trapFocus is enabled (default: true). You only need this hook when building custom consent UI.
@@ -0,0 +1,35 @@
1
+ ---
2
+ title: useReducedMotion
3
+ description: Detect the user's prefers-reduced-motion OS setting and reactively disable animations.
4
+ ---
5
+ `useReducedMotion()` reads the `prefers-reduced-motion: reduce` media query and reactively updates when the user's preference changes. Use it to conditionally skip animations for users who have enabled reduced motion in their OS accessibility settings.
6
+
7
+ The hook returns `false` during SSR to avoid hydration mismatches, then updates to the actual preference on the client.
8
+
9
+ ```tsx
10
+ import { useReducedMotion } from '@c15t/react/hooks';
11
+
12
+ function AnimatedBanner() {
13
+ const prefersReducedMotion = useReducedMotion();
14
+
15
+ return (
16
+ <div
17
+ style={{
18
+ transition: prefersReducedMotion ? 'none' : 'opacity 300ms ease',
19
+ opacity: 1,
20
+ }}
21
+ >
22
+ Consent banner content
23
+ </div>
24
+ );
25
+ }
26
+ ```
27
+
28
+ ## Return Value
29
+
30
+ |Type|Description|
31
+ |--|--|
32
+ |`boolean`|`true` if the user prefers reduced motion, `false` otherwise|
33
+
34
+ > ℹ️ **Info:**
35
+ > c15t's built-in components already respect prefers-reduced-motion internally. This hook is primarily useful when building custom UI with the headless approach.
@@ -0,0 +1,31 @@
1
+ ---
2
+ title: useSSRStatus
3
+ description: Check whether server-side rendered consent data was used during initialization.
4
+ ---
5
+ `useSSRStatus()` returns information about whether SSR data was used for consent manager initialization. This is primarily useful for debugging SSR data flow in Next.js or other server-rendering frameworks.
6
+
7
+ ```tsx
8
+ import { useSSRStatus } from '@c15t/nextjs';
9
+
10
+ function DebugSSR() {
11
+ const { ssrDataUsed, ssrSkippedReason } = useSSRStatus();
12
+
13
+ if (ssrDataUsed) {
14
+ return <span>Consent initialized from SSR data</span>;
15
+ }
16
+
17
+ return <span>SSR skipped: {ssrSkippedReason ?? 'unknown'}</span>;
18
+ }
19
+ ```
20
+
21
+ ## Return Value
22
+
23
+ ### SSRStatus
24
+
25
+ |Property|Type|Description|Default|Required|
26
+ |:--|:--|:--|:--|:--:|
27
+ |ssrDataUsed|boolean|Whether SSR data was used for initialization. \`true\` if SSR data was provided and successfully consumed, \`false\` otherwise.|-|✅ Required|
28
+ |ssrSkippedReason|"no\_data" \|"fetch\_failed" \|null|Reason SSR data was skipped, or \`null\` if used successfully.|-|✅ Required|
29
+
30
+ > ℹ️ **Info:**
31
+ > Must be used within a ConsentManagerProvider. Throws if used outside the provider context.