@c15t/nextjs 2.2.1 → 3.0.0-alpha.0

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 (220) hide show
  1. package/AGENTS.md +102 -142
  2. package/README.md +4 -4
  3. package/dist/api.js +1 -0
  4. package/dist/config.js +1 -0
  5. package/dist/devtools.js +2 -0
  6. package/dist/headers.js +1 -0
  7. package/dist/iab/styles.css +1 -1
  8. package/dist/iab/styles.tw3.css +133 -19
  9. package/dist/index.js +1 -1
  10. package/dist/middleware.js +1 -0
  11. package/dist/node-bridge.js +1 -0
  12. package/dist/pages.js +1 -0
  13. package/dist/proxy.js +1 -0
  14. package/dist/root.js +2 -0
  15. package/dist/server.js +1 -0
  16. package/dist/static.js +1 -0
  17. package/dist/styles.css +1 -1
  18. package/dist/styles.tw3.css +173 -29
  19. package/dist/version.js +1 -1
  20. package/dist-types/api.d.ts +88 -0
  21. package/dist-types/config.d.ts +110 -0
  22. package/dist-types/devtools.d.ts +1 -0
  23. package/dist-types/headers.d.ts +4 -0
  24. package/dist-types/index.d.ts +28 -10
  25. package/dist-types/middleware.d.ts +15 -0
  26. package/dist-types/node-bridge.d.ts +57 -0
  27. package/dist-types/pages.d.ts +88 -0
  28. package/dist-types/proxy.d.ts +34 -0
  29. package/dist-types/root.d.ts +86 -0
  30. package/dist-types/server.d.ts +164 -0
  31. package/dist-types/static.d.ts +42 -0
  32. package/dist-types/types.d.ts +5 -36
  33. package/dist-types/version.d.ts +1 -1
  34. package/docs/README.md +102 -142
  35. package/docs/assets/v3/brand-bar.png +0 -0
  36. package/docs/assets/v3/brand-card.png +0 -0
  37. package/docs/assets/v3/choice-wall.png +0 -0
  38. package/docs/assets/v3/mobile-card.png +0 -0
  39. package/docs/assets/v3/preferences.png +0 -0
  40. package/docs/customization/overview.md +45 -0
  41. package/docs/customization/recipes.md +79 -0
  42. package/docs/customization/slots.md +55 -0
  43. package/docs/customization/tokens.md +76 -0
  44. package/docs/customization/translations.md +49 -0
  45. package/docs/frameworks/next/api-reference/data-fetching.md +416 -0
  46. package/docs/frameworks/next/app-router.md +403 -0
  47. package/docs/frameworks/next/client-side.md +118 -0
  48. package/docs/frameworks/next/components/consent-banner.md +251 -211
  49. package/docs/frameworks/next/components/consent-dialog-link.md +96 -35
  50. package/docs/frameworks/next/components/consent-dialog-trigger.md +74 -149
  51. package/docs/frameworks/next/components/consent-dialog.md +189 -134
  52. package/docs/frameworks/next/components/consent-manager-provider.md +60 -318
  53. package/docs/frameworks/next/components/consent-widget.md +172 -114
  54. package/docs/frameworks/next/components/dev-tools.md +199 -40
  55. package/docs/frameworks/next/components/frame.md +137 -42
  56. package/docs/frameworks/next/concepts/consent-categories.md +24 -89
  57. package/docs/frameworks/next/concepts/policy-presets.md +142 -0
  58. package/docs/frameworks/next/content-security-policy.md +189 -0
  59. package/docs/frameworks/next/data-fetching.md +74 -0
  60. package/docs/frameworks/next/geography-headers.md +251 -0
  61. package/docs/frameworks/next/headless.md +95 -185
  62. package/docs/frameworks/next/hooks/use-consent-manager/overview.md +42 -163
  63. package/docs/frameworks/next/iab/overview.md +37 -107
  64. package/docs/frameworks/next/optimization.md +158 -194
  65. package/docs/frameworks/next/pages-router.md +296 -0
  66. package/docs/frameworks/next/quickstart.md +31 -132
  67. package/docs/frameworks/next/script-loader.md +134 -467
  68. package/docs/frameworks/next/server-side.md +97 -130
  69. package/docs/frameworks/next/static-export.md +164 -0
  70. package/docs/frameworks/next/styling/overview.md +166 -250
  71. package/docs/frameworks/next/troubleshooting.md +134 -144
  72. package/docs/guides/consent-state.md +60 -0
  73. package/docs/guides/data-fetching.md +163 -0
  74. package/docs/guides/deployment-modes.md +63 -0
  75. package/docs/guides/troubleshooting.md +68 -0
  76. package/docs/guides/verify-consent.md +62 -0
  77. package/docs/integrations/adobe-analytics.md +239 -105
  78. package/docs/integrations/ahrefs-analytics.md +238 -104
  79. package/docs/integrations/amplitude.md +219 -157
  80. package/docs/integrations/building-integrations.md +32 -224
  81. package/docs/integrations/clearbit.md +247 -86
  82. package/docs/integrations/cloudflare-web-analytics.md +250 -84
  83. package/docs/integrations/crisp.md +251 -97
  84. package/docs/integrations/databuddy.md +259 -153
  85. package/docs/integrations/fathom-analytics.md +239 -96
  86. package/docs/integrations/google-maps.md +328 -207
  87. package/docs/integrations/google-tag-manager.md +248 -96
  88. package/docs/integrations/google-tag.md +261 -90
  89. package/docs/integrations/heap.md +222 -149
  90. package/docs/integrations/hightouch.md +225 -131
  91. package/docs/integrations/hotjar.md +239 -90
  92. package/docs/integrations/intercom.md +239 -98
  93. package/docs/integrations/linkedin-insights.md +243 -113
  94. package/docs/integrations/logrocket.md +241 -123
  95. package/docs/integrations/matomo-analytics.md +256 -111
  96. package/docs/integrations/meta-pixel.md +197 -324
  97. package/docs/integrations/microsoft-clarity.md +233 -114
  98. package/docs/integrations/microsoft-uet.md +245 -110
  99. package/docs/integrations/mixpanel-analytics.md +252 -87
  100. package/docs/integrations/openai-pixel.md +441 -0
  101. package/docs/integrations/overview.md +95 -133
  102. package/docs/integrations/pirsch.md +249 -96
  103. package/docs/integrations/plausible-analytics.md +241 -100
  104. package/docs/integrations/posthog.md +353 -214
  105. package/docs/integrations/promptwatch.md +251 -81
  106. package/docs/integrations/reddit-pixel.md +226 -173
  107. package/docs/integrations/rudderstack.md +244 -187
  108. package/docs/integrations/rybbit-analytics.md +244 -91
  109. package/docs/integrations/segment.md +238 -92
  110. package/docs/integrations/snapchat-pixel.md +240 -110
  111. package/docs/integrations/tiktok-pixel.md +249 -81
  112. package/docs/integrations/umami-analytics.md +242 -95
  113. package/docs/integrations/vercel-analytics.md +242 -90
  114. package/docs/integrations/x-pixel.md +238 -104
  115. package/docs/integrations/youtube.md +354 -142
  116. package/docs/upgrade-v3.md +334 -0
  117. package/iab/styles.css +1 -1
  118. package/iab/styles.tw3.css +1 -1
  119. package/package.json +106 -65
  120. package/readme.json +3 -3
  121. package/src/iab/styles.css +1 -1
  122. package/src/iab/styles.tw3.css +1 -1
  123. package/src/styles.css +1 -1
  124. package/src/styles.tw3.css +1 -1
  125. package/styles.css +1 -1
  126. package/styles.tw3.css +1 -1
  127. package/client/components/consent-dialog-link.js +0 -3
  128. package/client/components/integrations.js +0 -3
  129. package/dist/components/integrations/index.cjs +0 -1
  130. package/dist/components/integrations/index.js +0 -1
  131. package/dist/headless.cjs +0 -1
  132. package/dist/index.cjs +0 -1
  133. package/dist/libs/browser-initial-data.cjs +0 -1
  134. package/dist/libs/browser-initial-data.js +0 -1
  135. package/dist/libs/initial-data.cjs +0 -1
  136. package/dist/libs/initial-data.js +0 -1
  137. package/dist/types.cjs +0 -1
  138. package/dist/version.cjs +0 -1
  139. package/dist-types/components/integrations/index.d.ts +0 -1
  140. package/dist-types/libs/browser-initial-data.d.ts +0 -9
  141. package/dist-types/libs/initial-data.d.ts +0 -33
  142. package/docs/frameworks/next/building-headless-components.md +0 -379
  143. package/docs/frameworks/next/callbacks.md +0 -186
  144. package/docs/frameworks/next/concepts/client-modes.md +0 -177
  145. package/docs/frameworks/next/concepts/consent-models.md +0 -117
  146. package/docs/frameworks/next/concepts/cookie-management.md +0 -122
  147. package/docs/frameworks/next/concepts/glossary.md +0 -24
  148. package/docs/frameworks/next/concepts/initialization-flow.md +0 -149
  149. package/docs/frameworks/next/concepts/policy-packs.md +0 -230
  150. package/docs/frameworks/next/hooks/use-color-scheme.md +0 -41
  151. package/docs/frameworks/next/hooks/use-consent-manager/checking-consent.md +0 -96
  152. package/docs/frameworks/next/hooks/use-consent-manager/location-info.md +0 -97
  153. package/docs/frameworks/next/hooks/use-consent-manager/setting-consent.md +0 -94
  154. package/docs/frameworks/next/hooks/use-draggable.md +0 -59
  155. package/docs/frameworks/next/hooks/use-focus-trap.md +0 -42
  156. package/docs/frameworks/next/hooks/use-reduced-motion.md +0 -37
  157. package/docs/frameworks/next/hooks/use-ssr-status.md +0 -32
  158. package/docs/frameworks/next/hooks/use-text-direction.md +0 -50
  159. package/docs/frameworks/next/hooks/use-translations.md +0 -55
  160. package/docs/frameworks/next/iab/consent-banner.md +0 -91
  161. package/docs/frameworks/next/iab/consent-dialog.md +0 -129
  162. package/docs/frameworks/next/iab/use-gvl-data.md +0 -21
  163. package/docs/frameworks/next/iframe-blocking.md +0 -106
  164. package/docs/frameworks/next/internationalization.md +0 -207
  165. package/docs/frameworks/next/network-blocker.md +0 -140
  166. package/docs/frameworks/next/policy-packs.md +0 -248
  167. package/docs/frameworks/next/styling/classnames.md +0 -94
  168. package/docs/frameworks/next/styling/color-scheme.md +0 -84
  169. package/docs/frameworks/next/styling/css-variables.md +0 -53
  170. package/docs/frameworks/next/styling/slots.md +0 -94
  171. package/docs/frameworks/next/styling/tailwind.md +0 -137
  172. package/docs/frameworks/next/styling/tokens.md +0 -156
  173. package/docs/shared/concepts/client-modes.md +0 -103
  174. package/docs/shared/concepts/consent-categories.md +0 -41
  175. package/docs/shared/concepts/consent-models.md +0 -72
  176. package/docs/shared/concepts/cookie-management.md +0 -88
  177. package/docs/shared/concepts/glossary.md +0 -24
  178. package/docs/shared/concepts/initialization-flow.md +0 -105
  179. package/docs/shared/concepts/policy-packs.md +0 -225
  180. package/docs/shared/react/components/consent-banner.md +0 -242
  181. package/docs/shared/react/components/consent-dialog-link.md +0 -45
  182. package/docs/shared/react/components/consent-dialog-trigger.md +0 -185
  183. package/docs/shared/react/components/consent-dialog.md +0 -119
  184. package/docs/shared/react/components/consent-manager-provider.md +0 -225
  185. package/docs/shared/react/components/consent-widget.md +0 -121
  186. package/docs/shared/react/components/dev-tools.md +0 -81
  187. package/docs/shared/react/components/frame.md +0 -52
  188. package/docs/shared/react/guides/building-headless-components.md +0 -110
  189. package/docs/shared/react/guides/callbacks.md +0 -89
  190. package/docs/shared/react/guides/headless.md +0 -31
  191. package/docs/shared/react/guides/iframe-blocking.md +0 -65
  192. package/docs/shared/react/guides/internationalization.md +0 -123
  193. package/docs/shared/react/guides/network-blocker.md +0 -72
  194. package/docs/shared/react/guides/optimization.md +0 -44
  195. package/docs/shared/react/guides/policy-packs.md +0 -173
  196. package/docs/shared/react/guides/script-loader.md +0 -311
  197. package/docs/shared/react/hooks/use-color-scheme.md +0 -31
  198. package/docs/shared/react/hooks/use-consent-manager/checking-consent.md +0 -95
  199. package/docs/shared/react/hooks/use-consent-manager/location-info.md +0 -96
  200. package/docs/shared/react/hooks/use-consent-manager/overview.md +0 -74
  201. package/docs/shared/react/hooks/use-consent-manager/setting-consent.md +0 -93
  202. package/docs/shared/react/hooks/use-draggable.md +0 -30
  203. package/docs/shared/react/hooks/use-focus-trap.md +0 -20
  204. package/docs/shared/react/hooks/use-reduced-motion.md +0 -33
  205. package/docs/shared/react/hooks/use-ssr-status.md +0 -16
  206. package/docs/shared/react/hooks/use-text-direction.md +0 -38
  207. package/docs/shared/react/hooks/use-translations.md +0 -15
  208. package/docs/shared/react/iab/consent-banner.md +0 -60
  209. package/docs/shared/react/iab/consent-dialog.md +0 -76
  210. package/docs/shared/react/iab/overview.md +0 -80
  211. package/docs/shared/react/iab/use-gvl-data.md +0 -21
  212. package/docs/shared/react/styling/classnames.md +0 -93
  213. package/docs/shared/react/styling/color-scheme.md +0 -35
  214. package/docs/shared/react/styling/css-variables.md +0 -53
  215. package/docs/shared/react/styling/overview.md +0 -261
  216. package/docs/shared/react/styling/slots.md +0 -93
  217. package/docs/shared/react/styling/stylesheet-entrypoint.md +0 -8
  218. package/docs/shared/react/styling/tailwind.md +0 -88
  219. package/docs/shared/react/styling/tokens.md +0 -155
  220. package/docs/shared/troubleshooting.md +0 -82
@@ -1,311 +0,0 @@
1
- ---
2
- title: Script Loader
3
- description: Reference page for script loader.
4
- group: reference
5
- ---
6
- The script loader manages third-party JavaScript based on consent state. You declare scripts in your provider's `scripts` option, and c15t decides when each script should load, stay loaded, unload, or receive a consent update.
7
-
8
- Use it for analytics, pixels, tag managers, product analytics, and other vendor snippets that should not run until the right consent condition is satisfied. Prebuilt helpers live in [`@c15t/scripts`](/docs/integrations/overview); custom scripts can be declared directly when the vendor is specific to your app.
9
-
10
- <PackageCommandTabs mode="install" command="@c15t/scripts" />
11
-
12
- > ℹ️ **Info:**
13
- > Start with the integrations overview before writing your own script. Built-in helpers encode vendor boot order, consent updates, and common defaults so you do not have to.
14
- >
15
- > 📝 **Note:**
16
- > If you need a vendor c15t does not ship yet, see the custom integration guide. It explains when a one-off Script is enough and when to build a reusable manifest-backed helper.
17
- >
18
- > ℹ️ **Info:**
19
- > The script loader handles JavaScript tags and callback lifecycles. For iframe-only embeds, use the iframe blocking pattern. For UI components such as maps or video players, combine consent state with a component-level placeholder or a dedicated renderable integration.
20
-
21
- ## Mental Model
22
-
23
- Every script you register has the same lifecycle. c15t evaluates each script against the current consent state, then drives it through a small number of states:
24
-
25
- 1. **Pending** — registered but waiting for consent. Nothing is in the DOM yet.
26
- 2. **Loaded** — consent matched, c15t injected the script (or ran callbacks for callback-only scripts).
27
- 3. **Updated** — already loaded, consent state changed, `onConsentChange` ran so the SDK can react.
28
- 4. **Unloaded** — consent was revoked. c15t removed the script element unless you opted into persistence.
29
-
30
- Four lifecycle callbacks let you hook into transitions: `onBeforeLoad`, `onLoad`, `onConsentChange`, and `onError`. Two flags — [`alwaysLoad`](#always-load) and [`persistAfterConsentRevoked`](#persist-after-revocation) — change how c15t treats consent boundaries. Everything else (DOM placement, ad-block evasion, dynamic management) is a refinement on top of this core model.
31
-
32
- ## Choose the Right Approach
33
-
34
- Most projects mix more than one style. Pick the smallest one that keeps consent behavior obvious:
35
-
36
- |Style|Use when|
37
- |--|--|
38
- |**Built-in helper** from `@c15t/scripts`|c15t already ships the vendor. See the [integrations overview](/docs/integrations/overview).|
39
- |**Plain `Script`**|One-off app code with simple load and callback behavior.|
40
- |**Callback-only `Script`**|Another package already loaded the SDK; c15t only synchronizes consent.|
41
- |**Manifest-backed helper**|Reusable vendor integration with structured setup phases, queues, stubs, or a vendor consent API.|
42
- |**Iframe / renderable integration**|Vendor exposes an iframe or React component, not just a `<script>` tag.|
43
-
44
- ## Script Types
45
-
46
- ### Standard Scripts
47
-
48
- Standard scripts load an external JavaScript file via a `<script>` tag. This is the default for most analytics and pixel SDKs:
49
-
50
- ```tsx
51
- {
52
- id: 'analytics',
53
- src: 'https://cdn.example.com/analytics.js',
54
- category: 'measurement',
55
- }
56
- ```
57
-
58
- ### Inline Scripts
59
-
60
- Inline scripts execute JavaScript from `textContent` instead of loading a URL. Use these sparingly; a manifest-backed helper is usually better for reusable vendor code.
61
-
62
- ```tsx
63
- {
64
- id: 'gtag-config',
65
- textContent: `
66
- window.dataLayer = window.dataLayer || [];
67
- function gtag(){dataLayer.push(arguments);}
68
- gtag('js', new Date());
69
- gtag('config', 'G-XXXXXX');
70
- `,
71
- category: 'measurement',
72
- }
73
- ```
74
-
75
- ### Callback-Only Scripts
76
-
77
- Callback-only scripts do not inject a script tag. They run lifecycle callbacks when consent allows them to. Use this when another package has already loaded the SDK and c15t only needs to drive consent:
78
-
79
- ```tsx
80
- {
81
- id: 'posthog-consent',
82
- callbackOnly: true,
83
- category: 'measurement',
84
- onLoad: ({ hasConsent }) => {
85
- if (hasConsent) {
86
- posthog.opt_in_capturing();
87
- }
88
- },
89
- onConsentChange: ({ hasConsent }) => {
90
- if (hasConsent) {
91
- posthog.opt_in_capturing();
92
- } else {
93
- posthog.opt_out_capturing();
94
- }
95
- },
96
- }
97
- ```
98
-
99
- ### Manifest-Backed Helpers
100
-
101
- Built-in integrations in `@c15t/scripts` are manifest-backed. A manifest describes vendor setup as structured phases, then c15t compiles it into a `Script`. Manifests keep queue stubs, script URLs, consent signaling, and post-load work consistent across apps and they are safe to ship from a server.
102
-
103
- Use a manifest-backed helper when:
104
-
105
- * the integration should be reused across projects,
106
- * the vendor snippet has ordered setup steps,
107
- * the vendor exposes a consent API,
108
- * or you plan to contribute the integration back to c15t.
109
-
110
- Read the [custom integration guide](/docs/integrations/building-integrations) for the manifest contract, phases, and testing checklist.
111
-
112
- ### Iframe And Renderable Integrations
113
-
114
- Some vendors are not just script tags. YouTube embeds, maps, calendars, and checkout widgets often need a visible component, a placeholder, or an iframe.
115
-
116
- * For iframe-only embeds, gate the iframe `src` with the [iframe blocking](/docs/frameworks/react/iframe-blocking) pattern instead of loading a script just to hide an iframe.
117
- * For SDK-backed UI, use the script loader for the shared SDK and render the component only when consent and SDK readiness agree.
118
- * Use `YouTubeEmbed` for the iframe-only YouTube candidate and `GoogleMap` for the callback-based SDK candidate.
119
- * Use `useConsentScript()` when building custom wrappers. It registers scripts through the consent store, follows `loadedScripts`, and returns a promise-shaped readiness contract for callback-based SDKs.
120
-
121
- ## Lifecycle Callbacks
122
-
123
- Every script supports four callbacks. Each receives a `ScriptCallbackInfo` payload (id, element, hasConsent, consents):
124
-
125
- * `onBeforeLoad` — runs before the script tag is injected. Create globals, queues, or vendor stubs here.
126
- * `onLoad` — runs after the browser loads the script. Call vendor `init()` APIs here.
127
- * `onConsentChange` — runs for loaded scripts when consent changes. Forward the new consent state to the vendor SDK.
128
- * `onError` — runs when the script fails to load. Record diagnostics or render a fallback.
129
-
130
- ```tsx
131
- {
132
- id: 'analytics',
133
- src: 'https://analytics.example.com/v2.js',
134
- category: 'measurement',
135
- onBeforeLoad: ({ id }) => {
136
- window.analyticsQueue = window.analyticsQueue || [];
137
- },
138
- onLoad: () => {
139
- window.analytics.init('my-key');
140
- },
141
- onError: ({ error }) => {
142
- console.error('Failed to load analytics:', error);
143
- },
144
- onConsentChange: ({ hasConsent }) => {
145
- window.analytics.setConsent(hasConsent);
146
- },
147
- }
148
- ```
149
-
150
- ## Consent Conditions
151
-
152
- The `category` field accepts a `HasCondition`. It can be a single consent category or a logical expression:
153
-
154
- ```tsx
155
- // Simple: requires measurement consent
156
- { category: 'measurement' }
157
-
158
- // AND: requires both measurement and marketing
159
- { category: { and: ['measurement', 'marketing'] } }
160
-
161
- // OR: requires either measurement or marketing
162
- { category: { or: ['measurement', 'marketing'] } }
163
- ```
164
-
165
- Consent categories use the same names as the rest of c15t (`necessary`, `functionality`, `experience`, `measurement`, `marketing`).
166
-
167
- ## Persistence Options
168
-
169
- ### Always Load
170
-
171
- `alwaysLoad` loads the script regardless of whether its category is currently granted. Use it only when the vendor must be present early **and** has a reliable consent API of its own — Google Tag Manager with Consent Mode is the canonical example.
172
-
173
- ```tsx
174
- {
175
- id: 'google-tag-manager',
176
- src: 'https://www.googletagmanager.com/gtm.js?id=GTM-XXXX',
177
- category: 'measurement',
178
- alwaysLoad: true,
179
- }
180
- ```
181
-
182
- When `alwaysLoad` is on, `onConsentChange` becomes mandatory: it is how the loaded SDK learns about every transition.
183
-
184
- > ⚠️ **Warning:**
185
- > alwaysLoad shifts compliance responsibility to the vendor integration. Make sure the script receives denied-by-default consent signals before it can track.
186
-
187
- ### Persist After Revocation
188
-
189
- `persistAfterConsentRevoked` keeps a script in the page after consent is revoked instead of unloading it. Use it only when the vendor exposes a runtime consent toggle — otherwise unloading is safer because removing the element guarantees the SDK stops.
190
-
191
- ```tsx
192
- {
193
- id: 'error-tracking',
194
- src: 'https://errors.example.com/track.js',
195
- category: 'measurement',
196
- persistAfterConsentRevoked: true,
197
- onConsentChange: ({ hasConsent }) => {
198
- window.ErrorTracker.setConsent(hasConsent);
199
- },
200
- }
201
- ```
202
-
203
- As with `alwaysLoad`, `onConsentChange` is how the persisted SDK learns about consent updates.
204
-
205
- ### `alwaysLoad` vs `persistAfterConsentRevoked`
206
-
207
- These two flags answer different questions. Use this table to keep them straight:
208
-
209
- |Question|`alwaysLoad`|`persistAfterConsentRevoked`|
210
- |--|--|--|
211
- |Loads before consent is granted?|Yes|No (waits for consent like a normal script)|
212
- |Stays loaded after consent is revoked?|Yes|Yes|
213
- |Requires a vendor consent API?|Yes|Yes|
214
-
215
- ## DOM Placement
216
-
217
- Control where the script is injected and whether the element id is anonymized:
218
-
219
- ```tsx
220
- {
221
- id: 'widget',
222
- src: 'https://widget.example.com/embed.js',
223
- category: 'experience',
224
- target: 'body', // 'head' (default) or 'body'
225
- anonymizeId: true, // default: true, hides the c15t script id from ad blockers
226
- nonce: 'abc123', // optional CSP nonce
227
- }
228
- ```
229
-
230
- Set `anonymizeId: false` only when another script or test needs a stable DOM id. Pass `nonce` when your CSP requires it; c15t applies it directly to the generated `<script>` element.
231
-
232
- You usually do not need a per-script `nonce`. Setting `nonce` once on the provider covers every injected script (and the theme stylesheet); a per-script value overrides it for that script alone.
233
-
234
- ## Dynamic Management
235
-
236
- Framework packages expose script-manager methods so integrations can be added, removed, or inspected at runtime. Use this for tenant-specific tools, feature-flagged scripts, or vendors that are configured after sign-in:
237
-
238
- * `setScripts(scripts)` — registers script definitions and immediately evaluates them against consent.
239
- * `removeScript(id)` — removes a definition and unloads its element if needed.
240
- * `isScriptLoaded(id)` — returns whether c15t has loaded a script.
241
- * `getLoadedScriptIds()` — returns every currently loaded script id.
242
-
243
- Dynamic scripts should still use stable ids. If the same vendor is added repeatedly with different ids, c15t treats each call as a new script.
244
-
245
- ## Calling Vendor APIs From Your App
246
-
247
- The script loader controls **when the vendor SDK loads**. It does not intercept calls your application code makes to that SDK afterwards. Whether your event calls are safe before consent is granted depends on the script's persistence flags:
248
-
249
- |Vendor pattern|What c15t does|What your app code must do|
250
- |--|--|--|
251
- |Consent-gated load, unloaded on revoke (e.g. cookieless analytics)|Script not in DOM until consent granted; removed on revoke. Global is `undefined` outside that window.|**Guard every call.** Unguarded `window.vendor.track(...)` throws when the global is absent.|
252
- |Consent-gated load with `persistAfterConsentRevoked` (e.g. Meta Pixel)|Script not in DOM until consent granted; stays after revoke. c15t calls vendor's consent-revoke API on revocation.|Guard calls only for the pre-initial-consent window. Once loaded, the SDK handles its own suppression.|
253
- |`alwaysLoad: true` with a vendor consent API (e.g. GTM, gtag, Databuddy, PostHog)|Script in DOM on page start; c15t signals consent state through the vendor's API.|Calls are safe — the vendor SDK suppresses transmission when consent is denied.|
254
- |No app-facing API (e.g. Cloudflare Web Analytics)|Script in/out of DOM based on consent. Tracking is fully automatic.|Nothing to guard.|
255
-
256
- The safe pattern in React is to read consent state through `useConsentManager().has(category)` before calling the SDK:
257
-
258
- ```tsx
259
- import { useCallback } from 'react';
260
- import { useConsentManager } from '@c15t/react';
261
-
262
- function useTrackSignup() {
263
- const { has } = useConsentManager();
264
-
265
- return useCallback(() => {
266
- if (has('measurement')) {
267
- window.fathom?.trackEvent('signup');
268
- }
269
- }, [has]);
270
- }
271
-
272
- function SignupButton() {
273
- const trackSignup = useTrackSignup();
274
-
275
- return <button onClick={trackSignup}>Sign up</button>;
276
- }
277
- ```
278
-
279
- From non-React code, read the consent store directly:
280
-
281
- ```ts
282
- import { getOrCreateConsentRuntime } from 'c15t';
283
-
284
- const { consentStore } = getOrCreateConsentRuntime();
285
-
286
- if (consentStore.getState().has('measurement')) {
287
- window.fathom?.trackEvent('signup');
288
- }
289
- ```
290
-
291
- Each [integration page](/docs/integrations/overview) includes a vendor-specific **Tracking events in your app** block that names which pattern applies.
292
-
293
- ## Debugging Checklist
294
-
295
- When a script does not behave as expected:
296
-
297
- 1. Confirm the script's `category` matches the consent that has been granted.
298
- 2. Check whether the script is `alwaysLoad` or consent-gated.
299
- 3. Confirm `onBeforeLoad` creates any globals before the vendor code reads them.
300
- 4. Confirm `onConsentChange` updates persisted or always-loaded scripts when consent changes.
301
- 5. Check whether the browser or an ad blocker blocked the request.
302
- 6. Use c15t devtools to inspect script lifecycle events when available.
303
-
304
- ## API Reference
305
-
306
- |Property|Value|
307
- |:--|:--|
308
- |Type Name|\`Script\`|
309
- |Source Path|\`./packages/core/src/libs/script-loader/types.ts\`|
310
-
311
- \*ExtractedTypeTable: Could not extract "Script" from "./packages/core/src/libs/script-loader/types.ts" using base path "/home/runner/work/c15t/c15t". Verify the path/name and that the file is included by your tsconfig.\*
@@ -1,31 +0,0 @@
1
- ---
2
- title: Use Color Scheme
3
- description: Reference page for use color scheme.
4
- group: reference
5
- ---
6
- ## Parameters
7
-
8
- |Value|Behavior|
9
- |--|--|
10
- |`'light'`|Force light mode|
11
- |`'dark'`|Force dark mode|
12
- |`'system'`|Follow `prefers-color-scheme` media query|
13
- |`null`|Disable - c15t won't manage color scheme|
14
- |`undefined`|No-op|
15
-
16
- ## Provider-Level Configuration
17
-
18
- You can also set the color scheme on the provider without using this hook:
19
-
20
- ```tsx
21
- <ConsentManagerProvider
22
- options={{
23
- colorScheme: 'system',
24
- // ...
25
- }}
26
- >
27
- ```
28
-
29
- ## System Preference Detection
30
-
31
- When set to `'system'`, the hook listens for changes to the `prefers-color-scheme` media query and updates automatically when the user changes their OS theme.
@@ -1,95 +0,0 @@
1
- ---
2
- title: Checking Consent
3
- description: Reference page for checking consent.
4
- group: reference
5
- ---
6
- ## has(condition)
7
-
8
- The `has()` method evaluates whether the current consent state satisfies a condition. It supports simple category checks and complex logical expressions.
9
-
10
- ### Simple Check
11
-
12
- ```tsx
13
- const { has } = useConsentManager();
14
-
15
- if (has('measurement')) {
16
- // User has granted measurement consent
17
- }
18
- ```
19
-
20
- ### AND Logic
21
-
22
- All conditions must be true:
23
-
24
- ```tsx
25
- has({ and: ['measurement', 'marketing'] })
26
- // true only if BOTH measurement AND marketing are granted
27
- ```
28
-
29
- ### OR Logic
30
-
31
- At least one condition must be true:
32
-
33
- ```tsx
34
- has({ or: ['measurement', 'marketing'] })
35
- // true if EITHER measurement OR marketing is granted
36
- ```
37
-
38
- ### NOT Logic
39
-
40
- Negates a condition:
41
-
42
- ```tsx
43
- has({ not: 'marketing' })
44
- // true if marketing consent is NOT granted
45
- ```
46
-
47
- ### Nested Conditions
48
-
49
- Combine operators for complex logic:
50
-
51
- ```tsx
52
- has({
53
- and: [
54
- 'necessary',
55
- { or: ['measurement', 'marketing'] },
56
- { not: 'functionality' },
57
- ],
58
- })
59
- // true if: necessary AND (measurement OR marketing) AND NOT functionality
60
- ```
61
-
62
- ### HasCondition Type
63
-
64
- ```ts
65
- type HasCondition<CategoryType> =
66
- | CategoryType // "measurement"
67
- | { and: HasCondition[] | HasCondition } // { and: ["a", "b"] }
68
- | { or: HasCondition[] | HasCondition } // { or: ["a", "b"] }
69
- | { not: HasCondition } // { not: "a" }
70
- ```
71
-
72
- ## hasConsented()
73
-
74
- Returns `true` if the user has made any consent choice (accepted, rejected, or customized). Returns `false` if no consent has been recorded yet.
75
-
76
- ```tsx
77
- const { hasConsented } = useConsentManager();
78
-
79
- if (hasConsented()) {
80
- // User has previously made a consent choice
81
- } else {
82
- // First visit — no consent recorded
83
- }
84
- ```
85
-
86
- ## getDisplayedConsents()
87
-
88
- Returns the consent types that should be displayed in the UI (based on active `consentCategories` and each type's `display` property):
89
-
90
- ```tsx
91
- const { getDisplayedConsents } = useConsentManager();
92
-
93
- const visibleCategories = getDisplayedConsents();
94
- // Returns ConsentType[] with name, description, defaultValue, etc.
95
- ```
@@ -1,96 +0,0 @@
1
- ---
2
- title: Location Info
3
- description: Reference page for location info.
4
- group: reference
5
- ---
6
- ## locationInfo
7
-
8
- The `locationInfo` state contains the user's detected geographic information:
9
-
10
- ```tsx
11
- const { locationInfo } = useConsentManager();
12
-
13
- if (locationInfo) {
14
- console.log(locationInfo.jurisdiction); // 'GDPR', 'CCPA', etc.
15
- console.log(locationInfo.countryCode); // 'DE', 'US', etc.
16
- console.log(locationInfo.regionCode); // 'BY', 'CA', etc.
17
- }
18
- ```
19
-
20
- `locationInfo` is `null` until the backend responds with geolocation data (or in offline mode if no overrides are set).
21
-
22
- ## Jurisdiction Codes
23
-
24
- |Code|Region|Consent Model|
25
- |--|--|--|
26
- |`GDPR`|European Union|opt-in|
27
- |`UK_GDPR`|United Kingdom|opt-in|
28
- |`CH`|Switzerland|opt-in|
29
- |`BR`|Brazil (LGPD)|opt-in|
30
- |`APPI`|Japan|opt-in|
31
- |`PIPA`|South Korea|opt-in|
32
- |`PIPEDA`|Canada (excl. Quebec)|opt-out|
33
- |`QC_LAW25`|Quebec, Canada|opt-in|
34
- |`CCPA`|California, USA|opt-out|
35
- |`AU`|Australia|opt-out|
36
- |`NONE`|No jurisdiction|null model|
37
-
38
- ## setOverrides()
39
-
40
- Override detected values for testing or manual configuration. This triggers a re-fetch of consent banner data with the new values:
41
-
42
- ```tsx
43
- const { setOverrides } = useConsentManager();
44
-
45
- // Override country (triggers jurisdiction detection)
46
- await setOverrides({ country: 'DE' });
47
-
48
- // Override language
49
- await setOverrides({ language: 'de' });
50
-
51
- // Override both
52
- await setOverrides({ country: 'US', region: 'CA', language: 'es' });
53
- ```
54
-
55
- ## setLocationInfo()
56
-
57
- Directly set location info without triggering a re-fetch:
58
-
59
- ```tsx
60
- const { setLocationInfo } = useConsentManager();
61
-
62
- setLocationInfo({
63
- jurisdiction: 'GDPR',
64
- countryCode: 'DE',
65
- regionCode: 'BY',
66
- });
67
- ```
68
-
69
- ## Testing Different Jurisdictions
70
-
71
- A development-only component for testing consent behavior across jurisdictions:
72
-
73
- ```tsx
74
- function JurisdictionTester() {
75
- const { setOverrides, model, locationInfo } = useConsentManager();
76
-
77
- const testCases = [
78
- { label: 'GDPR', country: 'DE' },
79
- { label: 'CCPA', country: 'US', region: 'CA' },
80
- { label: 'PIPEDA', country: 'CA', region: undefined },
81
- { label: 'QC_LAW25', country: 'CA', region: 'QC' },
82
- { label: 'NONE', country: 'US', region: 'TX' },
83
- ];
84
-
85
- return (
86
- <div>
87
- <p>Current: {locationInfo?.jurisdiction ?? 'none'} → model: {model}</p>
88
- {testCases.map((tc) => (
89
- <button key={tc.label} onClick={() => setOverrides({ country: tc.country, region: tc.region })}>
90
- Test as {tc.label}
91
- </button>
92
- ))}
93
- </div>
94
- );
95
- }
96
- ```
@@ -1,74 +0,0 @@
1
- ---
2
- title: Overview
3
- description: Reference page for overview.
4
- group: reference
5
- ---
6
- > ⚠️ **Warning:**
7
- > Must be used within a ConsentManagerProvider. Throws an error if used outside the provider.
8
-
9
- ## State Properties
10
-
11
- |Property|Value|
12
- |:--|:--|
13
- |Type Name|\`StoreRuntimeState\`|
14
- |Source Path|\`./packages/core/src/store/type.ts\`|
15
-
16
- \*ExtractedTypeTable: Could not extract "StoreRuntimeState" from "./packages/core/src/store/type.ts" using base path "/home/runner/work/c15t/c15t". Verify the path/name and that the file is included by your tsconfig.\*
17
-
18
- ## Action Methods
19
-
20
- |Property|Value|
21
- |:--|:--|
22
- |Type Name|\`StoreActions\`|
23
- |Source Path|\`./packages/core/src/store/type.ts\`|
24
-
25
- \*ExtractedTypeTable: Could not extract "StoreActions" from "./packages/core/src/store/type.ts" using base path "/home/runner/work/c15t/c15t". Verify the path/name and that the file is included by your tsconfig.\*
26
-
27
- ## Key Types
28
-
29
- ### ConsentState
30
-
31
- A record mapping consent category names to their boolean values:
32
-
33
- ```ts
34
- type ConsentState = Record<AllConsentNames, boolean>;
35
- // Example: { necessary: true, measurement: true, marketing: false }
36
- ```
37
-
38
- ### ConsentInfo
39
-
40
- Metadata about when and how consent was recorded:
41
-
42
- ```ts
43
- interface ConsentInfo {
44
- time: number; // Epoch timestamp when consent was recorded
45
- subjectId?: string; // Client-generated subject ID (sub_xxx format)
46
- externalId?: string; // External user ID linked via identifyUser()
47
- identityProvider?: string; // Identity provider (e.g. 'clerk', 'auth0')
48
- }
49
- ```
50
-
51
- ### LocationInfo
52
-
53
- Detected geographic location from the c15t backend:
54
-
55
- ```ts
56
- interface LocationInfo {
57
- countryCode: string; // ISO 3166-1 alpha-2 (e.g. 'DE')
58
- regionCode: string; // Region/state code (e.g. 'BY')
59
- jurisdiction: string; // Applicable jurisdiction (e.g. 'GDPR', 'CCPA')
60
- }
61
- ```
62
-
63
- ### Model
64
-
65
- The active consent model:
66
-
67
- ```ts
68
- type Model = 'opt-in' | 'opt-out' | 'iab' | null;
69
- ```
70
-
71
- * `'opt-in'` — Explicit consent required before tracking (GDPR)
72
- * `'opt-out'` — Tracking allowed by default, user can opt out (CCPA)
73
- * `'iab'` — IAB TCF 2.3 compliance mode
74
- * `null` — No jurisdiction detected yet