@c15t/react 3.0.0-alpha.3 → 3.0.0-alpha.5

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 (219) hide show
  1. package/AGENTS.md +92 -72
  2. package/README.md +21 -17
  3. package/SKILL.md +34 -0
  4. package/dist/component-hooks/use-headless-consent-ui.js +1 -1
  5. package/dist/component-hooks/use-headless-iab-consent-ui.js +1 -1
  6. package/dist/components/consent-gate/atoms.js +1 -1
  7. package/dist/components/consent-gate/consent-gate.js +1 -1
  8. package/dist/components/iab-panel/atoms/card.js +1 -1
  9. package/dist/components/iab-panel/atoms/feature-item.js +2 -0
  10. package/dist/components/iab-panel/atoms/header.js +1 -1
  11. package/dist/components/iab-panel/iab-panel.js +1 -1
  12. package/dist/components/iab-panel/index.js +1 -1
  13. package/dist/components/iab-prompt/atoms/overlay.js +1 -1
  14. package/dist/components/iab-prompt/atoms/root.js +1 -1
  15. package/dist/components/panel/atoms/card.js +1 -1
  16. package/dist/components/panel/atoms/root.js +1 -1
  17. package/dist/components/panel-trigger/atoms/button.js +1 -1
  18. package/dist/components/panel-trigger/atoms/toolbar.js +1 -1
  19. package/dist/components/preferences/atoms/accordion.js +1 -1
  20. package/dist/components/prompt/atoms/overlay.js +1 -1
  21. package/dist/components/prompt/atoms/root.js +1 -1
  22. package/dist/components/prompt/components.js +1 -1
  23. package/dist/components/shared/libs/compose-refs.js +1 -0
  24. package/dist/components/shared/libs/slot.js +1 -1
  25. package/dist/components/shared/primitives/button.js +1 -1
  26. package/dist/components/shared/ui/dialog/dialog.js +1 -1
  27. package/dist/components/shared/ui/icon.js +1 -1
  28. package/dist/context/consent-tracking-context.js +1 -1
  29. package/dist/devtools.js +1 -1
  30. package/dist/draft-context.js +2 -0
  31. package/dist/draft.js +1 -1
  32. package/dist/external-iab-context.js +1 -1
  33. package/dist/gpp.js +2 -0
  34. package/dist/hooks/use-color-scheme.js +1 -1
  35. package/dist/hooks/use-focus-trap.js +1 -1
  36. package/dist/hooks.js +1 -1
  37. package/dist/iab/styles.tw3.css +4 -4
  38. package/dist/index-parts/consent-banner.js +1 -0
  39. package/dist/index-parts/consent-dialog-link.js +1 -0
  40. package/dist/index-parts/consent-dialog-trigger.js +1 -0
  41. package/dist/index-parts/consent-dialog.js +1 -0
  42. package/dist/index-parts/consent-gate.js +1 -0
  43. package/dist/index-parts/core.js +1 -0
  44. package/dist/index-parts/draft.js +1 -0
  45. package/dist/index-parts/hooks.js +1 -0
  46. package/dist/index-parts/module-hooks.js +1 -0
  47. package/dist/index-parts/provider.js +1 -0
  48. package/dist/index-parts/theme.js +1 -0
  49. package/dist/index-parts/translations.js +1 -0
  50. package/dist/index.js +1 -1
  51. package/dist/kernel-selector.js +1 -1
  52. package/dist/module-hooks/iframe-blocker.js +1 -1
  53. package/dist/postcss-tailwind3.js +1 -0
  54. package/dist/provider.js +1 -1
  55. package/dist/server/fetch-ssr-data.js +1 -1
  56. package/dist/server/headers.js +1 -1
  57. package/dist/server/normalize-url.js +1 -1
  58. package/dist/styles.tw3.css +16 -16
  59. package/dist/transports/offline.js +1 -1
  60. package/dist/utils/merge-slot-props.js +1 -1
  61. package/dist/utils/theme-utils.js +1 -1
  62. package/dist/version.js +1 -1
  63. package/dist-types/component-hooks/use-headless-consent-ui.d.ts +1 -1
  64. package/dist-types/components/iab-panel/atoms/feature-item.d.ts +28 -0
  65. package/dist-types/components/iab-panel/iab-panel.d.ts +2 -2
  66. package/dist-types/components/iab-panel/index.d.ts +5 -2
  67. package/dist-types/components/iab-panel/use-iab-translations.d.ts +4 -0
  68. package/dist-types/components/iab-prompt/iab-prompt.d.ts +2 -2
  69. package/dist-types/components/iab-prompt/index.d.ts +2 -2
  70. package/dist-types/components/panel/atoms/card.d.ts +1 -0
  71. package/dist-types/components/prompt/components.d.ts +6 -0
  72. package/dist-types/components/shared/libs/compose-refs.d.ts +20 -0
  73. package/dist-types/components/shared/ui/icon.d.ts +2 -1
  74. package/dist-types/context/consent-tracking-context.d.ts +10 -0
  75. package/dist-types/context/theme-context.d.ts +2 -2
  76. package/dist-types/context.d.ts +6 -0
  77. package/dist-types/devtools.d.ts +13 -2
  78. package/dist-types/draft-context.d.ts +31 -0
  79. package/dist-types/draft.d.ts +13 -30
  80. package/dist-types/gpp.d.ts +27 -0
  81. package/dist-types/hooks/use-focus-trap.d.ts +3 -1
  82. package/dist-types/hooks.d.ts +57 -13
  83. package/dist-types/iab.d.ts +1 -1
  84. package/dist-types/index-parts/consent-banner.d.ts +7 -0
  85. package/dist-types/index-parts/consent-dialog-link.d.ts +7 -0
  86. package/dist-types/index-parts/consent-dialog-trigger.d.ts +7 -0
  87. package/dist-types/index-parts/consent-dialog.d.ts +7 -0
  88. package/dist-types/index-parts/consent-gate.d.ts +7 -0
  89. package/dist-types/index-parts/core.d.ts +8 -0
  90. package/dist-types/index-parts/draft.d.ts +7 -0
  91. package/dist-types/index-parts/hooks.d.ts +7 -0
  92. package/dist-types/index-parts/module-hooks.d.ts +7 -0
  93. package/dist-types/index-parts/provider.d.ts +7 -0
  94. package/dist-types/index-parts/theme.d.ts +8 -0
  95. package/dist-types/index-parts/translations.d.ts +7 -0
  96. package/dist-types/index.d.ts +14 -15
  97. package/dist-types/kernel-selector.d.ts +0 -8
  98. package/dist-types/module-hooks/iframe-blocker.d.ts +12 -7
  99. package/dist-types/postcss-tailwind3.d.ts +21 -0
  100. package/dist-types/provider.d.ts +57 -17
  101. package/dist-types/server/headers.d.ts +14 -4
  102. package/dist-types/server/normalize-url.d.ts +14 -7
  103. package/dist-types/server/types.d.ts +12 -1
  104. package/dist-types/transports/offline.d.ts +7 -16
  105. package/dist-types/ui-config-context.d.ts +7 -1
  106. package/dist-types/utils/merge-slot-props.d.ts +15 -1
  107. package/dist-types/utils/theme-utils.d.ts +17 -2
  108. package/dist-types/version.d.ts +1 -1
  109. package/docs/README.md +92 -72
  110. package/docs/assets/v3/bottom-bar.png +0 -0
  111. package/docs/assets/v3/brand-card.png +0 -0
  112. package/docs/assets/v3/brand-preferences.png +0 -0
  113. package/docs/assets/v3/choice-wall.png +0 -0
  114. package/docs/assets/v3/headless-bar-html.png +0 -0
  115. package/docs/assets/v3/headless-bar-mobile.png +0 -0
  116. package/docs/assets/v3/headless-bar.png +0 -0
  117. package/docs/assets/v3/slim-bar.png +0 -0
  118. package/docs/concepts/choose-your-setup.md +87 -0
  119. package/docs/{frameworks/react/concepts → concepts}/consent-categories.md +22 -7
  120. package/docs/{guides → concepts}/consent-state.md +89 -105
  121. package/docs/{guides → concepts}/data-fetching.md +31 -27
  122. package/docs/concepts/how-consent-works.md +123 -0
  123. package/docs/{frameworks/react/concepts/policy-presets.md → concepts/policies.md} +7 -59
  124. package/docs/customization/class-names.md +202 -0
  125. package/docs/customization/dark-mode.md +157 -0
  126. package/docs/customization/motion.md +119 -0
  127. package/docs/customization/overview.md +67 -34
  128. package/docs/customization/recipes.md +839 -49
  129. package/docs/customization/slots.md +216 -35
  130. package/docs/customization/stylesheets.md +147 -0
  131. package/docs/customization/tailwind.md +842 -0
  132. package/docs/customization/tokens.md +163 -96
  133. package/docs/customization/translations.md +60 -3
  134. package/docs/frameworks/react/callbacks.md +118 -0
  135. package/docs/frameworks/react/clear-on-revocation.md +106 -0
  136. package/docs/frameworks/react/components/consent-banner.md +42 -28
  137. package/docs/frameworks/react/components/consent-dialog-link.md +13 -11
  138. package/docs/frameworks/react/components/consent-dialog-trigger.md +81 -76
  139. package/docs/frameworks/react/components/consent-dialog.md +56 -50
  140. package/docs/frameworks/react/components/consent-gate.md +37 -20
  141. package/docs/frameworks/react/components/consent-provider.md +130 -0
  142. package/docs/frameworks/react/components/consent-widget.md +23 -20
  143. package/docs/frameworks/react/components/dev-tools.md +53 -85
  144. package/docs/frameworks/react/components.md +105 -0
  145. package/docs/frameworks/react/compose.md +354 -0
  146. package/docs/frameworks/react/content-security-policy.md +126 -0
  147. package/docs/frameworks/react/customize.md +250 -0
  148. package/docs/frameworks/react/embeds.md +89 -0
  149. package/docs/frameworks/react/gpp.md +163 -0
  150. package/docs/frameworks/react/{hooks/overview.md → hooks.md} +21 -16
  151. package/docs/frameworks/react/{iab/overview.md → iab.md} +80 -31
  152. package/docs/frameworks/react/network-blocker.md +35 -41
  153. package/docs/frameworks/react/quickstart.md +139 -101
  154. package/docs/frameworks/react/rendering.md +128 -0
  155. package/docs/frameworks/react/scripts.md +115 -0
  156. package/docs/frameworks/react/translations.md +155 -0
  157. package/docs/frameworks/react/troubleshooting.md +92 -47
  158. package/docs/frameworks/react/vendor-consent.md +170 -0
  159. package/docs/guides/banner-experiments.md +654 -0
  160. package/docs/guides/troubleshooting.md +120 -47
  161. package/docs/guides/verify-consent.md +81 -49
  162. package/docs/integrations/adobe-analytics.md +167 -159
  163. package/docs/integrations/ahrefs-analytics.md +152 -154
  164. package/docs/integrations/amplitude.md +162 -156
  165. package/docs/integrations/building-integrations.md +136 -37
  166. package/docs/integrations/clearbit.md +154 -154
  167. package/docs/integrations/cloudflare-web-analytics.md +156 -156
  168. package/docs/integrations/cloudflare-zaraz.md +209 -261
  169. package/docs/integrations/crisp.md +164 -158
  170. package/docs/integrations/databuddy.md +157 -173
  171. package/docs/integrations/fathom-analytics.md +158 -156
  172. package/docs/integrations/front-chat.md +167 -167
  173. package/docs/integrations/google-maps.md +118 -83
  174. package/docs/integrations/google-tag-manager.md +178 -163
  175. package/docs/integrations/google-tag.md +163 -160
  176. package/docs/integrations/heap.md +163 -155
  177. package/docs/integrations/hightouch.md +161 -157
  178. package/docs/integrations/hotjar.md +159 -155
  179. package/docs/integrations/intercom.md +183 -153
  180. package/docs/integrations/klaviyo.md +486 -0
  181. package/docs/integrations/linkedin-insights.md +174 -150
  182. package/docs/integrations/logrocket.md +160 -156
  183. package/docs/integrations/matomo-analytics.md +188 -178
  184. package/docs/integrations/meta-pixel.md +188 -150
  185. package/docs/integrations/microsoft-clarity.md +163 -155
  186. package/docs/integrations/microsoft-uet.md +148 -154
  187. package/docs/integrations/mixpanel-analytics.md +155 -160
  188. package/docs/integrations/one-dollar-stats.md +166 -165
  189. package/docs/integrations/openai-pixel.md +204 -301
  190. package/docs/integrations/overview.md +137 -80
  191. package/docs/integrations/pinterest-tag.md +191 -183
  192. package/docs/integrations/pirsch.md +169 -159
  193. package/docs/integrations/plausible-analytics.md +172 -158
  194. package/docs/integrations/posthog.md +313 -240
  195. package/docs/integrations/promptwatch.md +154 -154
  196. package/docs/integrations/reddit-pixel.md +185 -157
  197. package/docs/integrations/rudderstack.md +201 -186
  198. package/docs/integrations/rybbit-analytics.md +171 -160
  199. package/docs/integrations/segment.md +182 -154
  200. package/docs/integrations/snapchat-pixel.md +186 -156
  201. package/docs/integrations/tiktok-pixel.md +171 -150
  202. package/docs/integrations/umami-analytics.md +163 -158
  203. package/docs/integrations/vercel-analytics.md +166 -157
  204. package/docs/integrations/x-pixel.md +176 -150
  205. package/docs/integrations/youtube.md +121 -86
  206. package/docs/upgrade-v3.md +496 -467
  207. package/package.json +20 -9
  208. package/dist/ui-save.js +0 -1
  209. package/dist-types/ui-save.d.ts +0 -25
  210. package/docs/assets/v3/brand-bar.png +0 -0
  211. package/docs/assets/v3/mobile-card.png +0 -0
  212. package/docs/assets/v3/preferences.png +0 -0
  213. package/docs/frameworks/react/components/consent-manager-provider.md +0 -95
  214. package/docs/frameworks/react/script-loader.md +0 -69
  215. package/docs/frameworks/react/styling/overview.md +0 -266
  216. package/docs/guides/deployment-modes.md +0 -75
  217. package/docs/guides/shared-consent-controls.md +0 -158
  218. package/docs/integrations/clear-on-revocation.md +0 -167
  219. package/docs/integrations/granular-consent.md +0 -210
@@ -1,158 +0,0 @@
1
- ---
2
- title: Share consent controls across frameworks
3
- description: Use the same c15t script lifecycle, external consent source, and
4
- event controls in every framework.
5
- group: guides
6
- ---
7
-
8
- ## Choose one consent authority
9
-
10
- c15t owns script loading, consent gates, lifecycle callbacks, and optional cleanup
11
- through its framework-independent core. React, Vue, Svelte, Astro, and the browser
12
- client connect to that core. Next.js and TanStack Start use the React provider;
13
- Nuxt uses Vue; SvelteKit uses Svelte. None requires Astro for these controls.
14
-
15
- With c15t as the consent authority, keep your framework's hosted, self-hosted, or
16
- offline setup. Offline mode keeps choices in the browser; a hosted backend can
17
- store records. The script SDK and event dispatcher work with either mode.
18
-
19
- To keep another CMP, provide a `consentSource`. It owns the banner, preferences,
20
- records, expiration, privacy signals, and category mapping. c15t follows its
21
- current permissions without creating a second choice record. Optional categories
22
- start denied, including during SSR. An unavailable source or a failed read denies
23
- them again. Initialize the CMP independently, or register its loader as an
24
- explicitly early-loading script so it does not wait for its own consent.
25
-
26
- The source contract is exported from `@c15t/core/runtime`:
27
-
28
- ```ts title="src/consent-source.ts — adapter skeleton"
29
- import type { ExternalConsentSource } from 'c15t/runtime';
30
- import { provider } from './existing-cmp';
31
-
32
- export const consentSource: ExternalConsentSource = {
33
- getPermissions: () => provider.getCategoryPermissions(),
34
- subscribe: (notify) => provider.subscribe(notify),
35
- openPreferences: () => provider.openPreferences(),
36
- };
37
- ```
38
-
39
- `provider` is your application's adapter for the existing CMP, not a c15t export.
40
- Map its categories to c15t's `measurement`, `marketing`, `functionality`, and
41
- `experience` booleans. Missing categories are denied; `necessary` stays true.
42
- Return `null` until the CMP is ready. `subscribe` must notify on initialization,
43
- changes, withdrawal, and expiration, and return a function that removes listeners.
44
- Keep browser access inside these functions so importing the adapter during SSR is safe.
45
-
46
- If `subscribe` throws, c15t reports the failure through `callbacks.onError` and
47
- continues startup with optional categories denied. The failed connection ignores
48
- later notifications and does not forward preference requests. Recreate the owner
49
- after the CMP is available to connect again.
50
-
51
- ## Pass the controls to your framework
52
-
53
- The `consentSource` option is available at these registration points. Register your SDK configurations through the same owner's
54
- `scripts` option. Do not create an additional runtime beside an existing provider.
55
-
56
- | Framework | Registration point |
57
- | --------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
58
- | React | `ConsentProvider options={{ mode, consentSource, scripts }}` |
59
- | Next.js / TanStack Start | `ConsentRoot options={{ consentSource }}` with `scripts` as a top-level prop; `ConsentProvider` also accepts the React options |
60
- | Vue | `app.use(c15tVue, { consentSource, scripts })` |
61
- | Nuxt | `app.config.ts` → `c15t: { consentSource, scripts }` |
62
- | Svelte / SvelteKit | `ConsentManagerProvider` options or corresponding top-level props |
63
- | Astro | `clientOptions.consentSource` |
64
- | Browser client | `createConsentClient({ consentSource, scripts })` |
65
- | Headless JavaScript / Solid | `createConsentRuntime({ mode, consentSource, scripts })` |
66
-
67
- For example, a React client boundary can use the source directly:
68
-
69
- ```tsx title="src/Consent.tsx"
70
- 'use client';
71
-
72
- import type { ReactNode } from 'react';
73
- import { ConsentProvider, offline, useSetActiveUI } from 'c15t/react';
74
- import { googleTagManager } from '@c15t/scripts/google-tag-manager';
75
- import { consentSource } from './consent-source';
76
-
77
- const mode = offline();
78
- const scripts = [googleTagManager({ id: 'GTM-EXAMPLE' })];
79
-
80
- function Preferences() {
81
- const setActiveUI = useSetActiveUI();
82
- return <button type="button" onClick={() => setActiveUI('dialog')}>Privacy settings</button>;
83
- }
84
-
85
- export function Consent({ children }: { children: ReactNode }) {
86
- return (
87
- <ConsentProvider options={{ mode, consentSource, scripts }}>
88
- {children}
89
- <Preferences />
90
- </ConsentProvider>
91
- );
92
- }
93
- ```
94
-
95
- Replace the container ID. `mode` remains required by the provider API, but an
96
- external source bypasses c15t backend initialization and persistence. Omit c15t's
97
- banner and dialog. Preference links, hooks, and `kernel.set.activeUI('dialog')`
98
- delegate to the source. Preference-opening failures reach `callbacks.onError`;
99
- `kernel.commands.save()` rejects instead of recording a second choice.
100
-
101
- In Next.js, construct the source in the client boundary; do not pass functions
102
- from a Server Component. Existing `ConsentRoot` state can stay serializable, but
103
- c15t records do not establish external permissions. A client-owned
104
- `ConsentProvider` avoids a redundant server consent fetch for external-only setups.
105
- For Nuxt, use `app.config.ts` for the functions, not serialized public runtime
106
- configuration; the module skips its consent fetch and record hydration when a
107
- source is configured. Browser access remains deferred until mount.
108
-
109
- Solid currently ships UI primitives, not a lifecycle provider. Create the core
110
- runtime once, call `start()` from `onMount`, and `dispose()` from `onCleanup`.
111
- Other frameworks' providers perform that lifecycle automatically. A provider given
112
- an existing `runtime` borrows it: configure controls on the runtime owner, which
113
- also owns starting and disposing it.
114
-
115
- ## Handle withdrawal and application events
116
-
117
- When the source withdraws an optional category that was granted, c15t reloads
118
- the page, as it does when a visitor revokes consent in c15t's own UI. Removing a
119
- script element cannot stop JavaScript that already ran, so the reload starts a
120
- page with only permitted code. The reload runs in the next task, after
121
- synchronous consent callbacks and `onBeforeConsentRevocationReload`. Disposing
122
- the owner cancels a pending reload.
123
-
124
- c15t cannot tell a visitor's withdrawal from expiry or a reset in the CMP, so
125
- any notification that turns off a granted category reloads. The CMP owns
126
- persistence: store the new decision before notifying c15t, or the reloaded page
127
- reads the old one. Set `reloadOnConsentRevoked: false` to handle withdrawal
128
- yourself. c15t still updates gates and calls script consent callbacks.
129
-
130
- `createEventDispatcher` from `@c15t/scripts/events` also has no framework dependency:
131
-
132
- ```ts title="src/events.ts — attach to an existing runtime"
133
- import { createEventDispatcher } from '@c15t/scripts/events';
134
-
135
- const events = createEventDispatcher({
136
- scripts,
137
- getSnapshot: () => runtime.kernel.getSnapshot(),
138
- });
139
- events.track('docs_search', { resultCount: 4 });
140
- ```
141
-
142
- Here `scripts` is the same configuration registered with the existing `runtime`.
143
- For a provider-owned kernel, use that kernel's live `getSnapshot` instead. The
144
- dispatcher sends only to configured integrations with supported event APIs when
145
- measurement and the script's own consent condition allow it. It discards denied
146
- events, isolates vendor failures, and deduplicates explicitly configured SPA
147
- pageviews. It does not subscribe to a framework router: notify it from your
148
- router's navigation hook. Use vendor-specific helpers for APIs outside the shared
149
- event contract.
150
-
151
- ## Verify the integration
152
-
153
- Test an undecided visitor, an existing grant, withdrawal, expiry, and a source
154
- that cannot be read. Check that only permitted scripts execute, the preference
155
- control opens the existing CMP, c15t does not render another banner or persist
156
- another receipt, and unmounting removes the source listeners. Test your actual
157
- CMP category mapping and tag-manager container; shared gates do not validate
158
- those configurations or establish compliance by themselves.
@@ -1,167 +0,0 @@
1
- ---
2
- title: Clear on revocation
3
- description: Remove configured first-party cookies and Web Storage keys when
4
- their consent category is denied.
5
- group: integrations
6
- ---
7
-
8
- ## Configure cleanup
9
-
10
- Add `clearOnRevocation` to your provider or runtime options. Declare only the
11
- data owned by each optional category:
12
-
13
- ```ts
14
- import { hosted, type ClearOnRevocationConfig } from 'c15t';
15
- import { createConsentRuntime } from 'c15t/runtime';
16
-
17
- const clearOnRevocation = {
18
- measurement: {
19
- cookies: ['_ga', '_ga_*'],
20
- localStorage: ['analytics:*'],
21
- },
22
- marketing: {
23
- cookies: ['_fbp'],
24
- sessionStorage: ['campaign-id'],
25
- },
26
- } satisfies ClearOnRevocationConfig;
27
-
28
- const runtime = createConsentRuntime({
29
- mode: hosted({ url: '/api/c15t' }),
30
- clearOnRevocation,
31
- });
32
-
33
- // Start in the browser after mount. The endpoint must serve your c15t backend.
34
- runtime.start();
35
-
36
- // Call runtime.dispose() when the app no longer needs consent management.
37
- ```
38
-
39
- For React, pass the same configuration through `ConsentProvider.options`:
40
-
41
- ```tsx
42
- import type { ReactNode } from 'react';
43
- import { ConsentProvider, hosted } from 'c15t/react';
44
-
45
- const mode = hosted({ url: '/api/c15t' });
46
-
47
- export function Consent({ children }: { children: ReactNode }) {
48
- return (
49
- <ConsentProvider
50
- options={{
51
- mode,
52
- clearOnRevocation: {
53
- measurement: { cookies: ['_ga', '_ga_*'] },
54
- },
55
- }}
56
- >
57
- {children}
58
- </ConsentProvider>
59
- );
60
- }
61
- ```
62
-
63
- The same option is available in Next.js and TanStack Start `ConsentRoot` props, Vue and
64
- Nuxt configuration, Svelte providers, and Astro integration options. Solid and
65
- other headless integrations can use `createConsentRuntime` as shown above.
66
- Every adapter uses the same cleanup module.
67
-
68
- Omitting `clearOnRevocation` leaves cleanup disabled. The provider option is
69
- initial-only. Remount the provider to replace its cleanup configuration. For
70
- a shared runtime, configure the runtime owner rather than a borrowing provider.
71
-
72
- ## Matching names and cookie scopes
73
-
74
- Use an exact string or a nonempty prefix followed by `*`. `_ga_*` matches
75
- `_ga_ABC123`; it does not match `_ga`. Regular expressions, wildcards in other
76
- positions, and a bare `*` are unsupported. Web Storage keys may contain spaces,
77
- Unicode, and punctuation. Cookie names use their raw spelling, without URL
78
- decoding.
79
-
80
- Cookies can share a name while having different domains or paths. Cleanup
81
- tries the current host and its parent domains, and the current path and its
82
- ancestors. To target a specific scope, use an object:
83
-
84
- ```ts
85
- const clearOnRevocation = {
86
- measurement: {
87
- cookies: [
88
- { name: 'analytics-id', domain: 'example.com', path: '/' },
89
- { name: 'checkout-metrics', domain: '', path: '/checkout' },
90
- { name: 'partitioned-metrics', partitioned: true },
91
- ],
92
- },
93
- };
94
- ```
95
-
96
- An empty `domain` means host-only. Explicit domains and paths replace the
97
- automatic attempts for that field. Exact names can be deleted at a configured
98
- path even when the current page cannot read that cookie. Prefix matching can
99
- only discover cookie names visible to the current page, so use an exact name
100
- for a cookie on another path.
101
-
102
- Partitioned cookies require `partitioned: true`; ordinary targets remove
103
- unpartitioned cookies. Cookie deletion preserves the browser's `__Secure-`
104
- and `__Host-` prefix requirements. c15t protects its own consent, notice,
105
- privacy, pending-save, and IAB consent records in cookies and localStorage,
106
- including configured custom storage keys, even if your patterns match them.
107
- c15t does not store consent in sessionStorage, so targeted entries there are
108
- removed even when their names match consent storage keys.
109
-
110
- ## When cleanup runs
111
-
112
- The runtime attaches cleanup after persistence and the script loader. Cleanup
113
- waits while the policy is pending. On the first settled snapshot, it removes
114
- configured data for every denied category. This includes a new opt-in visitor
115
- who has not made a choice and a returning visitor whose permission expired.
116
-
117
- After that first pass, cleanup runs when a category changes from allowed to
118
- denied. Saving a refusal, expiry, a policy change, Global Privacy Control,
119
- or synchronized records can cause that transition. Under an opt-out policy,
120
- an expired grant that remains effectively allowed does not trigger deletion.
121
- The `necessary` category cannot be configured for cleanup.
122
-
123
- Cleanup keeps waiting if a failed initial request leaves the policy pending.
124
- If a previously settled policy falls back to denial after an initialization
125
- failure, cleanup removes its configured data. A later successful retry cannot
126
- restore deleted data.
127
-
128
- Runtime construction, server rendering, draft checkbox edits, opening the
129
- dialog, and disposal do not clear data. Cleanup does not poll storage or repeat
130
- on unrelated UI updates.
131
-
132
- ## Use an existing kernel
133
-
134
- For a manually assembled integration, attach the module in the browser after
135
- persistence hydration and script-loader setup:
136
-
137
- ```ts
138
- import { createClearOnRevocation } from 'c15t/modules/clear-on-revocation';
139
-
140
- const cleanup = createClearOnRevocation({
141
- kernel,
142
- config: { measurement: { cookies: ['_ga', '_ga_*'] } },
143
- storageConfig,
144
- });
145
-
146
- // Stop observing consent when this integration is torn down.
147
- cleanup.dispose();
148
- ```
149
-
150
- Here `kernel` is your existing consent kernel. Pass the same `storageConfig`
151
- used by persistence so cleanup protects custom record keys. Attaching the
152
- module can immediately clear denied categories if the policy is already
153
- settled. Do not also attach it when your provider or runtime owns cleanup.
154
-
155
- ## Browser limits
156
-
157
- Cleanup can remove JavaScript-accessible first-party cookies and keys in the
158
- current origin's `localStorage` and `sessionStorage`. It cannot remove
159
- `HttpOnly` cookies or another origin's data. Keep `HttpOnly` protections and
160
- use your server to expire cookies that require server access. Cookie deletion
161
- must match the cookie's scope. See the
162
- [browser cookie documentation](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Cookies).
163
-
164
- Browser restrictions can prevent reads or deletions. Cleanup failures do not
165
- block consent updates. A running SDK may write data again after a sweep, so
166
- keep script gating and the integration's consent-change or teardown behavior
167
- configured. Deleting a script element cannot undo JavaScript it already ran.
@@ -1,210 +0,0 @@
1
- ---
2
- title: Granular consent
3
- description: Let visitors grant a category and still turn one vendor off,
4
- without adopting IAB TCF.
5
- group: integrations
6
- ---
7
-
8
- Granular consent is choice below the category level: a visitor grants
9
- marketing and still turns Meta off. The unit of that choice is a vendor, so
10
- the API names them `vendors`, `vendor` and `data-vendor`, and the hooks
11
- `useVendorAllowed` and `useVendorDraft`. Everything else stays as it is:
12
- categories, policies, and the preference center gain vendor rows rather than
13
- a second consent model.
14
-
15
- ## Declare vendors
16
-
17
- Add `vendors` to your runtime options. Each vendor sits inside a category
18
- condition and needs a name and a privacy policy URL so the preference surface
19
- can list it. The React provider takes the same option once its preference
20
- center renders vendor rows; scripts, rules and iframes are gated the same way
21
- whichever place declares it:
22
-
23
- ```ts
24
- import { hosted, type Vendor } from 'c15t';
25
- import { createConsentRuntime } from 'c15t/runtime';
26
-
27
- const vendors = [
28
- {
29
- id: 'meta-pixel',
30
- name: 'Meta Pixel',
31
- category: 'marketing',
32
- privacyPolicyUrl: 'https://www.facebook.com/privacy/policy/',
33
- description: 'Ad conversion measurement and audiences.',
34
- },
35
- {
36
- id: 'google-analytics',
37
- name: 'Google Analytics',
38
- category: 'measurement',
39
- privacyPolicyUrl: 'https://policies.google.com/privacy',
40
- },
41
- ] satisfies Vendor[];
42
-
43
- const runtime = createConsentRuntime({
44
- mode: hosted({ url: '/api/c15t' }),
45
- vendors,
46
- scripts: [
47
- {
48
- id: 'meta-pixel',
49
- category: 'marketing',
50
- vendor: 'meta-pixel',
51
- src: 'https://connect.facebook.net/en_US/fbevents.js',
52
- },
53
- ],
54
- });
55
-
56
- // Start in the browser after mount. The endpoint must serve your c15t backend.
57
- runtime.start();
58
- ```
59
-
60
- The `id` is a lowercase slug of up to 64 characters. Reuse it as the `vendor`
61
- field on scripts and network rules and as the `data-vendor` attribute on
62
- iframes. Integrations from `@c15t/scripts` already set `vendor` to their
63
- manifest slug, so `gtag()` and `metaPixel()` need no extra wiring.
64
-
65
- A backend can also declare vendors. Add `vendors` and an optional
66
- `vendorListVersion` to the manifest configuration; `/init` returns them and the
67
- client merges them with the vendors declared in code. When both declare the
68
- same id, the copy declared in code wins, and the backend copy comes back if the
69
- code declaration is removed later. A slug used by a script, rule or iframe
70
- but declared nowhere still gates loading. It is hidden from the preference surface, and the
71
- runtime warns about it outside production.
72
-
73
- ## How a vendor is gated
74
-
75
- A target loads when its category condition passes and the visitor has not
76
- turned its vendor off:
77
-
78
- ```text
79
- loads = category condition satisfied AND vendor not denied
80
- ```
81
-
82
- The category is evaluated first, so an unknown category still throws as a
83
- configuration error. The iframe blocker is the exception: an `<iframe>` with an
84
- unknown `data-category` stays blocked and logs a console warning, so one typo
85
- can't stop the other iframes on the page from being gated. A vendor toggle never grants a category on its own: with
86
- marketing denied, `meta-pixel` stays blocked whatever its own switch says.
87
- A script with `alwaysLoad` still mounts, as it does for a denied category;
88
- its callbacks receive the vendor result in `info.vendor.granted` so a
89
- self-managing SDK can honor it.
90
-
91
- Under an `iab` policy the `vendor` slug is inert. Vendor consent then comes from
92
- the TC string through `vendorId`, and the vendor rows are not shown.
93
-
94
- The same rule applies to the three gates:
95
-
96
- | Surface | Field |
97
- | --------------- | ------------------------------- |
98
- | Script loader | `Script.vendor` |
99
- | Network blocker | `NetworkBlockerRule.vendor` |
100
- | Iframe blocker | `data-vendor` on the `<iframe>` |
101
-
102
- An iframe with `data-vendor` and no `data-category` is gated on the vendor
103
- alone. An unknown `data-vendor` value is granted rather than thrown: a vendor
104
- the visitor never saw cannot have been turned off. Such a frame has no
105
- category to follow, so a denial the visitor recorded earlier holds even while
106
- nothing declares the slug, for example before the backend's vendor list has
107
- arrived on a cold start.
108
-
109
- A script, rule or frame keeps its slug declared for as long as it is
110
- configured. If a backend list or a provider update drops the entry, the
111
- loader or blocker puts it back, so a stored denial keeps gating it. A slug
112
- several modules share stays under every category they name it with, whichever
113
- module updates last, and drops a category only once no module names it there.
114
- Disposing a loader or blocker, or removing a gated frame from the page, drops
115
- what only it named, so a vendor no live module owns stops being toggleable.
116
-
117
- ## Record a vendor choice
118
-
119
- Vendor grants travel with the save. Stage them and confirm with the next save,
120
- or pass them next to the categories:
121
-
122
- ```ts
123
- // Stage from a toggle handler; nothing changes until save({}) runs. The
124
- // empty patch confirms no category, so only the staged vendor is recorded;
125
- // save() with no input would reconfirm every displayed category too.
126
- runtime.stageVendorConsent('meta-pixel', false);
127
- await runtime.kernel.commands.save({});
128
-
129
- // Or confirm categories and vendors in one action.
130
- await runtime.kernel.commands.save({
131
- marketing: true,
132
- measurement: true,
133
- vendors: { 'meta-pixel': false },
134
- });
135
- ```
136
-
137
- `stageVendorConsent` stages a vendor slug for the next save; it is not the
138
- IAB handle's `setVendorConsent`, which sets a TCF vendor by numeric id and
139
- takes effect at once. The grants can also travel in the save context as
140
- `{ vendors }`, which wins when both are given.
141
-
142
- Only the vendors the visitor turned off are stored. Accept all and reject all
143
- both clear that list, so vendors follow their category on a bulk action. A bulk
144
- action narrowed to the displayed categories only lifts the denials of vendors
145
- those categories decide on their own; a vendor another granted category would
146
- still load keeps its denial. A
147
- vendor that is not declared, or is declared with `disabled: true`, is ignored.
148
- Under an opt-out policy every vendor starts on and the stored list is the
149
- do-not-sell list.
150
-
151
- A vendor-only change records without touching category receipts. The kernel
152
- emits `vendors:recorded` rather than `choice:recorded`, writes the
153
- `<storageKey>-vendors` cookie and localStorage entry, and sends the complete
154
- grant map to the backend as `vendorChoice`. Category confirmation times are not
155
- renewed. The vendor entry also carries the subject id, so a visitor whose first
156
- act only decided vendors keeps the same subject after a reload even though no
157
- category record exists yet.
158
-
159
- Scripts see the vendor result in their callbacks. `ScriptCallbackInfo.vendor`
160
- carries `{ id, granted }` outside IAB mode. Integrations that send Google
161
- Consent Mode or RudderStack signals send every category as denied while their
162
- vendor is off, so the vendor's own consent API cannot re-enable tracking.
163
-
164
- ## Show vendors in the preference center
165
-
166
- The `ConsentWidget` and `ConsentDialog` in React, Vue and Svelte list vendors
167
- under their category when the provider declares them. Pass the same `vendors`
168
- array to `ConsentProvider`, to the `vendors` prop of `ConsentRoot` in
169
- [Next.js](https://c15t.com/docs/frameworks/next/script-loader#granular-consent) and
170
- [TanStack Start](https://c15t.com/docs/frameworks/tanstack-start/quickstart#granular-consent),
171
- to the Nuxt module or Vue plugin config next to `scripts`, or to
172
- `ConsentManagerProvider` options in Svelte:
173
-
174
- ```tsx
175
- import { ConsentProvider, hosted } from 'c15t/react';
176
-
177
- <ConsentProvider options={{ mode: hosted({ url: '/api/c15t' }), vendors }}>
178
- {children}
179
- </ConsentProvider>;
180
- ```
181
-
182
- Each category row expands to one card per vendor with its own switch. The
183
- switches disable while the category is off in the draft, and Save records the
184
- vendors the visitor moved. A custom control uses `useVendorDraft()` from
185
- `c15t/react` to read and stage the same grants, with `isStale` and `reset` for
186
- a draft the policy or vendor list changed under, and `useVendorAllowed(id)` to
187
- read one vendor's effective result. Copy comes from
188
- `consentManagerDialog.vendors.{title, privacyPolicy, disabledByCategory,
189
- switchLabel}` in the translations. In Vue, `useConsentDraft()` returns the
190
- same `vendors` map and `setVendor`; in Svelte, `getConsentManager()` exposes
191
- `selectedVendors`, `setSelectedVendor` and `getDisplayedVendors(category)`.
192
- The three frameworks render the same cards, and the parity suite compares
193
- their markup, accessibility tree, computed styles and geometry.
194
-
195
- ## What a denial does not do
196
-
197
- Turning a vendor off blocks future loads and requests. It does not delete the
198
- cookies that vendor already set, and
199
- [clear on revocation](./clear-on-revocation.md) does not help here:
200
- it runs when a category is denied, and the category stays granted when only one
201
- of its vendors is off. Remove that vendor's cookies yourself from an
202
- `onConsentChange` callback that checks `info.vendor.granted`.
203
-
204
- A vendor denial has no expiry and no policy basis. It stays until the visitor
205
- changes it or a bulk action clears it, including across a policy change that
206
- requires the category choice again.
207
-
208
- Adding a vendor to the list does not reopen consent. New vendors default to on
209
- inside a granted category. Use the policy rule's `copyRevision` when a new
210
- vendor should prompt the visitor again.