@c15t/scripts 3.0.0-alpha.0 → 3.0.0-alpha.2

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 (88) hide show
  1. package/AGENTS.md +7 -0
  2. package/README.md +4 -3
  3. package/dist/e2e-test-utils.js +5 -3
  4. package/dist/engine/runtime.js +14 -3
  5. package/dist/events.js +218 -0
  6. package/dist/registry.js +40 -0
  7. package/dist/vendors/ads-and-pixels/pinterest-tag.js +123 -0
  8. package/dist/vendors/analytics/google-tag.js +14 -2
  9. package/dist/vendors/analytics/microsoft-clarity.js +4 -1
  10. package/dist/vendors/analytics/one-dollar-stats.js +30 -0
  11. package/dist/vendors/analytics/segment.js +10 -1
  12. package/dist/vendors/functional/front-chat.js +64 -0
  13. package/dist/vendors/tag-managers/cloudflare-zaraz.js +98 -0
  14. package/dist/vendors/tag-managers/google-tag-manager.js +17 -3
  15. package/dist-types/__tests__/helpers.d.ts +2 -2
  16. package/dist-types/engine/compile.d.ts +1 -1
  17. package/dist-types/engine/runtime.d.ts +1 -1
  18. package/dist-types/events.d.ts +46 -0
  19. package/dist-types/registry.d.ts +36 -0
  20. package/dist-types/resolve.d.ts +1 -1
  21. package/dist-types/vendors/_shared/install-builders.d.ts +1 -1
  22. package/dist-types/vendors/ads-and-pixels/pinterest-tag.d.ts +295 -0
  23. package/dist-types/vendors/analytics/adobe-analytics.d.ts +1 -1
  24. package/dist-types/vendors/analytics/google-tag.d.ts +3 -1
  25. package/dist-types/vendors/analytics/matomo-analytics.d.ts +1 -1
  26. package/dist-types/vendors/analytics/one-dollar-stats.d.ts +39 -0
  27. package/dist-types/vendors/analytics/segment.d.ts +7 -1
  28. package/dist-types/vendors/functional/front-chat.d.ts +62 -0
  29. package/dist-types/vendors/tag-managers/cloudflare-zaraz.d.ts +39 -0
  30. package/dist-types/vendors/tag-managers/google-tag-manager.d.ts +3 -1
  31. package/docs/README.md +7 -0
  32. package/docs/customization/overview.md +4 -3
  33. package/docs/customization/recipes.md +4 -2
  34. package/docs/customization/tokens.md +66 -3
  35. package/docs/frameworks/javascript/script-loader.md +53 -0
  36. package/docs/frameworks/next/script-loader.md +60 -12
  37. package/docs/frameworks/react/script-loader.md +14 -0
  38. package/docs/guides/consent-state.md +327 -0
  39. package/docs/guides/deployment-modes.md +12 -0
  40. package/docs/guides/shared-consent-controls.md +158 -0
  41. package/docs/integrations/adobe-analytics.md +1 -1
  42. package/docs/integrations/ahrefs-analytics.md +1 -1
  43. package/docs/integrations/amplitude.md +1 -1
  44. package/docs/integrations/building-integrations.md +5 -0
  45. package/docs/integrations/clear-on-revocation.md +167 -0
  46. package/docs/integrations/clearbit.md +1 -1
  47. package/docs/integrations/cloudflare-web-analytics.md +1 -1
  48. package/docs/integrations/cloudflare-zaraz.md +399 -0
  49. package/docs/integrations/crisp.md +1 -1
  50. package/docs/integrations/databuddy.md +1 -1
  51. package/docs/integrations/fathom-analytics.md +1 -1
  52. package/docs/integrations/front-chat.md +322 -0
  53. package/docs/integrations/google-maps.md +21 -21
  54. package/docs/integrations/google-tag-manager.md +1 -1
  55. package/docs/integrations/google-tag.md +1 -1
  56. package/docs/integrations/granular-consent.md +210 -0
  57. package/docs/integrations/heap.md +1 -1
  58. package/docs/integrations/hightouch.md +1 -1
  59. package/docs/integrations/hotjar.md +1 -1
  60. package/docs/integrations/intercom.md +1 -1
  61. package/docs/integrations/linkedin-insights.md +1 -1
  62. package/docs/integrations/logrocket.md +1 -1
  63. package/docs/integrations/matomo-analytics.md +1 -1
  64. package/docs/integrations/meta-pixel.md +1 -1
  65. package/docs/integrations/microsoft-clarity.md +1 -1
  66. package/docs/integrations/microsoft-uet.md +1 -1
  67. package/docs/integrations/mixpanel-analytics.md +1 -1
  68. package/docs/integrations/one-dollar-stats.md +305 -0
  69. package/docs/integrations/openai-pixel.md +1 -1
  70. package/docs/integrations/overview.md +22 -18
  71. package/docs/integrations/pinterest-tag.md +321 -0
  72. package/docs/integrations/pirsch.md +1 -1
  73. package/docs/integrations/plausible-analytics.md +1 -1
  74. package/docs/integrations/posthog.md +1 -1
  75. package/docs/integrations/promptwatch.md +1 -1
  76. package/docs/integrations/reddit-pixel.md +1 -1
  77. package/docs/integrations/rudderstack.md +1 -1
  78. package/docs/integrations/rybbit-analytics.md +1 -1
  79. package/docs/integrations/segment.md +1 -1
  80. package/docs/integrations/snapchat-pixel.md +1 -1
  81. package/docs/integrations/tiktok-pixel.md +1 -1
  82. package/docs/integrations/umami-analytics.md +1 -1
  83. package/docs/integrations/vercel-analytics.md +1 -1
  84. package/docs/integrations/x-pixel.md +1 -1
  85. package/docs/integrations/youtube.md +27 -22
  86. package/docs/upgrade-v3.md +176 -1
  87. package/package.json +30 -2
  88. package/readme.json +0 -19
@@ -0,0 +1,210 @@
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](../frameworks/next/script-loader.md#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.
@@ -194,7 +194,7 @@ clientEntrypoint: fileURLToPath(new URL('./src/c15t.client.ts', import.meta.url)
194
194
  Export the scripts from that module:
195
195
 
196
196
  ```ts title="src/c15t.client.ts"
197
- import type { C15tClientOptionsExtension } from '@c15t/astro';
197
+ import type { C15tClientOptionsExtension } from 'c15t/astro';
198
198
  import { scripts } from './consent-scripts';
199
199
 
200
200
  export default { scripts } satisfies C15tClientOptionsExtension;
@@ -194,7 +194,7 @@ clientEntrypoint: fileURLToPath(new URL('./src/c15t.client.ts', import.meta.url)
194
194
  Export the scripts from that module:
195
195
 
196
196
  ```ts title="src/c15t.client.ts"
197
- import type { C15tClientOptionsExtension } from '@c15t/astro';
197
+ import type { C15tClientOptionsExtension } from 'c15t/astro';
198
198
  import { scripts } from './consent-scripts';
199
199
 
200
200
  export default { scripts } satisfies C15tClientOptionsExtension;
@@ -194,7 +194,7 @@ clientEntrypoint: fileURLToPath(new URL('./src/c15t.client.ts', import.meta.url)
194
194
  Export the scripts from that module:
195
195
 
196
196
  ```ts title="src/c15t.client.ts"
197
- import type { C15tClientOptionsExtension } from '@c15t/astro';
197
+ import type { C15tClientOptionsExtension } from 'c15t/astro';
198
198
  import { scripts } from './consent-scripts';
199
199
 
200
200
  export default { scripts } satisfies C15tClientOptionsExtension;
@@ -197,7 +197,7 @@ clientEntrypoint: fileURLToPath(new URL('./src/c15t.client.ts', import.meta.url)
197
197
  Export the scripts from that module:
198
198
 
199
199
  ```ts title="src/c15t.client.ts"
200
- import type { C15tClientOptionsExtension } from '@c15t/astro';
200
+ import type { C15tClientOptionsExtension } from 'c15t/astro';
201
201
  import { scripts } from './consent-scripts';
202
202
 
203
203
  export default { scripts } satisfies C15tClientOptionsExtension;
@@ -194,7 +194,7 @@ clientEntrypoint: fileURLToPath(new URL('./src/c15t.client.ts', import.meta.url)
194
194
  Export the scripts from that module:
195
195
 
196
196
  ```ts title="src/c15t.client.ts"
197
- import type { C15tClientOptionsExtension } from '@c15t/astro';
197
+ import type { C15tClientOptionsExtension } from 'c15t/astro';
198
198
  import { scripts } from './consent-scripts';
199
199
 
200
200
  export default { scripts } satisfies C15tClientOptionsExtension;
@@ -194,7 +194,7 @@ clientEntrypoint: fileURLToPath(new URL('./src/c15t.client.ts', import.meta.url)
194
194
  Export the scripts from that module:
195
195
 
196
196
  ```ts title="src/c15t.client.ts"
197
- import type { C15tClientOptionsExtension } from '@c15t/astro';
197
+ import type { C15tClientOptionsExtension } from 'c15t/astro';
198
198
  import { scripts } from './consent-scripts';
199
199
 
200
200
  export default { scripts } satisfies C15tClientOptionsExtension;
@@ -203,7 +203,7 @@ clientEntrypoint: fileURLToPath(new URL('./src/c15t.client.ts', import.meta.url)
203
203
  Export the scripts from that module:
204
204
 
205
205
  ```ts title="src/c15t.client.ts"
206
- import type { C15tClientOptionsExtension } from '@c15t/astro';
206
+ import type { C15tClientOptionsExtension } from 'c15t/astro';
207
207
  import { scripts } from './consent-scripts';
208
208
 
209
209
  export default { scripts } satisfies C15tClientOptionsExtension;
@@ -196,7 +196,7 @@ clientEntrypoint: fileURLToPath(new URL('./src/c15t.client.ts', import.meta.url)
196
196
  Export the scripts from that module:
197
197
 
198
198
  ```ts title="src/c15t.client.ts"
199
- import type { C15tClientOptionsExtension } from '@c15t/astro';
199
+ import type { C15tClientOptionsExtension } from 'c15t/astro';
200
200
  import { scripts } from './consent-scripts';
201
201
 
202
202
  export default { scripts } satisfies C15tClientOptionsExtension;
@@ -194,7 +194,7 @@ clientEntrypoint: fileURLToPath(new URL('./src/c15t.client.ts', import.meta.url)
194
194
  Export the scripts from that module:
195
195
 
196
196
  ```ts title="src/c15t.client.ts"
197
- import type { C15tClientOptionsExtension } from '@c15t/astro';
197
+ import type { C15tClientOptionsExtension } from 'c15t/astro';
198
198
  import { scripts } from './consent-scripts';
199
199
 
200
200
  export default { scripts } satisfies C15tClientOptionsExtension;
@@ -194,7 +194,7 @@ clientEntrypoint: fileURLToPath(new URL('./src/c15t.client.ts', import.meta.url)
194
194
  Export the scripts from that module:
195
195
 
196
196
  ```ts title="src/c15t.client.ts"
197
- import type { C15tClientOptionsExtension } from '@c15t/astro';
197
+ import type { C15tClientOptionsExtension } from 'c15t/astro';
198
198
  import { scripts } from './consent-scripts';
199
199
 
200
200
  export default { scripts } satisfies C15tClientOptionsExtension;
@@ -197,7 +197,7 @@ clientEntrypoint: fileURLToPath(new URL('./src/c15t.client.ts', import.meta.url)
197
197
  Export the scripts from that module:
198
198
 
199
199
  ```ts title="src/c15t.client.ts"
200
- import type { C15tClientOptionsExtension } from '@c15t/astro';
200
+ import type { C15tClientOptionsExtension } from 'c15t/astro';
201
201
  import { scripts } from './consent-scripts';
202
202
 
203
203
  export default { scripts } satisfies C15tClientOptionsExtension;
@@ -0,0 +1,305 @@
1
+ ---
2
+ title: OneDollarStats
3
+ description: Load the OneDollarStats tracker with measurement permission,
4
+ forward its settings and verify loading and revocation.
5
+ group: integrations
6
+ ---
7
+
8
+ ## Configure OneDollarStats
9
+
10
+ OneDollarStats needs no API key. The helper loads the tracker after
11
+ measurement permission and forwards its settings as `data-*` attributes.
12
+
13
+ | Package manager | Command |
14
+ | :-------------- | :-------------------------- |
15
+ | npm | `npm install @c15t/scripts` |
16
+ | pnpm | `pnpm add @c15t/scripts` |
17
+ | yarn | `yarn add @c15t/scripts` |
18
+ | bun | `bun add @c15t/scripts` |
19
+
20
+ ```ts title="src/consent-scripts.ts"
21
+ import { oneDollarStats } from '@c15t/scripts/one-dollar-stats';
22
+
23
+ export const scripts = [oneDollarStats()];
24
+ ```
25
+
26
+ ## Register the scripts
27
+
28
+ Complete your [framework quickstart](https://c15t.com/docs/frameworks) first. Keep its Inth
29
+ endpoint, policy, styles and consent UI. Remove the vendor's original script,
30
+ SDK initializer or tag-manager entry so c15t owns loading once.
31
+
32
+ The `scripts` export in `src/consent-scripts.ts` is a configuration, not an
33
+ initializer. Add it to your existing consent owner using the registration point
34
+ below. These are partial edits to that owner, not additional providers.
35
+
36
+ **Next.js**
37
+
38
+ Import the configuration into the client boundary from your router guide:
39
+
40
+ ```ts
41
+ import { ConsentRoot } from 'c15t/next';
42
+ import { scripts } from './consent-scripts';
43
+ ```
44
+
45
+ Keep the server-resolved `state` and shared `consentConfig` from your
46
+ router guide. Its manifest, init and save URLs stay in effect. Add
47
+ `scripts` as a top-level prop on the existing root:
48
+
49
+ ```tsx
50
+ <ConsentRoot state={state} config={consentConfig} scripts={scripts}>
51
+ {children}
52
+ </ConsentRoot>
53
+ ```
54
+
55
+ For a Pages Router or static-export setup using `ConsentProvider`, add
56
+ `scripts` to its existing `options` instead. Keep the router-specific setup
57
+ from [Next.js script loading](../frameworks/next/script-loader.md).
58
+
59
+ **TanStack Start**
60
+
61
+ In your existing root route component, import the scripts alongside
62
+ `ConsentRoot`. Keep the server loader from the [TanStack Start quickstart](https://c15t.com/docs/frameworks/tanstack-start/quickstart).
63
+
64
+ ```tsx
65
+ import { Outlet } from '@tanstack/react-router';
66
+ import { ConsentRoot } from 'c15t/tanstack-start';
67
+ import { scripts } from '../consent-scripts';
68
+
69
+ function Root() {
70
+ const state = Route.useLoaderData();
71
+ return (
72
+ <ConsentRoot state={state} backendURL={backendURL} initRoute={false} scripts={scripts}>
73
+ <Outlet />
74
+ {/* Keep your consent banner, dialog and preferences link here. */}
75
+ </ConsentRoot>
76
+ );
77
+ }
78
+ ```
79
+
80
+ This edits the existing route. `Route` and `backendURL` come from its setup;
81
+ keep the document shell and head components if they are part of your root.
82
+ `initRoute={false}` keeps the quickstart's direct-backend initialization.
83
+ If your app mounts a consent server route, retain its existing `initRoute`
84
+ instead. Do not return script callbacks from a server function or route loader.
85
+
86
+ **React**
87
+
88
+ Import the scripts into your existing provider component:
89
+
90
+ ```ts
91
+ import { ConsentProvider } from 'c15t/react';
92
+ import { scripts } from './consent-scripts';
93
+ ```
94
+
95
+ Keep the existing options and add `scripts`:
96
+
97
+ ```tsx
98
+ <ConsentProvider options={{ ...consentOptions, scripts }}>
99
+ {children}
100
+ </ConsentProvider>
101
+ ```
102
+
103
+ Here `consentOptions` is your existing configuration, including
104
+ `mode: hosted({ url: backendURL })`. Keep the banner, dialog and preferences
105
+ link inside the provider. See [React script loading](../frameworks/react/script-loader.md).
106
+
107
+ **Nuxt**
108
+
109
+ Attach one loader from the root `app.vue`, after the Nuxt module has
110
+ started its browser runtime. This keeps vendor callbacks in application code rather
111
+ than serialized `nuxt.config.ts` runtime configuration.
112
+
113
+ ```vue title="app/app.vue"
114
+ <script setup lang="ts">
115
+ import { onUnmounted } from 'vue';
116
+ import { createScriptLoader } from 'c15t/modules/script-loader';
117
+ import { scripts } from '../src/consent-scripts';
118
+
119
+ const nuxtApp = useNuxtApp();
120
+ const kernel = useConsentKernel();
121
+ let loader: ReturnType<typeof createScriptLoader> | undefined;
122
+
123
+ const removeMountedHook = nuxtApp.hook('app:mounted', () => {
124
+ loader = createScriptLoader({ kernel, scripts });
125
+ });
126
+ onUnmounted(() => {
127
+ removeMountedHook();
128
+ loader?.dispose();
129
+ });
130
+ </script>
131
+
132
+ <template>
133
+ <ConsentRoot />
134
+ <NuxtPage />
135
+ </template>
136
+ ```
137
+
138
+ Merge the setup code into your root and retain its footer and preferences
139
+ link. `useConsentKernel` is auto-imported by the c15t Nuxt module. Adjust the
140
+ relative script import if your `app.vue` is at the project root. This loader
141
+ waits until the module has applied browser persistence and privacy signals,
142
+ then reads the current snapshot and observes future changes. Do not also register these scripts
143
+ in another loader. See the [Nuxt quickstart](https://c15t.com/docs/frameworks/nuxt/quickstart).
144
+
145
+ **Vue**
146
+
147
+ Use the kernel already provided by the Vue plugin. Merge this setup into
148
+ `App.vue`, whose lifetime covers the application:
149
+
150
+ ```vue title="src/App.vue"
151
+ <script setup lang="ts">
152
+ import { onMounted, onUnmounted } from 'vue';
153
+ import { createScriptLoader } from 'c15t/modules/script-loader';
154
+ import { useConsentKernel } from 'c15t/vue/vue-plugin';
155
+ import ConsentRoot from 'c15t/vue/consent-root';
156
+ import { scripts } from './consent-scripts';
157
+
158
+ const kernel = useConsentKernel();
159
+ let loader: ReturnType<typeof createScriptLoader> | undefined;
160
+
161
+ onMounted(() => {
162
+ loader = createScriptLoader({ kernel, scripts });
163
+ });
164
+ onUnmounted(() => loader?.dispose());
165
+ </script>
166
+
167
+ <template>
168
+ <ConsentRoot />
169
+ <main>Your application</main>
170
+ </template>
171
+ ```
172
+
173
+ Keep your existing page content and preferences link. The plugin still owns
174
+ the kernel and persistence; this component owns only the vendor loader.
175
+ Do not register the same scripts in plugin configuration as well. See the
176
+ [Vue quickstart](https://c15t.com/docs/frameworks/vue/quickstart).
177
+
178
+ **Astro**
179
+
180
+ Point the existing Astro integration at a client module. Keep its `mode`,
181
+ `ui` and framework integration from the [Astro quickstart](https://c15t.com/docs/frameworks/astro/quickstart).
182
+ Import `fileURLToPath` in your Astro configuration:
183
+
184
+ ```js title="astro.config.mjs"
185
+ import { fileURLToPath } from 'node:url';
186
+ ```
187
+
188
+ Add this option to the existing `c15t({ ... })` call. Resolve the path from
189
+ the configuration file because Astro injects the import into a virtual module:
190
+
191
+ ```js
192
+ clientEntrypoint: fileURLToPath(new URL('./src/c15t.client.ts', import.meta.url)),
193
+ ```
194
+
195
+ Export the scripts from that module:
196
+
197
+ ```ts title="src/c15t.client.ts"
198
+ import type { C15tClientOptionsExtension } from 'c15t/astro';
199
+ import { scripts } from './consent-scripts';
200
+
201
+ export default { scripts } satisfies C15tClientOptionsExtension;
202
+ ```
203
+
204
+ The integration passes this extension to its shared browser runtime. Vendor
205
+ helpers contain callbacks, so do not put them in the serialized `scripts`
206
+ option in `astro.config.mjs`. Keep one runtime across consent islands and
207
+ `ClientRouter` navigation.
208
+
209
+ **Svelte**
210
+
211
+ Import the scripts in the component that owns your existing provider and
212
+ pass them as a top-level prop:
213
+
214
+ ```svelte title="src/App.svelte"
215
+ <script lang="ts">
216
+ import { ConsentManagerProvider, hosted } from '@c15t/svelte';
217
+ import { scripts } from './consent-scripts';
218
+
219
+ const backendURL = import.meta.env.VITE_C15T_BACKEND_URL;
220
+ if (!backendURL) throw new Error('Set VITE_C15T_BACKEND_URL');
221
+ const mode = hosted({ url: backendURL });
222
+ </script>
223
+
224
+ <ConsentManagerProvider {mode} {scripts}>
225
+ <!-- Keep your application, consent UI and preferences link here. -->
226
+ </ConsentManagerProvider>
227
+ ```
228
+
229
+ Retain the styles and consent UI from the [Svelte quickstart](https://c15t.com/docs/frameworks/svelte/quickstart).
230
+ The provider owns the loader and disposes it on unmount.
231
+
232
+ **SvelteKit**
233
+
234
+ Add the scripts to the existing root layout provider. Keep the server load
235
+ and its serializable prefetch data from the [SvelteKit quickstart](https://c15t.com/docs/frameworks/sveltekit/quickstart).
236
+
237
+ ```svelte title="src/routes/+layout.svelte"
238
+ <script lang="ts">
239
+ import { ConsentManagerProvider, hosted } from '@c15t/svelte';
240
+ import { scripts } from '../consent-scripts';
241
+
242
+ let { children, data } = $props();
243
+ const mode = hosted({ url: data.backendURL });
244
+ </script>
245
+
246
+ <ConsentManagerProvider {mode} {scripts} prefetch={data.prefetch}>
247
+ {@render children()}
248
+ <!-- Keep your consent UI and preferences link here. -->
249
+ </ConsentManagerProvider>
250
+ ```
251
+
252
+ Import vendor helpers in the layout component, not in `+layout.server.ts`.
253
+ For static hosting, keep your browser-only `mode` setup and omit request
254
+ prefetch; the `scripts` prop stays the same. If you pass an externally owned
255
+ `runtime` to the provider, register scripts when creating that runtime instead.
256
+
257
+ **JavaScript**
258
+
259
+ Attach the loader to your existing kernel before calling
260
+ `kernel.commands.init()`:
261
+
262
+ ```ts
263
+ import { createScriptLoader } from 'c15t/modules/script-loader';
264
+ import { scripts } from './consent-scripts';
265
+
266
+ const loader = createScriptLoader({ kernel, scripts });
267
+ ```
268
+
269
+ Call `loader.dispose()` when that application instance is destroyed.
270
+ `kernel` is the hosted kernel from your quickstart. A provider-owned kernel
271
+ already has a loader; do not attach a second one. See
272
+ [JavaScript script loading](../frameworks/javascript/script-loader.md).
273
+
274
+ ## Options
275
+
276
+ Every setting is a string without the `data-` prefix. Setting names use
277
+ lowercase letters, digits and hyphens. Unknown names are forwarded so newer
278
+ tracker settings work.
279
+
280
+ | Option | Behavior |
281
+ | -------------- | ----------------------------------------------------------------------------------------------------------------------------- |
282
+ | `hostname` | Bare host, optionally with a port. Overrides the event hostname on every host, including production. |
283
+ | `devmode` | `'true'` records local visits. Local testing needs `hostname` as well. |
284
+ | `autocollect` | `'false'` turns off automatic page view and click collection. |
285
+ | `hash-routing` | `'true'` tracks hash routes. `'false'` omits the attribute, because the tracker turns hash routing on whenever it is present. |
286
+ | `url` | Custom collection endpoint. |
287
+
288
+ The tracker follows client-side navigation itself. See the
289
+ [vendor reference](https://docs.onedollarstats.com/installation) for its
290
+ settings.
291
+
292
+ ## Consent behavior
293
+
294
+ Measurement permission gates the tracker. The tracker installs history hooks
295
+ and event listeners that removing its script cannot undo, so c15t reloads the
296
+ page when a visitor revokes measurement permission. Keep
297
+ `reloadOnConsentRevoked` enabled, and check measurement permission before any
298
+ manual tracking call.
299
+
300
+ ## Verify the integration
301
+
302
+ Use a fresh session with an opt-in policy and confirm the tracker is absent.
303
+ Grant `measurement`, navigate between routes and confirm page views arrive. Then
304
+ revoke it, confirm the page reloads, and check that later navigation sends no
305
+ events. Follow the [consent verification guide](../guides/verify-consent.md).
@@ -198,7 +198,7 @@ clientEntrypoint: fileURLToPath(new URL('./src/c15t.client.ts', import.meta.url)
198
198
  Export the scripts from that module:
199
199
 
200
200
  ```ts title="src/c15t.client.ts"
201
- import type { C15tClientOptionsExtension } from '@c15t/astro';
201
+ import type { C15tClientOptionsExtension } from 'c15t/astro';
202
202
  import { scripts } from './consent-scripts';
203
203
 
204
204
  export default { scripts } satisfies C15tClientOptionsExtension;