@c15t/nextjs 2.1.0 → 2.2.1

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 (162) hide show
  1. package/AGENTS.md +155 -0
  2. package/README.md +31 -15
  3. package/client/components/integrations.js +3 -0
  4. package/dist/components/integrations/index.cjs +1 -0
  5. package/dist/components/integrations/index.js +1 -0
  6. package/dist/headless.cjs +1 -1
  7. package/dist/index.cjs +1 -1
  8. package/dist/libs/browser-initial-data.cjs +1 -1
  9. package/dist/libs/initial-data.cjs +1 -1
  10. package/dist/styles.tw3.css +1 -1
  11. package/dist/version.cjs +1 -1
  12. package/dist/version.js +1 -1
  13. package/dist-types/components/integrations/index.d.ts +1 -0
  14. package/dist-types/libs/browser-initial-data.d.ts +1 -1
  15. package/dist-types/version.d.ts +1 -1
  16. package/docs/README.md +155 -73
  17. package/docs/{building-headless-components.md → frameworks/next/building-headless-components.md} +3 -1
  18. package/docs/{callbacks.md → frameworks/next/callbacks.md} +3 -1
  19. package/docs/{components → frameworks/next/components}/consent-banner.md +10 -21
  20. package/docs/{components → frameworks/next/components}/consent-dialog-link.md +8 -5
  21. package/docs/frameworks/next/components/consent-dialog-trigger.md +202 -0
  22. package/docs/{components → frameworks/next/components}/consent-dialog.md +7 -15
  23. package/docs/frameworks/next/components/consent-manager-provider.md +327 -0
  24. package/docs/{components → frameworks/next/components}/consent-widget.md +8 -6
  25. package/docs/{components → frameworks/next/components}/dev-tools.md +9 -6
  26. package/docs/{components → frameworks/next/components}/frame.md +8 -9
  27. package/docs/{concepts → frameworks/next/concepts}/client-modes.md +4 -2
  28. package/docs/{concepts → frameworks/next/concepts}/consent-categories.md +1 -0
  29. package/docs/{concepts → frameworks/next/concepts}/consent-models.md +1 -0
  30. package/docs/{concepts → frameworks/next/concepts}/cookie-management.md +3 -3
  31. package/docs/{concepts → frameworks/next/concepts}/glossary.md +1 -0
  32. package/docs/{concepts → frameworks/next/concepts}/initialization-flow.md +1 -0
  33. package/docs/{concepts → frameworks/next/concepts}/policy-packs.md +1 -0
  34. package/docs/{headless.md → frameworks/next/headless.md} +3 -1
  35. package/docs/{hooks → frameworks/next/hooks}/use-color-scheme.md +1 -0
  36. package/docs/{hooks → frameworks/next/hooks}/use-consent-manager/checking-consent.md +3 -1
  37. package/docs/{hooks → frameworks/next/hooks}/use-consent-manager/location-info.md +3 -1
  38. package/docs/frameworks/next/hooks/use-consent-manager/overview.md +185 -0
  39. package/docs/{hooks → frameworks/next/hooks}/use-consent-manager/setting-consent.md +3 -1
  40. package/docs/{hooks → frameworks/next/hooks}/use-draggable.md +3 -1
  41. package/docs/{hooks → frameworks/next/hooks}/use-focus-trap.md +1 -0
  42. package/docs/{hooks → frameworks/next/hooks}/use-reduced-motion.md +3 -1
  43. package/docs/{hooks → frameworks/next/hooks}/use-ssr-status.md +6 -5
  44. package/docs/{hooks → frameworks/next/hooks}/use-text-direction.md +1 -0
  45. package/docs/frameworks/next/hooks/use-translations.md +55 -0
  46. package/docs/{iab → frameworks/next/iab}/consent-banner.md +9 -12
  47. package/docs/{iab → frameworks/next/iab}/consent-dialog.md +9 -14
  48. package/docs/{iab → frameworks/next/iab}/overview.md +4 -2
  49. package/docs/{iab → frameworks/next/iab}/use-gvl-data.md +3 -2
  50. package/docs/{iframe-blocking.md → frameworks/next/iframe-blocking.md} +8 -9
  51. package/docs/{internationalization.md → frameworks/next/internationalization.md} +13 -3
  52. package/docs/{network-blocker.md → frameworks/next/network-blocker.md} +13 -51
  53. package/docs/{optimization.md → frameworks/next/optimization.md} +5 -4
  54. package/docs/{policy-packs.md → frameworks/next/policy-packs.md} +3 -1
  55. package/docs/{quickstart.md → frameworks/next/quickstart.md} +26 -42
  56. package/docs/{script-loader.md → frameworks/next/script-loader.md} +72 -90
  57. package/docs/{server-side.md → frameworks/next/server-side.md} +12 -15
  58. package/docs/{styling → frameworks/next/styling}/classnames.md +3 -1
  59. package/docs/{styling → frameworks/next/styling}/color-scheme.md +3 -1
  60. package/docs/frameworks/next/styling/css-variables.md +53 -0
  61. package/docs/frameworks/next/styling/overview.md +299 -0
  62. package/docs/frameworks/next/styling/slots.md +94 -0
  63. package/docs/{styling → frameworks/next/styling}/tailwind.md +3 -1
  64. package/docs/frameworks/next/styling/tokens.md +156 -0
  65. package/docs/{troubleshooting.md → frameworks/next/troubleshooting.md} +3 -1
  66. package/docs/integrations/adobe-analytics.md +160 -0
  67. package/docs/integrations/ahrefs-analytics.md +15 -82
  68. package/docs/integrations/amplitude.md +230 -0
  69. package/docs/integrations/building-integrations.md +15 -181
  70. package/docs/integrations/clearbit.md +130 -0
  71. package/docs/integrations/cloudflare-web-analytics.md +15 -83
  72. package/docs/integrations/crisp.md +13 -87
  73. package/docs/integrations/databuddy.md +16 -85
  74. package/docs/integrations/fathom-analytics.md +15 -86
  75. package/docs/integrations/google-maps.md +263 -0
  76. package/docs/integrations/google-tag-manager.md +18 -86
  77. package/docs/integrations/google-tag.md +15 -84
  78. package/docs/integrations/heap.md +219 -0
  79. package/docs/integrations/hightouch.md +199 -0
  80. package/docs/integrations/hotjar.md +15 -83
  81. package/docs/integrations/intercom.md +13 -83
  82. package/docs/integrations/linkedin-insights.md +15 -82
  83. package/docs/integrations/logrocket.md +175 -0
  84. package/docs/integrations/matomo-analytics.md +13 -88
  85. package/docs/integrations/meta-pixel.md +33 -316
  86. package/docs/integrations/microsoft-clarity.md +15 -83
  87. package/docs/integrations/microsoft-uet.md +16 -83
  88. package/docs/integrations/mixpanel-analytics.md +15 -83
  89. package/docs/integrations/overview.md +55 -6
  90. package/docs/integrations/pirsch.md +142 -0
  91. package/docs/integrations/plausible-analytics.md +14 -97
  92. package/docs/integrations/posthog.md +26 -98
  93. package/docs/integrations/promptwatch.md +16 -82
  94. package/docs/integrations/reddit-pixel.md +27 -122
  95. package/docs/integrations/rudderstack.md +271 -0
  96. package/docs/integrations/rybbit-analytics.md +15 -94
  97. package/docs/integrations/segment.md +15 -82
  98. package/docs/integrations/snapchat-pixel.md +21 -102
  99. package/docs/integrations/tiktok-pixel.md +13 -81
  100. package/docs/integrations/umami-analytics.md +16 -88
  101. package/docs/integrations/vercel-analytics.md +13 -85
  102. package/docs/integrations/x-pixel.md +27 -102
  103. package/docs/integrations/youtube.md +193 -0
  104. package/docs/shared/concepts/client-modes.md +103 -0
  105. package/docs/shared/concepts/consent-categories.md +41 -0
  106. package/docs/shared/concepts/consent-models.md +72 -0
  107. package/docs/shared/concepts/cookie-management.md +88 -0
  108. package/docs/shared/concepts/glossary.md +24 -0
  109. package/docs/shared/concepts/initialization-flow.md +105 -0
  110. package/docs/shared/concepts/policy-packs.md +225 -0
  111. package/docs/shared/react/components/consent-banner.md +242 -0
  112. package/docs/shared/react/components/consent-dialog-link.md +45 -0
  113. package/docs/shared/react/components/consent-dialog-trigger.md +185 -0
  114. package/docs/shared/react/components/consent-dialog.md +119 -0
  115. package/docs/shared/react/components/consent-manager-provider.md +225 -0
  116. package/docs/shared/react/components/consent-widget.md +121 -0
  117. package/docs/shared/react/components/dev-tools.md +81 -0
  118. package/docs/shared/react/components/frame.md +52 -0
  119. package/docs/shared/react/guides/building-headless-components.md +110 -0
  120. package/docs/shared/react/guides/callbacks.md +89 -0
  121. package/docs/shared/react/guides/headless.md +31 -0
  122. package/docs/shared/react/guides/iframe-blocking.md +65 -0
  123. package/docs/shared/react/guides/internationalization.md +123 -0
  124. package/docs/shared/react/guides/network-blocker.md +72 -0
  125. package/docs/shared/react/guides/optimization.md +44 -0
  126. package/docs/shared/react/guides/policy-packs.md +173 -0
  127. package/docs/shared/react/guides/script-loader.md +311 -0
  128. package/docs/shared/react/hooks/use-color-scheme.md +31 -0
  129. package/docs/shared/react/hooks/use-consent-manager/checking-consent.md +95 -0
  130. package/docs/shared/react/hooks/use-consent-manager/location-info.md +96 -0
  131. package/docs/shared/react/hooks/use-consent-manager/overview.md +74 -0
  132. package/docs/shared/react/hooks/use-consent-manager/setting-consent.md +93 -0
  133. package/docs/shared/react/hooks/use-draggable.md +30 -0
  134. package/docs/shared/react/hooks/use-focus-trap.md +20 -0
  135. package/docs/shared/react/hooks/use-reduced-motion.md +33 -0
  136. package/docs/shared/react/hooks/use-ssr-status.md +16 -0
  137. package/docs/shared/react/hooks/use-text-direction.md +38 -0
  138. package/docs/shared/react/hooks/use-translations.md +15 -0
  139. package/docs/shared/react/iab/consent-banner.md +60 -0
  140. package/docs/shared/react/iab/consent-dialog.md +76 -0
  141. package/docs/shared/react/iab/overview.md +80 -0
  142. package/docs/shared/react/iab/use-gvl-data.md +21 -0
  143. package/docs/shared/react/styling/classnames.md +93 -0
  144. package/docs/shared/react/styling/color-scheme.md +35 -0
  145. package/docs/shared/react/styling/css-variables.md +53 -0
  146. package/docs/shared/react/styling/overview.md +261 -0
  147. package/docs/shared/react/styling/slots.md +93 -0
  148. package/docs/shared/react/styling/stylesheet-entrypoint.md +8 -0
  149. package/docs/shared/react/styling/tailwind.md +88 -0
  150. package/docs/shared/react/styling/tokens.md +155 -0
  151. package/docs/shared/troubleshooting.md +82 -0
  152. package/package.json +19 -10
  153. package/readme.json +14 -8
  154. package/docs/ai-agents.md +0 -111
  155. package/docs/components/consent-dialog-trigger.md +0 -103
  156. package/docs/components/consent-manager-provider.md +0 -425
  157. package/docs/hooks/use-consent-manager/overview.md +0 -420
  158. package/docs/hooks/use-translations.md +0 -118
  159. package/docs/styling/css-variables.md +0 -92
  160. package/docs/styling/overview.md +0 -457
  161. package/docs/styling/slots.md +0 -128
  162. package/docs/styling/tokens.md +0 -216
@@ -0,0 +1,173 @@
1
+ ---
2
+ title: Policy Packs
3
+ description: Reference page for policy packs.
4
+ group: reference
5
+ ---
6
+ Policy packs configure how c15t handles regional consent — which model (opt-in, opt-out, none), which categories, and what UI to show. The backend resolves the right policy automatically based on the visitor's location.
7
+
8
+ **For most apps, you just need a `ConsentManagerProvider` pointing at your backend with presets configured there.** The frontend receives the resolved policy via the `/init` response — no client-side policy config required.
9
+
10
+ When a backend isn't available — local development, static previews, Storybook, automated tests, or as a resilience fallback during a temporary outage — you can pass policies directly to the provider via `offlinePolicy.policyPacks` and c15t resolves them locally.
11
+
12
+ > ℹ️ **Info:**
13
+ > For QA and testing, use the c15t DevTools to simulate different regions and policy responses against your real backend, rather than switching to offline mode.
14
+
15
+ ## Hosted Mode (Recommended)
16
+
17
+ When using inth.com or a self-hosted backend, the provider connects automatically. No policy configuration is needed on the frontend:
18
+
19
+ ```tsx
20
+ <ConsentManagerProvider
21
+ options={{
22
+ backendURL: 'https://your-instance.c15t.dev',
23
+ }}
24
+ >
25
+ <ConsentBanner />
26
+ <ConsentDialog />
27
+ {children}
28
+ </ConsentManagerProvider>
29
+ ```
30
+
31
+ The backend resolves the correct policy based on the visitor's geo data and returns it in the `/init` response. Configure your presets on the backend side.
32
+
33
+ ## Offline Presets (Development and Fallback)
34
+
35
+ Use offline presets mainly for local development, Storybook, deterministic tests, or temporary backend outages:
36
+
37
+ ```tsx
38
+ import { policyPackPresets } from '@c15t/react';
39
+
40
+ offlinePolicy: {
41
+ i18n: {
42
+ defaultProfile: 'default',
43
+ messages: {
44
+ default: {
45
+ translations: {
46
+ en: { cookieBanner: { title: 'Privacy choices' } },
47
+ },
48
+ },
49
+ eu: {
50
+ fallbackLanguage: 'en',
51
+ translations: {
52
+ en: { cookieBanner: { title: 'EU GDPR Consent' } },
53
+ fr: { cookieBanner: { title: 'Consentement RGPD' } },
54
+ de: { cookieBanner: { title: 'GDPR-Einwilligung' } },
55
+ },
56
+ },
57
+ },
58
+ },
59
+ policyPacks: [
60
+ {
61
+ ...policyPackPresets.europeOptIn(),
62
+ i18n: { messageProfile: 'eu' },
63
+ },
64
+ policyPackPresets.californiaOptOut(),
65
+ policyPackPresets.worldNoBanner(),
66
+ ],
67
+ }
68
+ ```
69
+
70
+ Available presets:
71
+
72
+ |Preset|Model|Matches|
73
+ |--|--|--|
74
+ |`europeOptIn()`|`opt-in`|EEA + UK countries + geo fallback|
75
+ |`europeIab()`|`iab`|EEA + UK countries + geo fallback (TCF 2.3)|
76
+ |`californiaOptOut()`|`opt-out`|US-CA region|
77
+ |`quebecOptIn()`|`opt-in`|CA-QC region|
78
+ |`worldNoBanner()`|`none`|default fallback|
79
+
80
+ ## Provider Shape
81
+
82
+ Configure packs through `offlinePolicy.policyPacks`. Add `offlinePolicy.i18n`
83
+ when you want local previews or fallback behavior to mirror hosted policy-profile language behavior:
84
+
85
+ ```tsx
86
+ <ConsentManagerProvider
87
+ options={{
88
+ mode: 'offline',
89
+ offlinePolicy: {
90
+ i18n: {
91
+ defaultProfile: 'default',
92
+ messages: {
93
+ default: {
94
+ translations: {
95
+ en: { cookieBanner: { title: 'Privacy choices' } },
96
+ },
97
+ },
98
+ qc: {
99
+ fallbackLanguage: 'fr',
100
+ translations: {
101
+ en: { cookieBanner: { title: 'Quebec Privacy Settings' } },
102
+ fr: { cookieBanner: { title: 'Paramètres de confidentialité du Québec' } },
103
+ },
104
+ },
105
+ },
106
+ },
107
+ policyPacks: [
108
+ {
109
+ id: 'qc_opt_in',
110
+ match: { regions: [{ country: 'CA', region: 'QC' }] },
111
+ i18n: { messageProfile: 'qc' },
112
+ consent: { model: 'opt-in', expiryDays: 365 },
113
+ ui: { mode: 'banner' },
114
+ },
115
+ {
116
+ id: 'default',
117
+ match: { isDefault: true },
118
+ consent: { model: 'none' },
119
+ ui: { mode: 'none' },
120
+ },
121
+ ],
122
+ },
123
+ overrides: { country: 'CA', region: 'QC' },
124
+ }}
125
+ >
126
+ ```
127
+
128
+ With that setup, offline mode resolves language the same way as hosted mode:
129
+
130
+ * the active policy profile defines the allowed language set
131
+ * each profile can define its own `fallbackLanguage`
132
+ * built-in translations only fill missing keys for the selected language
133
+
134
+ ## Fallback Behavior
135
+
136
+ |Configuration|Result|
137
+ |--|--|
138
+ |`offlinePolicy.policyPacks` omitted|Synthetic opt-in fallback banner (also used for hosted network fallback)|
139
+ |`offlinePolicy: { policyPacks: [] }`|Explicit no-banner mode|
140
+ |Non-empty pack, no match, no default|Explicit no-banner mode|
141
+
142
+ Omitting the option gives you a safe opt-in default for local development and outage scenarios. Providing it tells c15t you want deterministic preview or fallback behavior exactly as configured.
143
+
144
+ ## QA and Debugging
145
+
146
+ The best way to test regional consent behavior is with the [c15t DevTools](/docs/frameworks/react/dev-tools). The DevTools Policy panel lets you simulate different countries, regions, and GPC signals against your real backend — no code changes needed.
147
+
148
+ For deeper inspection:
149
+
150
+ * Read `policy` and `policyDecision` from `useConsentManager()` to see the resolved config
151
+ * Open the DevTools Policy panel to inspect matcher resolution and fingerprints
152
+ * Compare your frontend preview with the backend `/init` response before shipping
153
+
154
+ If you need fully deterministic resolution without a backend during testing or preview work (for example, in automated tests or Storybook), pair `offlinePolicy.policyPacks` with `overrides`:
155
+
156
+ ```tsx
157
+ options={{
158
+ mode: 'offline',
159
+ offlinePolicy: {
160
+ policyPacks: [
161
+ policyPackPresets.europeOptIn(),
162
+ policyPackPresets.californiaOptOut(),
163
+ policyPackPresets.worldNoBanner(),
164
+ ],
165
+ },
166
+ overrides: {
167
+ country: 'US',
168
+ region: 'CA',
169
+ language: 'en-US',
170
+ gpc: true, // Simulate Global Privacy Control
171
+ },
172
+ }}
173
+ ```
@@ -0,0 +1,311 @@
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.\*
@@ -0,0 +1,31 @@
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.
@@ -0,0 +1,95 @@
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
+ ```