@c15t/scripts 3.0.0-alpha.1 → 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.
- package/AGENTS.md +4 -0
- package/README.md +3 -3
- package/dist/e2e-test-utils.js +5 -3
- package/dist/events.js +218 -0
- package/dist/registry.js +30 -0
- package/dist/vendors/ads-and-pixels/pinterest-tag.js +123 -0
- package/dist/vendors/analytics/google-tag.js +14 -2
- package/dist/vendors/analytics/one-dollar-stats.js +30 -0
- package/dist/vendors/analytics/segment.js +10 -1
- package/dist/vendors/functional/front-chat.js +64 -0
- package/dist/vendors/tag-managers/google-tag-manager.js +17 -3
- package/dist-types/events.d.ts +46 -0
- package/dist-types/registry.d.ts +27 -0
- package/dist-types/vendors/ads-and-pixels/pinterest-tag.d.ts +295 -0
- package/dist-types/vendors/analytics/google-tag.d.ts +3 -1
- package/dist-types/vendors/analytics/one-dollar-stats.d.ts +39 -0
- package/dist-types/vendors/analytics/segment.d.ts +7 -1
- package/dist-types/vendors/functional/front-chat.d.ts +62 -0
- package/dist-types/vendors/tag-managers/google-tag-manager.d.ts +3 -1
- package/docs/README.md +4 -0
- package/docs/customization/overview.md +4 -3
- package/docs/customization/recipes.md +4 -2
- package/docs/customization/tokens.md +66 -3
- package/docs/frameworks/javascript/script-loader.md +6 -0
- package/docs/frameworks/next/script-loader.md +18 -12
- package/docs/frameworks/react/script-loader.md +6 -0
- package/docs/guides/consent-state.md +327 -0
- package/docs/guides/shared-consent-controls.md +158 -0
- package/docs/integrations/adobe-analytics.md +1 -1
- package/docs/integrations/ahrefs-analytics.md +1 -1
- package/docs/integrations/amplitude.md +1 -1
- package/docs/integrations/clearbit.md +1 -1
- package/docs/integrations/cloudflare-web-analytics.md +1 -1
- package/docs/integrations/cloudflare-zaraz.md +1 -1
- package/docs/integrations/crisp.md +1 -1
- package/docs/integrations/databuddy.md +1 -1
- package/docs/integrations/fathom-analytics.md +1 -1
- package/docs/integrations/front-chat.md +322 -0
- package/docs/integrations/google-maps.md +1 -1
- package/docs/integrations/google-tag-manager.md +1 -1
- package/docs/integrations/google-tag.md +1 -1
- package/docs/integrations/granular-consent.md +3 -1
- package/docs/integrations/heap.md +1 -1
- package/docs/integrations/hightouch.md +1 -1
- package/docs/integrations/hotjar.md +1 -1
- package/docs/integrations/intercom.md +1 -1
- package/docs/integrations/linkedin-insights.md +1 -1
- package/docs/integrations/logrocket.md +1 -1
- package/docs/integrations/matomo-analytics.md +1 -1
- package/docs/integrations/meta-pixel.md +1 -1
- package/docs/integrations/microsoft-clarity.md +1 -1
- package/docs/integrations/microsoft-uet.md +1 -1
- package/docs/integrations/mixpanel-analytics.md +1 -1
- package/docs/integrations/one-dollar-stats.md +305 -0
- package/docs/integrations/openai-pixel.md +1 -1
- package/docs/integrations/overview.md +17 -14
- package/docs/integrations/pinterest-tag.md +321 -0
- package/docs/integrations/pirsch.md +1 -1
- package/docs/integrations/plausible-analytics.md +1 -1
- package/docs/integrations/posthog.md +1 -1
- package/docs/integrations/promptwatch.md +1 -1
- package/docs/integrations/reddit-pixel.md +1 -1
- package/docs/integrations/rudderstack.md +1 -1
- package/docs/integrations/rybbit-analytics.md +1 -1
- package/docs/integrations/segment.md +1 -1
- package/docs/integrations/snapchat-pixel.md +1 -1
- package/docs/integrations/tiktok-pixel.md +1 -1
- package/docs/integrations/umami-analytics.md +1 -1
- package/docs/integrations/vercel-analytics.md +1 -1
- package/docs/integrations/x-pixel.md +1 -1
- package/docs/integrations/youtube.md +1 -1
- package/docs/upgrade-v3.md +129 -1
- package/package.json +25 -2
|
@@ -11,10 +11,53 @@ React, Next.js and Svelte provide `styles.css`. Import the adapter's stylesheet
|
|
|
11
11
|
at the app's global entry point. Vue includes styles in its components; Astro
|
|
12
12
|
adds styles through its integration.
|
|
13
13
|
|
|
14
|
+
The stylesheet blocks rendering, so it carries only what a first paint can
|
|
15
|
+
show: the default tokens, every c15t CSS variable, and the rules for the
|
|
16
|
+
banner, `ConsentDialogTrigger` and the `ConsentGate` placeholder. The consent
|
|
17
|
+
dialog and preference widget bring their own rules. Each rule reaches the page
|
|
18
|
+
once.
|
|
19
|
+
|
|
14
20
|
```tsx
|
|
15
21
|
import 'c15t/react/styles.css';
|
|
16
22
|
```
|
|
17
23
|
|
|
24
|
+
| File | Holds | Loaded by |
|
|
25
|
+
| -------------------------------- | ---------------------------------------------------------------------- | ----------------------------------------------------------------- |
|
|
26
|
+
| `styles.css` or `styles.tw3.css` | Default tokens, all variables, banner, trigger and `ConsentGate` rules | Your app, once |
|
|
27
|
+
| `@c15t/ui/styles/dialog.css` | Dialog and preference widget rules | The dialog component, with its lazy chunk |
|
|
28
|
+
| `@c15t/ui/styles/primitives.css` | Rules for the `@c15t/ui/styles/primitives` class maps | Svelte's `styles.css`, or your app if it renders those class maps |
|
|
29
|
+
| `iab/styles.css` | IAB TCF banner and dialog rules and variables | Your app, after `styles.css` |
|
|
30
|
+
|
|
31
|
+
In React, Next.js and TanStack Start, the dialog's module imports
|
|
32
|
+
`@c15t/ui/styles/dialog.css`. The bundler emits it with the dialog's chunk and
|
|
33
|
+
loads it before that chunk runs, so the dialog never renders unstyled. The
|
|
34
|
+
chunk loads after first paint, by the time the dialog first opens. Do not
|
|
35
|
+
import `dialog.css` yourself. The `@c15t/react/components/consent-dialog`,
|
|
36
|
+
`/components/consent-widget`, `/primitives`, `/primitives/*` and `/iab` entry
|
|
37
|
+
points import it as soon as you import them, because they render dialog parts
|
|
38
|
+
outside the lazy chunk.
|
|
39
|
+
|
|
40
|
+
These modules import the stylesheet through `@c15t/ui/styles/dialog`. Under
|
|
41
|
+
the `node` export condition that module imports nothing, so server code that
|
|
42
|
+
loads `@c15t/react` with plain Node, such as the Pages Router or an SSR build
|
|
43
|
+
that keeps dependencies external, does not fail on the `.css` file. In your
|
|
44
|
+
own components, import `@c15t/ui/styles/dialog` rather than the `.css` file
|
|
45
|
+
if the module can run on the server.
|
|
46
|
+
|
|
47
|
+
Svelte loads its dialog with the page, so `c15t/svelte/styles.css` also
|
|
48
|
+
imports the dialog and primitive rules. Astro injects the banner rules; the
|
|
49
|
+
React and Svelte dialog islands import the rest, and Astro links those
|
|
50
|
+
stylesheets on every page, so in Astro the dialog rules still block rendering.
|
|
51
|
+
Vue components import their own stylesheets.
|
|
52
|
+
|
|
53
|
+
The dialog rules sit in `@layer components` and declare no variables, so
|
|
54
|
+
tokens from `theme`, variables you override in your own CSS, and Tailwind 4
|
|
55
|
+
utilities still win over them even though they load later. If you import
|
|
56
|
+
`styles.css` into a named layer, such as `@import 'c15t/react/styles.css'
|
|
57
|
+
layer(c15t)`, the dialog rules still join the top-level `components` layer.
|
|
58
|
+
List `components` in your layer order statement, for example
|
|
59
|
+
`@layer c15t, components, app;`, so it does not land after your own layers.
|
|
60
|
+
|
|
18
61
|
The standard stylesheet places rules in `@layer components`. For Tailwind 3,
|
|
19
62
|
use the `styles.tw3.css` entry instead of the standard stylesheet, between the
|
|
20
63
|
components and utilities directives in your Tailwind entry:
|
|
@@ -26,6 +69,18 @@ components and utilities directives in your Tailwind entry:
|
|
|
26
69
|
@tailwind utilities;
|
|
27
70
|
```
|
|
28
71
|
|
|
72
|
+
Tailwind 3 also processes the dialog stylesheet the bundler loads, and it
|
|
73
|
+
rejects a stylesheet that uses `@layer components` without its own
|
|
74
|
+
`@tailwind components` directive. Add the c15t plugin before `tailwindcss` in
|
|
75
|
+
your PostCSS config. It removes the layer wrapper from c15t's stylesheets so
|
|
76
|
+
Tailwind 3 accepts them and its preflight does not override them:
|
|
77
|
+
|
|
78
|
+
```js title="postcss.config.mjs"
|
|
79
|
+
export default {
|
|
80
|
+
plugins: ['@c15t/ui/postcss-tailwind3', 'tailwindcss', 'autoprefixer'],
|
|
81
|
+
};
|
|
82
|
+
```
|
|
83
|
+
|
|
29
84
|
Do not load both c15t stylesheet variants. For Tailwind 4 or unlayered CSS,
|
|
30
85
|
inspect layer order before reaching for `!important`.
|
|
31
86
|
|
|
@@ -48,9 +103,17 @@ export const theme = defineTheme({
|
|
|
48
103
|
});
|
|
49
104
|
```
|
|
50
105
|
|
|
51
|
-
Install `@c15t/ui` if importing its theme helper directly.
|
|
52
|
-
|
|
53
|
-
|
|
106
|
+
Install `@c15t/ui` if importing its theme helper directly. The browser does
|
|
107
|
+
not turn tokens into CSS. In React and Next.js, render
|
|
108
|
+
`<ConsentTheme theme={theme} />` where the app renders on the server, and pass
|
|
109
|
+
`theme` in your provider options for `consentActions`. Elsewhere, call
|
|
110
|
+
`generateThemeCSS(theme)` from `@c15t/ui/theme` on the server or at build time
|
|
111
|
+
and put the result in a `<style>` element or your stylesheet. See
|
|
112
|
+
[React styling](https://c15t.com/docs/frameworks/react/styling/overview) and
|
|
113
|
+
[Next.js styling](https://c15t.com/docs/frameworks/next/styling/overview).
|
|
114
|
+
|
|
115
|
+
`consentActions` selects styling by action role. A per-action entry overrides
|
|
116
|
+
`primary`, which overrides `default`.
|
|
54
117
|
|
|
55
118
|
## Target a prompt with CSS
|
|
56
119
|
|
|
@@ -92,3 +92,9 @@ Script gating does not remove cookies or Web Storage entries that a script
|
|
|
92
92
|
already wrote. Configure [clear on revocation](../../integrations/clear-on-revocation.md)
|
|
93
93
|
on your runtime, or attach its module to your existing kernel, to remove
|
|
94
94
|
declared data when its category is denied.
|
|
95
|
+
|
|
96
|
+
## Shared lifecycle controls
|
|
97
|
+
|
|
98
|
+
See [shared consent controls](../../guides/shared-consent-controls.md) for external CMPs,
|
|
99
|
+
preference delegation, withdrawal reloads, and application events. These controls
|
|
100
|
+
use the same core runtime across frameworks.
|
|
@@ -108,26 +108,26 @@ do not add a second provider. Keep your site's content and footer inside it.
|
|
|
108
108
|
|
|
109
109
|
## Pass prepared consent through your router
|
|
110
110
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
111
|
+
In the App Router, the root layout from the
|
|
112
|
+
[App Router guide](https://c15t.com/docs/frameworks/next/app-router) passes the pending
|
|
113
|
+
`resolveConsent` result to this wrapper. This partial example is that call;
|
|
114
|
+
keep the `html`, `body` and stylesheet from your existing layout:
|
|
115
115
|
|
|
116
116
|
```tsx
|
|
117
|
-
import type { ReactNode } from 'react';
|
|
118
117
|
import { resolveConsent } from 'c15t/next/server';
|
|
119
118
|
import { consentConfig } from '../c15t.config';
|
|
120
119
|
import { Consent } from '../components/consent';
|
|
121
120
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
121
|
+
// Inside the existing synchronous root layout:
|
|
122
|
+
const state = resolveConsent({ config: consentConfig });
|
|
123
|
+
|
|
124
|
+
<Consent state={state}>{children}</Consent>
|
|
126
125
|
```
|
|
127
126
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
[
|
|
127
|
+
No script loads until the browser has applied the resolved policy and the
|
|
128
|
+
visitor's choice allows it. With the
|
|
129
|
+
[awaited layout](https://c15t.com/docs/frameworks/next/app-router#render-the-banner-in-the-server-html),
|
|
130
|
+
pass the awaited result from `ResolvedConsent` to the same wrapper instead.
|
|
131
131
|
|
|
132
132
|
Pages Router passes `state={pageProps.consentState ?? {}}` to this wrapper
|
|
133
133
|
in `_app.tsx`. Keep `getServerSideProps` and its `c15t/next/pages` helper.
|
|
@@ -208,3 +208,9 @@ already wrote. Add `clearOnRevocation` to your `ConsentRoot` or provider
|
|
|
208
208
|
options to remove declared data when its category is denied. See
|
|
209
209
|
[clear on revocation](../../integrations/clear-on-revocation.md) for configuration
|
|
210
210
|
and browser limits.
|
|
211
|
+
|
|
212
|
+
## Shared lifecycle controls
|
|
213
|
+
|
|
214
|
+
See [shared consent controls](../../guides/shared-consent-controls.md) for external CMPs,
|
|
215
|
+
preference delegation, withdrawal reloads, and application events. These controls
|
|
216
|
+
use the same core runtime across frameworks.
|
|
@@ -61,3 +61,9 @@ already wrote. Add `clearOnRevocation` to `ConsentProvider.options` to remove
|
|
|
61
61
|
declared data when its category is denied. See
|
|
62
62
|
[clear on revocation](../../integrations/clear-on-revocation.md) for configuration
|
|
63
63
|
and browser limits.
|
|
64
|
+
|
|
65
|
+
## Shared lifecycle controls
|
|
66
|
+
|
|
67
|
+
See [shared consent controls](../../guides/shared-consent-controls.md) for external CMPs,
|
|
68
|
+
preference delegation, withdrawal reloads, and application events. These controls
|
|
69
|
+
use the same core runtime across frameworks.
|
|
@@ -20,6 +20,23 @@ grant.
|
|
|
20
20
|
| Explain regional behavior | `policyRule` |
|
|
21
21
|
| Diagnose initialization | `resolution` |
|
|
22
22
|
|
|
23
|
+
## Gate IAB vendors on the TC string
|
|
24
|
+
|
|
25
|
+
Under an IAB policy, a script, network rule or iframe that names a `vendorId`
|
|
26
|
+
or IAB purposes is an IAB target. It runs only while a confirmed TC string
|
|
27
|
+
grants what it declares: purpose and vendor consent for `iabPurposes`, purpose
|
|
28
|
+
and vendor legitimate interest for `iabLegIntPurposes`, and opt-ins for
|
|
29
|
+
`iabSpecialFeatures`. Every category it names must also be free of
|
|
30
|
+
restrictions, so GPC, an opt-out directive or strict scope blocks it.
|
|
31
|
+
|
|
32
|
+
A refused category is the one exception. It does not block an IAB target that
|
|
33
|
+
processes only on legitimate interest, after publisher restrictions, because
|
|
34
|
+
the TCF lets that processing run without consent. The visitor's control for it
|
|
35
|
+
is the objection, which the legitimate interest signals record. The category
|
|
36
|
+
itself stays refused: its `effectivePermissions` entry is `false`, and targets
|
|
37
|
+
that name only the category, or that also declare a consent purpose or special
|
|
38
|
+
feature, stay blocked.
|
|
39
|
+
|
|
23
40
|
## Record only explicit visitor actions
|
|
24
41
|
|
|
25
42
|
```ts
|
|
@@ -37,6 +54,45 @@ confirmation times. Do not call all three in one handler.
|
|
|
37
54
|
changes in effective permissions, including changes caused by expiry or privacy
|
|
38
55
|
signals. Hydration must not be counted as another visitor choice.
|
|
39
56
|
|
|
57
|
+
## When a choice is saved
|
|
58
|
+
|
|
59
|
+
A save records the choice in the browser first and sends it to the backend
|
|
60
|
+
afterwards. The stock banner, preference dialog and IAB surfaces in every
|
|
61
|
+
framework adapter, and the browser client's `acceptAll()`, `rejectAll()`
|
|
62
|
+
and `save()`, close without waiting for the backend. In order:
|
|
63
|
+
|
|
64
|
+
1. In the click task, the explicit choice and effective permissions change,
|
|
65
|
+
`onChoiceRecorded` and `onPermissionsChanged` run, gated scripts, iframes
|
|
66
|
+
and network rules follow the new permissions, and the surface leaves the
|
|
67
|
+
active state. Its exit animation still plays.
|
|
68
|
+
2. In the next task, the choice is written to the cookie and localStorage.
|
|
69
|
+
3. After that write is queued, the request to the backend starts.
|
|
70
|
+
4. When the request settles, the kernel emits `command:save:completed`. The
|
|
71
|
+
promise returned by `kernel.commands.save()`, React's `performAction()` and
|
|
72
|
+
Svelte's `saveConsents()` resolves or rejects only then.
|
|
73
|
+
5. If the save turned off a category or vendor that was granted, the page
|
|
74
|
+
reloads in the next task, after `onBeforeConsentRevocationReload` runs.
|
|
75
|
+
Removing a script cannot stop code that already ran, so the reload starts a
|
|
76
|
+
page with only permitted code. With several saves in flight, it waits for
|
|
77
|
+
the last one. Set `reloadOnConsentRevoked: false` to handle revocation
|
|
78
|
+
yourself.
|
|
79
|
+
|
|
80
|
+
A failed request does not reopen the surface or roll the choice back. The
|
|
81
|
+
kernel emits `command:error`, which reaches the `onError` callback in adapters
|
|
82
|
+
that accept one, and queues the payload in localStorage. The queue is replayed
|
|
83
|
+
after the next successful initialization and when the browser comes back
|
|
84
|
+
online, up to 10 attempts over 7 days. A replay carries the original action
|
|
85
|
+
time and policy snapshot token, so the backend records when the visitor
|
|
86
|
+
decided, and a duplicate submission resolves to the same consent record. A
|
|
87
|
+
backend that signs policy snapshot tokens rejects a replay made after the
|
|
88
|
+
token expires, which is 30 minutes by default for the self-hosted backend. A
|
|
89
|
+
save still queued by then is recorded only in the browser.
|
|
90
|
+
|
|
91
|
+
IAB surfaces close in the click task too, but an IAB choice is recorded only
|
|
92
|
+
after its TC string is encoded, which can wait for the TCF library to load.
|
|
93
|
+
If that local step records nothing, for example because the vendor list
|
|
94
|
+
failed to load, the surface comes back so the visitor can try again.
|
|
95
|
+
|
|
40
96
|
## Treat notices and privacy signals separately
|
|
41
97
|
|
|
42
98
|
`commands.dismissNotice()` acknowledges the current notice. It does not grant
|
|
@@ -58,3 +114,274 @@ would invent a grant and lose its original confirmation time.
|
|
|
58
114
|
Valid v2 records can be read without a startup rewrite. The next explicit action
|
|
59
115
|
writes the v3 format. See [migration](../upgrade-v3.md) for expiry, partial saves,
|
|
60
116
|
custom transports and backend contract changes.
|
|
117
|
+
|
|
118
|
+
## Keep open tabs in step
|
|
119
|
+
|
|
120
|
+
Tabs and windows on the same origin (scheme, host and port) share the consent
|
|
121
|
+
cookie and localStorage. When a visitor rejects in one tab, every other open tab
|
|
122
|
+
on that origin applies the rejection without a reload. Scripts and features
|
|
123
|
+
gated on `effectivePermissions` lose permission, subscribers are notified once
|
|
124
|
+
and `onPermissionsChanged` fires. Clearing records in one tab returns the others
|
|
125
|
+
to the active policy's defaults: an opt-in policy denies optional categories and
|
|
126
|
+
shows the prompt again.
|
|
127
|
+
|
|
128
|
+
Tabs on another subdomain that shares the consent cookie do not share
|
|
129
|
+
localStorage, so the browser sends them no `storage` event. They pick up the
|
|
130
|
+
change on their next focus or visibility change, or when you reconcile
|
|
131
|
+
yourself (see below).
|
|
132
|
+
|
|
133
|
+
The `storage` event only exists for localStorage. When localStorage is
|
|
134
|
+
unavailable (blocked by the browser, a sandboxed frame or a privacy mode) and
|
|
135
|
+
c15t stores in the cookie alone, another tab's change arrives only on the next
|
|
136
|
+
focus or visibility change, or when you call `runtime.reconcileStorage()` or
|
|
137
|
+
`persistence.reconcile()`. c15t does not poll the cookie or use a
|
|
138
|
+
`BroadcastChannel` for this.
|
|
139
|
+
|
|
140
|
+
Browser persistence reads stored records again at these moments:
|
|
141
|
+
|
|
142
|
+
| Moment | What happens |
|
|
143
|
+
| ------------------------------------------------------------------------ | --------------------------------- |
|
|
144
|
+
| Another tab or window on the same origin changes a c15t localStorage key | Reconciles on the `storage` event |
|
|
145
|
+
| The page becomes visible again | Reconciles on `visibilitychange` |
|
|
146
|
+
| The window regains focus | Reconciles on `focus` |
|
|
147
|
+
| The network reconnects | No storage read |
|
|
148
|
+
|
|
149
|
+
Several triggers in quick succession run one reconciliation in a later task.
|
|
150
|
+
Reconnecting does not read storage, because going online changes nothing in
|
|
151
|
+
browser storage. On reconnect the kernel retries saves the backend did not
|
|
152
|
+
accept and a failed initialization. Save retries do not write the cookie or
|
|
153
|
+
localStorage. A write that follows initialization, such as a Global Privacy
|
|
154
|
+
Control directive, obeys the ordering described below.
|
|
155
|
+
|
|
156
|
+
Every adapter that mounts browser persistence does this: the React, Next.js and
|
|
157
|
+
TanStack Start providers, Vue, Svelte, Astro, the script tag and
|
|
158
|
+
`createConsentRuntime`. With `persistence: false` nothing is stored or read.
|
|
159
|
+
|
|
160
|
+
### What a reconciliation applies
|
|
161
|
+
|
|
162
|
+
Stored records are merged into the ones in memory:
|
|
163
|
+
|
|
164
|
+
* Category decisions merge per category. Each category keeps the decision with
|
|
165
|
+
the newer confirmation time, so a tab that only changed marketing never
|
|
166
|
+
reverts another tab's newer measurement decision.
|
|
167
|
+
* Privacy directives, such as a Global Privacy Control opt-out, merge as a
|
|
168
|
+
union. A directive only restricts, so none is dropped.
|
|
169
|
+
* The notice dismissal and the vendor record are single decisions. A stored one
|
|
170
|
+
at least as new as the one in memory replaces it; an older one is ignored.
|
|
171
|
+
* When two tabs record decisions in the same millisecond, the one stored first
|
|
172
|
+
wins in both tabs.
|
|
173
|
+
* Tabs keep one subject. A stored subject is considered only when the record
|
|
174
|
+
that carries it changed, never on focus alone. It replaces a subject the tab
|
|
175
|
+
generated on its first save or copied from storage, so a tab that opened
|
|
176
|
+
before another tab stored a subject joins it. A subject id the server
|
|
177
|
+
resolved (at init, from a prefetch or in a save response) is replaced only by
|
|
178
|
+
a strictly newer stored choice, and an identity set with `identify()` is
|
|
179
|
+
never replaced.
|
|
180
|
+
* Under an IAB policy, the `@c15t/iab` module then loads the TC string the other
|
|
181
|
+
tab stored, together with its purpose, vendor and special-feature selections,
|
|
182
|
+
so `__tcfapi` and the preference controls show the choice now in force.
|
|
183
|
+
Selections the visitor changed in this tab without saving are kept. A missing
|
|
184
|
+
or older stored TC string leaves the current one in place, unless it conflicts
|
|
185
|
+
with the reconciled choice: then it is withdrawn and `__tcfapi` reports no
|
|
186
|
+
consent until the next save. A category denied after the TC string was saved
|
|
187
|
+
conflicts if the TC string grants any of its purposes. A partial selection
|
|
188
|
+
saved through IAB, which records its category as denied because not every
|
|
189
|
+
purpose is granted, keeps its TC string. A TC string confirmed before the
|
|
190
|
+
choice's newest decision no longer describes it and is withdrawn too, unless
|
|
191
|
+
a newer receipt replaces it. That receipt is adopted even when its TC string
|
|
192
|
+
is identical, since TC strings round their time to the day and custom-vendor
|
|
193
|
+
selections live only in the receipt; its expiry then applies. The TC
|
|
194
|
+
string and its receipt (`euconsent-v2`, `c15t-iab-authority-v1`) belong to one
|
|
195
|
+
origin, so after a save on a sibling subdomain that shares the consent cookie,
|
|
196
|
+
this subdomain reports no consent through `__tcfapi` until it saves again.
|
|
197
|
+
Vendors never receive the stale TC string in between: it is withdrawn, or
|
|
198
|
+
held back, before `__tcfapi` publishes. A tab also reloads the TC string
|
|
199
|
+
when another tab on the same origin stores a new one, which covers a save in
|
|
200
|
+
the same millisecond or one that changed only vendors. When two tabs save in
|
|
201
|
+
the same millisecond with different selections, the more restrictive TC
|
|
202
|
+
string wins in both, so a revoked vendor is never advertised again. If each
|
|
203
|
+
grants something the other denies, neither is published until the next save:
|
|
204
|
+
the stored receipt is removed, so a page opened later does not restore it.
|
|
205
|
+
When another tab removes the receipt, or clears localStorage, the TC string
|
|
206
|
+
is withdrawn here too, since a page opened now would find none, and a
|
|
207
|
+
receipt this tab was still decoding is not installed. The removal after a
|
|
208
|
+
tie checks that the stored receipt is the one it read, but localStorage has
|
|
209
|
+
no conditional removal, so a receipt another tab stored a moment earlier can
|
|
210
|
+
still be removed. Every tab then withdraws its TC string until the next save,
|
|
211
|
+
so the race only ever withholds consent.
|
|
212
|
+
* A record removed from readable storage since this tab last saw it present is
|
|
213
|
+
cleared, and the active policy decides again. A record this tab never saw in
|
|
214
|
+
storage, such as a receipt merged from the server after `identify()` or a
|
|
215
|
+
choice seeded while storage was blocked, stays.
|
|
216
|
+
* Blocked storage, or bytes that do not decode, change nothing. A failed read
|
|
217
|
+
never grants a category.
|
|
218
|
+
|
|
219
|
+
Expiry is not decided here. The applied records are evaluated at the time of the
|
|
220
|
+
read, the same way as at startup.
|
|
221
|
+
|
|
222
|
+
### Clearing records across tabs
|
|
223
|
+
|
|
224
|
+
`clearRecords()` removes every record and then stores the time of the clear,
|
|
225
|
+
the clear epoch, under its own key: `c15t-epoch` in localStorage and a cookie
|
|
226
|
+
of the same name (`<storageKey>-epoch` with a custom `storageKey`). Clearing
|
|
227
|
+
never removes it. Every consent record written afterwards also records the
|
|
228
|
+
epoch it was written under.
|
|
229
|
+
|
|
230
|
+
A decision confirmed before the epoch was made before the clear, so it is void
|
|
231
|
+
wherever it turns up. A decision stamped in the very millisecond of the clear
|
|
232
|
+
counts only if it comes from a tab that had already seen that clear, so a tab's
|
|
233
|
+
own choice right after its own clear stands while another tab's decision in the
|
|
234
|
+
same millisecond does not. A stored record left with no decisions after the
|
|
235
|
+
clear is void too, subject included.
|
|
236
|
+
|
|
237
|
+
* A tab that reconciles only after another tab cleared and saved again drops
|
|
238
|
+
its pre-clear decisions instead of merging them back. Its subject from before
|
|
239
|
+
the clear is dropped too.
|
|
240
|
+
* A tab that missed the clear writes only decisions it made after it. Its queued
|
|
241
|
+
write of an earlier decision is discarded, so it cannot bring back a cleared
|
|
242
|
+
record.
|
|
243
|
+
* Browser hydration and server reads (`readStoredRecordsFromCookieHeader`, used
|
|
244
|
+
by the Next.js, TanStack Start, Nuxt, SvelteKit and Astro helpers) apply the
|
|
245
|
+
same rule, so a server render agrees with the browser.
|
|
246
|
+
|
|
247
|
+
Records from before any clear, including v2 and legacy records, read as epoch 0
|
|
248
|
+
and are unaffected. A corrupt epoch, or one that cannot be read, also reads as
|
|
249
|
+
0: it voids nothing, so a failed read never grants a category. A consent record
|
|
250
|
+
whose own epoch field is corrupt is kept, and only its epoch is ignored.
|
|
251
|
+
|
|
252
|
+
Each clear moves the epoch forward, even when the device clock went back, so a
|
|
253
|
+
later clear never lets earlier decisions back in. Two clears in the same
|
|
254
|
+
millisecond therefore leave the epoch a millisecond ahead, and a decision saved
|
|
255
|
+
in that millisecond is void. An epoch up to one hour ahead
|
|
256
|
+
of the clock is kept, as it is when the clock was set back after a clear. Until
|
|
257
|
+
the clock catches up, decisions saved in that window are void too. An epoch more
|
|
258
|
+
than an hour ahead is treated as corrupt and reads as 0, so a clear never writes
|
|
259
|
+
one: after the clock went back more than an hour, the new epoch is capped at an
|
|
260
|
+
hour ahead of the clock.
|
|
261
|
+
|
|
262
|
+
That cap is a known limit. A cleared record carries times from before the clock
|
|
263
|
+
went back, and a runtime that missed the clear can write those times back. The
|
|
264
|
+
capped epoch is lower than them, so once the clock has recovered, such a
|
|
265
|
+
decision counts again. Leaving the epoch uncapped does not help: every tab
|
|
266
|
+
whose clock is still behind reads it as corrupt, which voids nothing. Times
|
|
267
|
+
alone cannot order a clear against decisions stamped by a clock that went back
|
|
268
|
+
more than an hour.
|
|
269
|
+
|
|
270
|
+
This changes the stored format. After a clear, the consent cookie carries
|
|
271
|
+
`&e=<time>` (16 bytes) and the localStorage record an `epoch` field (22 bytes),
|
|
272
|
+
and the epoch cookie itself holds a 13-digit time. Visitors who never cleared
|
|
273
|
+
their records store exactly what they did before. An older c15t build rejects
|
|
274
|
+
both the cookie and the localStorage record once they carry the epoch, so a page
|
|
275
|
+
still running one treats the visitor as undecided. Under an opt-out policy that
|
|
276
|
+
page grants optional categories by default until a new choice is saved, and the
|
|
277
|
+
configured prompt may appear again. Deploy the new build to every page of the
|
|
278
|
+
site before visitors can clear their records.
|
|
279
|
+
|
|
280
|
+
### When the cookie and localStorage disagree
|
|
281
|
+
|
|
282
|
+
When both copies hold a decision for a category from the same millisecond and
|
|
283
|
+
the two conflict, the denial wins.
|
|
284
|
+
|
|
285
|
+
The subject and IAB metadata come from the cookie. A server response, such as
|
|
286
|
+
server-side consent restoration, and a sibling subdomain sharing the cookie
|
|
287
|
+
with `crossSubdomain` can both rewrite it without touching this origin's
|
|
288
|
+
localStorage, so the local copy can be the older one. The local copy's subject
|
|
289
|
+
is used only when this browser's last consent write reached localStorage but
|
|
290
|
+
not the cookie, for example because the cookie grew past the size limit, and
|
|
291
|
+
the cookie has not changed since. Such a write stores the cookie as it stood
|
|
292
|
+
under `<storageKey>-cookie-miss` in localStorage; the next write that reaches
|
|
293
|
+
the cookie, or a clear, removes it. When localStorage rejects a write that the
|
|
294
|
+
cookie takes, for example because storage is full, the older localStorage copy
|
|
295
|
+
is removed.
|
|
296
|
+
|
|
297
|
+
When a server render seeded the page from the consent cookie
|
|
298
|
+
(`skipHydration`), that seed stays authoritative. A denial or privacy directive
|
|
299
|
+
that reached only localStorage is still applied on top of it when the page
|
|
300
|
+
mounts, since it can only restrict, if it is newer than the seeded decision or
|
|
301
|
+
from the same millisecond as a seeded grant. A stored grant is not.
|
|
302
|
+
|
|
303
|
+
The notice dismissal, privacy directives and vendor denials are stored twice
|
|
304
|
+
as well. Privacy directives from both copies all apply. A vendor list in
|
|
305
|
+
localStorage at least as new as the cookie's adds its denials but never lifts
|
|
306
|
+
one the cookie holds; a copy confirmed before the last clear is ignored, so its
|
|
307
|
+
denials never come back. The newer notice dismissal applies; it still only hides a
|
|
308
|
+
notice with the fingerprint it names. The consent record follows the rules
|
|
309
|
+
below.
|
|
310
|
+
|
|
311
|
+
The consent record is stored twice: as a cookie, which a server render reads,
|
|
312
|
+
and in localStorage. The cookie is authoritative. A well-formed cookie wins
|
|
313
|
+
even when it has expired, so a local copy can never bring back a grant the
|
|
314
|
+
cookie no longer carries.
|
|
315
|
+
|
|
316
|
+
A browser can still drop a cookie write, for example when the record grows past
|
|
317
|
+
the cookie size limit, while localStorage takes it. A denial in the local copy
|
|
318
|
+
that is newer than the cookie's decision for that category is therefore applied
|
|
319
|
+
on top of the cookie. A newer local grant is not, so a dropped cookie write only
|
|
320
|
+
ever leaves the visitor with less permission. A server render sees only the
|
|
321
|
+
cookie; after a dropped write that carried a denial, the browser is the stricter
|
|
322
|
+
of the two.
|
|
323
|
+
|
|
324
|
+
When the two copies were written under different clear epochs, each loses its
|
|
325
|
+
decisions from before the later epoch first, and the same rule applies to what
|
|
326
|
+
remains. A later epoch in the local copy never lets its grant replace a cookie
|
|
327
|
+
denial. The subject and IAB metadata come from the copy written under the later
|
|
328
|
+
epoch; a record written before the clear in force keeps its later decisions but
|
|
329
|
+
no subject.
|
|
330
|
+
|
|
331
|
+
A server render cannot know about a clear that never reached a cookie. If the
|
|
332
|
+
page could write localStorage but its cookie writes failed during
|
|
333
|
+
`clearRecords()` (cookies blocked for the page, or a cookie setter that
|
|
334
|
+
throws), the removal of the consent cookie failed too, and so did the epoch
|
|
335
|
+
cookie. The browser then applies the clear from localStorage, while a server
|
|
336
|
+
render still reads the old consent cookie until the next successful cookie
|
|
337
|
+
write. The same applies to a consent cookie set with a different `domain` than
|
|
338
|
+
the current `storageConfig` uses, which the clear cannot remove.
|
|
339
|
+
|
|
340
|
+
### Ordering with pending writes
|
|
341
|
+
|
|
342
|
+
A tab writes its own choices in a later task, not during the click. Before it
|
|
343
|
+
reads storage, it lands its own queued writes, so a reconciliation never undoes
|
|
344
|
+
the visitor's latest action in that tab. A queued write follows the same rules
|
|
345
|
+
as a read: it stores the per-category merge of its choice and the stored one,
|
|
346
|
+
the union of directives, and never replaces a newer notice or vendor record. It
|
|
347
|
+
keeps the stored subject unless this tab identified a different user.
|
|
348
|
+
When a slow save response returns a server subject id, the tab adds it only to
|
|
349
|
+
the record it wrote; it does not recreate records another tab cleared or
|
|
350
|
+
overwrite another tab's newer choice.
|
|
351
|
+
|
|
352
|
+
Two tabs that write at the same moment can both read storage before either
|
|
353
|
+
writes, and the later write can then drop the other tab's category or privacy
|
|
354
|
+
directive. The tab whose decision was dropped still holds it, and on its next
|
|
355
|
+
reconciliation it writes it back, merged with what storage holds. It does so
|
|
356
|
+
only for decisions it actually stored itself, never for one a clear voided or
|
|
357
|
+
another tab replaced with a newer one. A directive write stores the directives
|
|
358
|
+
it kept from storage too, so if another write drops one of those, this tab
|
|
359
|
+
restores it and applies it as well.
|
|
360
|
+
|
|
361
|
+
If another tab's change reaches this tab while one of its saves is pending, the
|
|
362
|
+
save depends on how far it got. A save not yet sent is dropped. A request
|
|
363
|
+
already sent still reaches the backend, which may record it; this tab ignores
|
|
364
|
+
the response, so it queues no retry and applies no subject id from it. A save
|
|
365
|
+
already queued for retry keeps its original decision time.
|
|
366
|
+
|
|
367
|
+
### Reconcile yourself or turn it off
|
|
368
|
+
|
|
369
|
+
Browsers send no event for a change made in the same document, or for a cookie
|
|
370
|
+
rewritten without a localStorage change, such as a `Set-Cookie` response header
|
|
371
|
+
or another subdomain sharing the cookie. The next focus or visibility change
|
|
372
|
+
picks it up. To apply it at once, call the method yourself:
|
|
373
|
+
|
|
374
|
+
```ts
|
|
375
|
+
// Runtime owners: returns true when any record changed.
|
|
376
|
+
runtime.reconcileStorage();
|
|
377
|
+
|
|
378
|
+
// Kernel owners with createPersistence from c15t/modules/persistence:
|
|
379
|
+
persistence.reconcile();
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
To keep storage but stop automatic reconciliation, pass `sync: false` in the
|
|
383
|
+
persistence options, for example `createConsentRuntime({ persistence: { sync:
|
|
384
|
+
false } })` or `createPersistence({ kernel, sync: false })`. The manual methods
|
|
385
|
+
still work.
|
|
386
|
+
|
|
387
|
+
`dispose()` removes the listeners and cancels a scheduled reconciliation.
|