@c15t/nextjs 2.0.0-rc.0 → 2.0.0-rc.10
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/README.md +10 -3
- package/client/components/consent-dialog-link.js +3 -0
- package/dist/headless.cjs +1 -1
- package/dist/iab/styles.css +12 -0
- package/dist/iab/styles.tw3.css +14 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/libs/browser-initial-data.cjs +1 -0
- package/dist/libs/browser-initial-data.js +1 -0
- package/dist/libs/initial-data.cjs +1 -1
- package/dist/libs/initial-data.js +1 -1
- package/dist/styles.css +10 -0
- package/dist/styles.tw3.css +13 -0
- package/dist/types.cjs +1 -1
- package/dist/version.cjs +1 -1
- package/dist/version.js +1 -1
- package/{dist → dist-types}/headless.d.ts +0 -1
- package/{dist → dist-types}/index.d.ts +3 -2
- package/dist-types/libs/browser-initial-data.d.ts +9 -0
- package/{dist → dist-types}/libs/initial-data.d.ts +7 -2
- package/dist-types/types.d.ts +38 -0
- package/dist-types/version.d.ts +1 -0
- package/docs/README.md +73 -0
- package/docs/building-headless-components.md +377 -0
- package/docs/callbacks.md +184 -0
- package/docs/components/consent-banner.md +269 -0
- package/docs/components/consent-dialog-link.md +59 -0
- package/docs/components/consent-dialog-trigger.md +103 -0
- package/docs/components/consent-dialog.md +177 -0
- package/docs/components/consent-manager-provider.md +425 -0
- package/docs/components/consent-widget.md +133 -0
- package/docs/components/dev-tools.md +63 -0
- package/docs/components/frame.md +73 -0
- package/docs/concepts/client-modes.md +175 -0
- package/docs/concepts/consent-categories.md +97 -0
- package/docs/concepts/consent-models.md +116 -0
- package/docs/concepts/cookie-management.md +122 -0
- package/docs/concepts/glossary.md +23 -0
- package/docs/concepts/initialization-flow.md +148 -0
- package/docs/concepts/policy-packs.md +229 -0
- package/docs/headless.md +190 -0
- package/docs/hooks/use-color-scheme.md +40 -0
- package/docs/hooks/use-consent-manager/checking-consent.md +94 -0
- package/docs/hooks/use-consent-manager/location-info.md +95 -0
- package/docs/hooks/use-consent-manager/overview.md +420 -0
- package/docs/hooks/use-consent-manager/setting-consent.md +92 -0
- package/docs/hooks/use-draggable.md +57 -0
- package/docs/hooks/use-focus-trap.md +41 -0
- package/docs/hooks/use-reduced-motion.md +35 -0
- package/docs/hooks/use-ssr-status.md +31 -0
- package/docs/hooks/use-text-direction.md +49 -0
- package/docs/hooks/use-translations.md +118 -0
- package/docs/iab/consent-banner.md +94 -0
- package/docs/iab/consent-dialog.md +134 -0
- package/docs/iab/overview.md +126 -0
- package/docs/iab/use-gvl-data.md +20 -0
- package/docs/iframe-blocking.md +107 -0
- package/docs/integrations/building-integrations.md +405 -0
- package/docs/integrations/databuddy.md +203 -0
- package/docs/integrations/google-tag-manager.md +153 -0
- package/docs/integrations/google-tag.md +122 -0
- package/docs/integrations/linkedin-insights.md +109 -0
- package/docs/integrations/meta-pixel.md +342 -0
- package/docs/integrations/microsoft-uet.md +112 -0
- package/docs/integrations/overview.md +105 -0
- package/docs/integrations/posthog.md +199 -0
- package/docs/integrations/tiktok-pixel.md +113 -0
- package/docs/integrations/x-pixel.md +143 -0
- package/docs/internationalization.md +197 -0
- package/docs/network-blocker.md +178 -0
- package/docs/optimization.md +234 -0
- package/docs/policy-packs.md +246 -0
- package/docs/quickstart.md +161 -0
- package/docs/script-loader.md +321 -0
- package/docs/server-side.md +176 -0
- package/docs/styling/classnames.md +92 -0
- package/docs/styling/color-scheme.md +82 -0
- package/docs/styling/css-variables.md +92 -0
- package/docs/styling/overview.md +456 -0
- package/docs/styling/slots.md +127 -0
- package/docs/styling/tailwind.md +113 -0
- package/docs/styling/tokens.md +216 -0
- package/docs/troubleshooting.md +146 -0
- package/iab/styles.css +1 -0
- package/package.json +38 -17
- package/readme.json +4 -0
- package/src/iab/styles.css +12 -0
- package/src/iab/styles.tw3.css +14 -0
- package/src/styles.css +10 -0
- package/src/styles.tw3.css +13 -0
- package/styles.css +1 -0
- package/dist/headless.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/libs/initial-data.d.ts.map +0 -1
- package/dist/types.d.ts +0 -16
- package/dist/types.d.ts.map +0 -1
- package/dist/version.d.ts +0 -2
- package/dist/version.d.ts.map +0 -1
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: IAB TCF 2.3
|
|
3
|
+
description: Implement IAB Transparency & Consent Framework 2.3 compliance for programmatic advertising in EU/EEA jurisdictions.
|
|
4
|
+
---
|
|
5
|
+
## What is IAB TCF?
|
|
6
|
+
|
|
7
|
+
The [IAB Transparency & Consent Framework (TCF)](https://iabeurope.eu/tcf-2-0/) is a standardized protocol for communicating user consent choices to ad tech vendors in the programmatic advertising ecosystem. TCF 2.3 is the current version and is widely adopted across the EU/EEA.
|
|
8
|
+
|
|
9
|
+
When your site participates in the IAB ecosystem (ad exchanges, SSPs, DSPs, DMPs), you need to:
|
|
10
|
+
|
|
11
|
+
* Disclose which vendors process user data and for what purposes
|
|
12
|
+
* Collect granular consent for each IAB-defined purpose
|
|
13
|
+
* Generate a **TC String** — a standardized encoding of consent choices that ad tech vendors can read
|
|
14
|
+
* Expose the `__tcfapi` CMP stub for vendor scripts to query consent status
|
|
15
|
+
|
|
16
|
+
## CMP Registration
|
|
17
|
+
|
|
18
|
+
[inth.com](https://inth.com) is pending validation as an IAB Europe-registered CMP for c15t. Once approved, when you use inth.com as your backend, the correct CMP ID will be automatically provided to your client via the `/init` endpoint — no client-side configuration needed.
|
|
19
|
+
|
|
20
|
+
If you self-host the c15t backend and have your own CMP registration with IAB Europe, you can configure your CMP ID on the backend via `advanced.iab.cmpId` or on the client via the `iab.cmpId` option. A valid (non-zero) CMP ID is required for IAB TCF compliance.
|
|
21
|
+
|
|
22
|
+
> ℹ️ **Info:**
|
|
23
|
+
> If you heavily customize or build your own IAB banner or dialog (rather than using the default IABConsentBanner and IABConsentDialog components), you cannot use inth.com's CMP ID. You must register your own CMP with IAB Europe and use your own CMP ID.
|
|
24
|
+
|
|
25
|
+
## How c15t Implements TCF
|
|
26
|
+
|
|
27
|
+
c15t provides a complete IAB TCF 2.3 CMP (Consent Management Platform) implementation:
|
|
28
|
+
|
|
29
|
+
1. **Global Vendor List (GVL)** — Automatically fetched from the c15t backend. Contains the official IAB vendor registry with purposes, features, and stacks.
|
|
30
|
+
2. **IABConsentBanner** — A pre-built banner showing partner count, purpose summaries, and legitimate interest notices.
|
|
31
|
+
3. **IABConsentDialog** — A tabbed preference center for granular purpose and vendor consent management.
|
|
32
|
+
4. **TC String generation** — Consent choices are encoded into the standard TC String format.
|
|
33
|
+
5. **`__tcfapi` stub** — The standard CMP API is exposed on `window` so vendor scripts can query consent.
|
|
34
|
+
|
|
35
|
+
If you use the prebuilt styled IAB UI, add your framework's `iab/styles.css` entrypoint alongside the base c15t stylesheet. IAB CSS is published separately so apps that do not render IAB surfaces do not ship those component rules.
|
|
36
|
+
|
|
37
|
+
## Quick Setup
|
|
38
|
+
|
|
39
|
+
If you use the prebuilt styled IAB UI, import the IAB stylesheet alongside the base stylesheet in your global CSS entrypoint:
|
|
40
|
+
|
|
41
|
+
```css title="src/app/globals.css"
|
|
42
|
+
@import "@c15t/nextjs/styles.css";
|
|
43
|
+
@import "@c15t/nextjs/iab/styles.css";
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
```tsx
|
|
47
|
+
import { type ReactNode } from 'react';
|
|
48
|
+
import { iab } from '@c15t/iab';
|
|
49
|
+
import { ConsentManagerProvider } from '@c15t/nextjs';
|
|
50
|
+
import { IABConsentBanner, IABConsentDialog } from '@c15t/react/iab';
|
|
51
|
+
|
|
52
|
+
export default function ConsentManager({ children }: { children: ReactNode }) {
|
|
53
|
+
return (
|
|
54
|
+
<ConsentManagerProvider
|
|
55
|
+
options={{
|
|
56
|
+
mode: 'hosted',
|
|
57
|
+
backendURL: '/api/c15t',
|
|
58
|
+
iab: iab({
|
|
59
|
+
vendors: [1, 2, 10, 25], // IAB vendor IDs you work with
|
|
60
|
+
// cmpId is automatically provided by the backend (inth.com).
|
|
61
|
+
// Only set this if you have your own CMP registration with IAB Europe.
|
|
62
|
+
// cmpId: 123,
|
|
63
|
+
}),
|
|
64
|
+
}}
|
|
65
|
+
>
|
|
66
|
+
<IABConsentBanner />
|
|
67
|
+
<IABConsentDialog showTrigger />
|
|
68
|
+
{children}
|
|
69
|
+
</ConsentManagerProvider>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## IAB Configuration Options
|
|
75
|
+
|
|
76
|
+
Configure IAB mode with `iab({ ... })` from `@c15t/iab`. The factory enables the addon and injects the runtime module automatically. The user-facing options are:
|
|
77
|
+
|
|
78
|
+
|Option|Type|Description|
|
|
79
|
+
|--|--|--|
|
|
80
|
+
|`cmpId`|`number`|CMP ID registered with IAB Europe. Automatically provided by the backend when using inth.com. Only set this if you have your own CMP registration.|
|
|
81
|
+
|`vendors`|`number[]`|IAB vendor IDs that your site works with|
|
|
82
|
+
|`customVendors`|`NonIABVendor[]`|Custom vendors not in the IAB registry|
|
|
83
|
+
|
|
84
|
+
## Key Concepts
|
|
85
|
+
|
|
86
|
+
### Purposes
|
|
87
|
+
|
|
88
|
+
IAB defines 11 standard purposes for data processing (e.g., "Store and/or access information on a device", "Select basic ads", "Measure ad performance"). Each purpose can be consented to individually.
|
|
89
|
+
|
|
90
|
+
### Stacks
|
|
91
|
+
|
|
92
|
+
Purposes are grouped into **stacks** by the GVL for a simplified UI presentation. For example, "Advertising based on limited data" might group purposes 2, 7, and 10 together.
|
|
93
|
+
|
|
94
|
+
### Special Features
|
|
95
|
+
|
|
96
|
+
Features like precise geolocation or device scanning that require explicit opt-in beyond standard consent.
|
|
97
|
+
|
|
98
|
+
### Legitimate Interest
|
|
99
|
+
|
|
100
|
+
Some purposes can be processed under legitimate interest rather than consent. Users can object to legitimate interest processing per-vendor.
|
|
101
|
+
|
|
102
|
+
### Vendors
|
|
103
|
+
|
|
104
|
+
Each vendor in the GVL declares which purposes it uses, whether via consent or legitimate interest. The preference center lets users toggle consent per-vendor.
|
|
105
|
+
|
|
106
|
+
## Standard vs IAB Components
|
|
107
|
+
|
|
108
|
+
|Feature|ConsentBanner / ConsentDialog|IABConsentBanner / IABConsentDialog|
|
|
109
|
+
|--|--|--|
|
|
110
|
+
|Consent model|opt-in / opt-out|IAB TCF 2.3|
|
|
111
|
+
|Granularity|Category-level (measurement, marketing, etc.)|Purpose-level + vendor-level|
|
|
112
|
+
|Vendor management|No|Yes (full GVL integration)|
|
|
113
|
+
|TC String|No|Yes|
|
|
114
|
+
|`__tcfapi`|No|Yes|
|
|
115
|
+
|Legitimate interest|No|Yes|
|
|
116
|
+
|Use when|General GDPR/CCPA compliance|Programmatic advertising in EU/EEA|
|
|
117
|
+
|
|
118
|
+
## Components
|
|
119
|
+
|
|
120
|
+
|Component|Description|
|
|
121
|
+
|--|--|
|
|
122
|
+
|[IABConsentBanner](/docs/frameworks/next/iab/consent-banner)|TCF-compliant banner with partner disclosure|
|
|
123
|
+
|[IABConsentDialog](/docs/frameworks/next/iab/consent-dialog)|Tabbed preference center for purposes and vendors|
|
|
124
|
+
|
|
125
|
+
> ℹ️ **Info:**
|
|
126
|
+
> For lower-level custom IAB flows, use useHeadlessIABConsentUI() from @c15t/react/iab. useGVLData() is currently internal and is not part of the public package surface.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: useGVLData (Internal)
|
|
3
|
+
description: Status note for the internal GVL hook used by the built-in IAB dialog.
|
|
4
|
+
---
|
|
5
|
+
> ❌ **Error:**
|
|
6
|
+
> c15t is not yet IAB certified. The IAB TCF components are under active development and should not be used in production. APIs and behavior may change before certification is achieved.
|
|
7
|
+
|
|
8
|
+
`useGVLData()` currently powers the built-in `IABConsentDialog`, but it is **not part of the public package surface**.
|
|
9
|
+
|
|
10
|
+
Older docs showed it as a public hook. That is no longer accurate.
|
|
11
|
+
|
|
12
|
+
If you need supported customization points today:
|
|
13
|
+
|
|
14
|
+
* Use `IABConsentBanner` and `IABConsentDialog` from `@c15t/react/iab` for the supported prebuilt UI
|
|
15
|
+
* Use `useHeadlessIABConsentUI()` from `@c15t/react/iab` when you need lower-level control over banner/dialog state and actions
|
|
16
|
+
|
|
17
|
+
> ℹ️ **Info:**
|
|
18
|
+
> Until useGVLData() is exported as public API, avoid importing it from deep internal paths. Those paths are not covered by semver guarantees and can change without notice.
|
|
19
|
+
|
|
20
|
+
When a public GVL-focused hook becomes part of the supported API, this page should document that public surface instead of the internal dialog hook.
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Iframe Blocking
|
|
3
|
+
description: Block embedded content (YouTube, social widgets, maps) until users grant consent for the appropriate category.
|
|
4
|
+
---
|
|
5
|
+
Embedded iframes from third parties (YouTube, Google Maps, social media widgets) can set cookies and track users without their consent. c15t provides two approaches to gate iframes behind consent:
|
|
6
|
+
|
|
7
|
+
1. **`<Frame>` component** - A React component that conditionally renders children based on consent
|
|
8
|
+
2. **HTML `data-category` attribute** - For raw `<iframe>` elements outside of React
|
|
9
|
+
|
|
10
|
+
## Frame Component
|
|
11
|
+
|
|
12
|
+
The `<Frame>` component wraps content that requires consent. Children are only mounted when the specified category has consent. When consent is not granted, a placeholder is shown instead.
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
import { Frame } from '@c15t/nextjs';
|
|
16
|
+
|
|
17
|
+
function YouTubeEmbed() {
|
|
18
|
+
return (
|
|
19
|
+
<Frame category="marketing">
|
|
20
|
+
<iframe
|
|
21
|
+
src="https://www.youtube.com/embed/dQw4w9WgXcQ"
|
|
22
|
+
width="560"
|
|
23
|
+
height="315"
|
|
24
|
+
allowFullScreen
|
|
25
|
+
/>
|
|
26
|
+
</Frame>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Custom Placeholder
|
|
32
|
+
|
|
33
|
+
Replace the default placeholder with your own UI:
|
|
34
|
+
|
|
35
|
+
```tsx
|
|
36
|
+
<Frame
|
|
37
|
+
category="marketing"
|
|
38
|
+
placeholder={
|
|
39
|
+
<div className="flex items-center justify-center h-64 bg-gray-100 rounded">
|
|
40
|
+
<p>Enable marketing cookies to watch this video.</p>
|
|
41
|
+
</div>
|
|
42
|
+
}
|
|
43
|
+
>
|
|
44
|
+
<iframe src="https://www.youtube.com/embed/..." />
|
|
45
|
+
</Frame>
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Compound Components
|
|
49
|
+
|
|
50
|
+
Build custom placeholder layouts using compound components:
|
|
51
|
+
|
|
52
|
+
```tsx
|
|
53
|
+
<Frame.Root category="marketing">
|
|
54
|
+
<Frame.Title category="marketing" />
|
|
55
|
+
<Frame.Button category="marketing" />
|
|
56
|
+
</Frame.Root>
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## HTML Attribute Approach
|
|
60
|
+
|
|
61
|
+
For iframes outside of React (e.g., CMS content, server-rendered HTML), add `data-category` and use `data-src` instead of `src`:
|
|
62
|
+
|
|
63
|
+
```html
|
|
64
|
+
<iframe
|
|
65
|
+
data-src="https://www.youtube.com/embed/dQw4w9WgXcQ"
|
|
66
|
+
data-category="marketing"
|
|
67
|
+
width="560"
|
|
68
|
+
height="315"
|
|
69
|
+
></iframe>
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
When consent for the specified category is granted, c15t automatically swaps `data-src` to `src`, loading the iframe. When consent is revoked, `src` is moved back to `data-src`.
|
|
73
|
+
|
|
74
|
+
### Dynamic Iframes
|
|
75
|
+
|
|
76
|
+
c15t uses a `MutationObserver` to watch for dynamically added iframes. Any iframe with `data-category` added to the DOM after initialization is automatically processed.
|
|
77
|
+
|
|
78
|
+
## Initializing the Iframe Blocker
|
|
79
|
+
|
|
80
|
+
The iframe blocker for HTML attributes needs to be initialized separately from the Frame component:
|
|
81
|
+
|
|
82
|
+
```tsx
|
|
83
|
+
import { useConsentManager } from '@c15t/nextjs';
|
|
84
|
+
import { useEffect } from 'react';
|
|
85
|
+
|
|
86
|
+
function IframeBlockerInit() {
|
|
87
|
+
const { initializeIframeBlocker } = useConsentManager();
|
|
88
|
+
|
|
89
|
+
useEffect(() => {
|
|
90
|
+
initializeIframeBlocker();
|
|
91
|
+
}, [initializeIframeBlocker]);
|
|
92
|
+
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## API Reference
|
|
98
|
+
|
|
99
|
+
### FrameProps
|
|
100
|
+
|
|
101
|
+
|Property|Type|Description|Default|Required|
|
|
102
|
+
|:--|:--|:--|:--|:--:|
|
|
103
|
+
|children|ReactNode|Content rendered when consent is granted. Children are not mounted until consent is given, preventing unnecessary network requests.|-|✅ Required|
|
|
104
|
+
|category|AllConsentNames|Consent category required to render children.|-|✅ Required|
|
|
105
|
+
|placeholder|ReactNode|A custom placeholder component to display when consent is not met. If not provided, a default placeholder will be displayed.|-|Optional|
|
|
106
|
+
|noStyle|boolean \|undefined|When true, removes all default styling from the component|false|Optional|
|
|
107
|
+
|theme|any|Custom theme to override default styles while maintaining structure and accessibility. Merges with defaults. Ignored when \`noStyle=\{true}\`.|undefined|Optional|
|
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Build a Custom Script Integration
|
|
3
|
+
description: Learn when to use a raw Script, when to build a reusable manifest-backed integration, and how to debug and test custom consent-aware scripts in c15t.
|
|
4
|
+
lastModified: 2026-04-10
|
|
5
|
+
---
|
|
6
|
+
If you cannot find a prebuilt integration in [`@c15t/scripts`](/docs/integrations), you have two good options:
|
|
7
|
+
|
|
8
|
+
1. Build a one-off `Script` object directly in your app.
|
|
9
|
+
2. Build a reusable manifest-backed integration helper.
|
|
10
|
+
|
|
11
|
+
Use the first option for app-specific scripts. Use the second option when you want something reusable, testable, and aligned with c15t's manifest system.
|
|
12
|
+
|
|
13
|
+
## Choose the Right Level
|
|
14
|
+
|
|
15
|
+
### One-off app script
|
|
16
|
+
|
|
17
|
+
Use a raw `Script` when:
|
|
18
|
+
|
|
19
|
+
* the integration is only used in one app
|
|
20
|
+
* the vendor setup is small
|
|
21
|
+
* you do not need to publish or share the helper
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import type { Script } from 'c15t';
|
|
25
|
+
|
|
26
|
+
export function acmeAnalytics(siteId: string): Script {
|
|
27
|
+
return {
|
|
28
|
+
id: 'acme-analytics',
|
|
29
|
+
src: `https://cdn.acme.com/analytics.js?site=${siteId}`,
|
|
30
|
+
category: 'measurement',
|
|
31
|
+
onBeforeLoad: () => {
|
|
32
|
+
window.acmeQueue = window.acmeQueue || [];
|
|
33
|
+
},
|
|
34
|
+
onConsentChange: ({ hasConsent }) => {
|
|
35
|
+
window.acme?.setConsent(hasConsent);
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Reusable manifest-backed integration
|
|
42
|
+
|
|
43
|
+
Use a manifest-backed helper when:
|
|
44
|
+
|
|
45
|
+
* you want to contribute to `@c15t/scripts`
|
|
46
|
+
* you want the integration to be reusable across apps
|
|
47
|
+
* you need structured startup/setup phases
|
|
48
|
+
* you want compatibility with c15t's server-side support for script loading
|
|
49
|
+
|
|
50
|
+
Manifest integrations should be declarative, serializable, and built from structured steps rather than raw inline JavaScript strings.
|
|
51
|
+
|
|
52
|
+
## Manifest Contract
|
|
53
|
+
|
|
54
|
+
Every reusable manifest carries two contract fields:
|
|
55
|
+
|
|
56
|
+
* `kind`: identifies the payload as a c15t vendor manifest
|
|
57
|
+
* `schemaVersion`: identifies which manifest schema the runtime should compile
|
|
58
|
+
|
|
59
|
+
Use `vendorManifestContract` so helpers stay aligned with the runtime's current contract:
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
const acmeManifest = {
|
|
63
|
+
...vendorManifestContract,
|
|
64
|
+
vendor: 'acme-analytics',
|
|
65
|
+
// ...
|
|
66
|
+
} as const satisfies VendorManifest;
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
If manifests are sent from a server later, these fields are how the client can validate that it knows how to interpret the payload before executing anything.
|
|
70
|
+
|
|
71
|
+
## Manifest Mental Model
|
|
72
|
+
|
|
73
|
+
The manifest runtime executes a script in ordered phases:
|
|
74
|
+
|
|
75
|
+
* `bootstrap`: globals or stubs that must exist before anything else
|
|
76
|
+
* `install`: startup steps plus a single `loadScript`
|
|
77
|
+
* `afterLoad`: work that should run after the external script loads
|
|
78
|
+
* `onBeforeLoadGranted` / `onBeforeLoadDenied`: initial consent-specific setup
|
|
79
|
+
* `onLoadGranted` / `onLoadDenied`: post-load consent-specific setup
|
|
80
|
+
* `onConsentChange`: runs on every consent update
|
|
81
|
+
* `onConsentGranted` / `onConsentDenied`: branch-specific consent updates
|
|
82
|
+
|
|
83
|
+
For vendors with explicit consent APIs, you can also use:
|
|
84
|
+
|
|
85
|
+
* `consentMapping`
|
|
86
|
+
* `consentSignal`
|
|
87
|
+
* `consentSignalTarget`
|
|
88
|
+
|
|
89
|
+
That is how the Google integrations map c15t consent categories to Consent Mode v2 and inject `default` and `update` signals in the correct phase order.
|
|
90
|
+
|
|
91
|
+
`category` supports the same consent condition model as a plain `Script`, so manifests can represent simple or nested rules such as:
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
category: { and: ['measurement', { not: 'marketing' }] }
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Structured Steps
|
|
98
|
+
|
|
99
|
+
Prefer structured steps over raw script text. The current manifest DSL supports patterns like:
|
|
100
|
+
|
|
101
|
+
* `setGlobal`
|
|
102
|
+
* `setGlobalPath`
|
|
103
|
+
* `defineQueueFunction`
|
|
104
|
+
* `defineStubFunction`
|
|
105
|
+
* `pushToQueue`
|
|
106
|
+
* `callGlobal`
|
|
107
|
+
* `defineQueueMethods`
|
|
108
|
+
* `defineGlobalMethods`
|
|
109
|
+
* `constructGlobal`
|
|
110
|
+
* `loadScript`
|
|
111
|
+
|
|
112
|
+
These steps are easier to validate, test, debug, and eventually transport from the server.
|
|
113
|
+
|
|
114
|
+
## Example Manifest Integration
|
|
115
|
+
|
|
116
|
+
If you are building a reusable helper, the pattern looks like this:
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
import type { Script } from 'c15t';
|
|
120
|
+
import { resolveManifest } from '@c15t/scripts/resolve';
|
|
121
|
+
import {
|
|
122
|
+
vendorManifestContract,
|
|
123
|
+
type VendorManifest,
|
|
124
|
+
} from '@c15t/scripts/types';
|
|
125
|
+
|
|
126
|
+
const acmeManifest = {
|
|
127
|
+
...vendorManifestContract,
|
|
128
|
+
vendor: 'acme-analytics',
|
|
129
|
+
category: 'measurement',
|
|
130
|
+
bootstrap: [
|
|
131
|
+
{
|
|
132
|
+
type: 'setGlobal',
|
|
133
|
+
name: 'acmeQueue',
|
|
134
|
+
value: [],
|
|
135
|
+
ifUndefined: true,
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
type: 'defineQueueFunction',
|
|
139
|
+
name: 'acme',
|
|
140
|
+
queue: 'acmeQueue',
|
|
141
|
+
ifUndefined: true,
|
|
142
|
+
},
|
|
143
|
+
],
|
|
144
|
+
install: [
|
|
145
|
+
{
|
|
146
|
+
type: 'callGlobal',
|
|
147
|
+
global: 'acme',
|
|
148
|
+
args: ['init', '{{siteId}}'],
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
type: 'loadScript',
|
|
152
|
+
src: 'https://cdn.acme.com/analytics.js?site={{siteId}}',
|
|
153
|
+
async: true,
|
|
154
|
+
},
|
|
155
|
+
],
|
|
156
|
+
onConsentGranted: [
|
|
157
|
+
{
|
|
158
|
+
type: 'callGlobal',
|
|
159
|
+
global: 'acme',
|
|
160
|
+
args: ['consent', true],
|
|
161
|
+
},
|
|
162
|
+
],
|
|
163
|
+
onConsentDenied: [
|
|
164
|
+
{
|
|
165
|
+
type: 'callGlobal',
|
|
166
|
+
global: 'acme',
|
|
167
|
+
args: ['consent', false],
|
|
168
|
+
},
|
|
169
|
+
],
|
|
170
|
+
} as const satisfies VendorManifest;
|
|
171
|
+
|
|
172
|
+
export function acmeAnalytics(siteId: string): Script {
|
|
173
|
+
return resolveManifest(acmeManifest, { siteId });
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Design Guidelines
|
|
178
|
+
|
|
179
|
+
When building an integration, prefer these rules:
|
|
180
|
+
|
|
181
|
+
* Keep helper logic thin. Put behavior in the manifest, not in post-resolution callback mutation.
|
|
182
|
+
* Keep manifests serializable. Avoid helper-only runtime branches where possible.
|
|
183
|
+
* Use explicit config inputs. Avoid generic override bags when a named option is clearer.
|
|
184
|
+
* Use `alwaysLoad` only when the vendor truly manages its own consent correctly.
|
|
185
|
+
* Use `persistAfterConsentRevoked` only when the vendor exposes a real consent toggle and does not need a full reload.
|
|
186
|
+
* Keep vendor-specific naming out of the core DSL when a generic step can express it.
|
|
187
|
+
|
|
188
|
+
## Testing Checklist
|
|
189
|
+
|
|
190
|
+
At minimum, test these flows:
|
|
191
|
+
|
|
192
|
+
1. Initial page load with consent denied.
|
|
193
|
+
2. Initial page load with consent granted.
|
|
194
|
+
3. Consent granted after the script was previously denied.
|
|
195
|
+
4. Consent revoked after the script was previously active.
|
|
196
|
+
5. Existing script element reuse if the script persists after revocation.
|
|
197
|
+
6. Error handling if the vendor global or loader is missing.
|
|
198
|
+
|
|
199
|
+
If you are contributing to `@c15t/scripts`, add focused engine/helper tests similar to the existing tests in `packages/scripts/src/engine.test.ts` and `packages/scripts/src/helpers.test.ts`.
|
|
200
|
+
|
|
201
|
+
## Debugging
|
|
202
|
+
|
|
203
|
+
Use `@c15t/dev-tools` while implementing and testing integrations.
|
|
204
|
+
|
|
205
|
+
The scripts panel now shows:
|
|
206
|
+
|
|
207
|
+
* whether a script is loaded, pending, or blocked
|
|
208
|
+
* grouped activity for `onBeforeLoad`, `onLoad`, and `onConsentChange`
|
|
209
|
+
* manifest phase activity such as `bootstrap`, `consent-default`, `setup`, and `afterLoad`
|
|
210
|
+
|
|
211
|
+
The events panel also records script lifecycle and manifest step events, which is useful when a vendor reads consent too early or a startup step runs in the wrong order.
|
|
212
|
+
|
|
213
|
+
## When to Stop and Use a Plain Script
|
|
214
|
+
|
|
215
|
+
Not every integration needs a reusable manifest helper.
|
|
216
|
+
|
|
217
|
+
If the vendor snippet is tiny, unique to one app, or mostly static, a plain `Script` object in your runtime options is usually the simpler choice. Reach for the manifest system when you need reuse, consistency, structured startup behavior, or a path to server-driven manifests.
|
|
218
|
+
|
|
219
|
+
## Reference Types
|
|
220
|
+
|
|
221
|
+
### Script
|
|
222
|
+
|
|
223
|
+
|Property|Type|Description|Default|Required|
|
|
224
|
+
|:--|:--|:--|:--|:--:|
|
|
225
|
+
|id|string|Unique identifier for the script|-|✅ Required|
|
|
226
|
+
|src|string \|undefined|URL of the script to load|-|Optional|
|
|
227
|
+
|textContent|string \|undefined|Inline JavaScript code to execute|-|Optional|
|
|
228
|
+
|category|HasCondition\<AllConsentNames>|Consent category or condition required to load this script|-|✅ Required|
|
|
229
|
+
|callbackOnly|boolean \|undefined|Whether this is a callback-only script that doesn't need to load an external resource. When true, no script tag will be added to the DOM, only callbacks will be executed.|false|Optional|
|
|
230
|
+
|persistAfterConsentRevoked|boolean \|undefined|Whether the script should persist after consent is revoked.|false|Optional|
|
|
231
|
+
|alwaysLoad|boolean \|undefined|Whether the script should always load regardless of consent state. This is useful for scripts like Google Tag Manager or PostHog that manage their own consent state internally. The script will load immediately and never be unloaded based on consent changes. Note: When using this option, you are responsible for ensuring the script itself respects user consent preferences through its own consent management.|false|Optional|
|
|
232
|
+
|fetchPriority|"high" \|"low" \|"auto" \|undefined|Priority hint for browser resource loading|-|Optional|
|
|
233
|
+
|attributes|Record\<string, string> \|undefined|Additional attributes to add to the script element|-|Optional|
|
|
234
|
+
|async|boolean \|undefined|Whether to use async loading|-|Optional|
|
|
235
|
+
|defer|boolean \|undefined|Whether to defer script loading|-|Optional|
|
|
236
|
+
|nonce|string \|undefined|Content Security Policy nonce|-|Optional|
|
|
237
|
+
|anonymizeId|boolean \|undefined|Whether to use an anonymized ID for the script element, this helps ensure the script is not blocked by ad blockers|true|Optional|
|
|
238
|
+
|target|"head" \|"body" \|undefined|Where to inject the script element in the DOM. Options: \`'head'\`: Scripts are appended to \`\<head>\` (default); \`'body'\`: Scripts are appended to \`\<body>\`|'head'|Optional|
|
|
239
|
+
|onBeforeLoad|Object \|undefined|Callback executed before the script is loaded|-|Optional|
|
|
240
|
+
|onLoad|Object \|undefined|Callback executed when the script loads successfully|-|Optional|
|
|
241
|
+
|onError|Object \|undefined|Callback executed if the script fails to load|-|Optional|
|
|
242
|
+
|onConsentChange|Object \|undefined|Callback executed whenever the consent store is changed. This callback only applies to scripts already loaded.|-|Optional|
|
|
243
|
+
|vendorId|string \|number \|undefined|IAB TCF vendor ID - links script to a registered vendor. When in IAB mode, the script will only load if this vendor has consent. Takes precedence over \`category\` when in IAB mode. Use custom vendor IDs (string or number) to gate non-IAB vendors too.|-|Optional|
|
|
244
|
+
|iabPurposes|number\[] \|undefined|IAB TCF purpose IDs this script requires consent for. When in IAB mode and no vendorId is set, the script will only load if ALL specified purposes have consent.|-|Optional|
|
|
245
|
+
|iabLegIntPurposes|number\[] \|undefined|IAB TCF legitimate interest purpose IDs. These purposes can operate under legitimate interest instead of consent. The script loads if all iabPurposes have consent OR all iabLegIntPurposes have legitimate interest established.|-|Optional|
|
|
246
|
+
|iabSpecialFeatures|number\[] \|undefined|IAB TCF special feature IDs this script requires. Options: 1: Use precise geolocation data; 2: Actively scan device characteristics for identification|-|Optional|
|
|
247
|
+
|
|
248
|
+
#### `onBeforeLoad`
|
|
249
|
+
|
|
250
|
+
Callback executed before the script is loaded
|
|
251
|
+
|
|
252
|
+
|Property|Type|Description|Default|Required|
|
|
253
|
+
|:--|:--|:--|:--|:--:|
|
|
254
|
+
|id|string|The original script ID|-|✅ Required|
|
|
255
|
+
|elementId|string|The actual DOM element ID used (anonymized if enabled)|-|✅ Required|
|
|
256
|
+
|hasConsent|boolean|Has consent|-|✅ Required|
|
|
257
|
+
|consents|ConsentState|The current consent state|-|✅ Required|
|
|
258
|
+
|element|HTMLScriptElement \|undefined|The script element (for load/error callbacks) Will be undefined for callback-only scripts|-|Optional|
|
|
259
|
+
|error|Error \|undefined|Error information (for error callbacks)|-|Optional|
|
|
260
|
+
|
|
261
|
+
#### `onLoad`
|
|
262
|
+
|
|
263
|
+
Callback executed when the script loads successfully
|
|
264
|
+
|
|
265
|
+
|Property|Type|Description|Default|Required|
|
|
266
|
+
|:--|:--|:--|:--|:--:|
|
|
267
|
+
|id|string|The original script ID|-|✅ Required|
|
|
268
|
+
|elementId|string|The actual DOM element ID used (anonymized if enabled)|-|✅ Required|
|
|
269
|
+
|hasConsent|boolean|Has consent|-|✅ Required|
|
|
270
|
+
|consents|ConsentState|The current consent state|-|✅ Required|
|
|
271
|
+
|element|HTMLScriptElement \|undefined|The script element (for load/error callbacks) Will be undefined for callback-only scripts|-|Optional|
|
|
272
|
+
|error|Error \|undefined|Error information (for error callbacks)|-|Optional|
|
|
273
|
+
|
|
274
|
+
#### `onError`
|
|
275
|
+
|
|
276
|
+
Callback executed if the script fails to load
|
|
277
|
+
|
|
278
|
+
|Property|Type|Description|Default|Required|
|
|
279
|
+
|:--|:--|:--|:--|:--:|
|
|
280
|
+
|id|string|The original script ID|-|✅ Required|
|
|
281
|
+
|elementId|string|The actual DOM element ID used (anonymized if enabled)|-|✅ Required|
|
|
282
|
+
|hasConsent|boolean|Has consent|-|✅ Required|
|
|
283
|
+
|consents|ConsentState|The current consent state|-|✅ Required|
|
|
284
|
+
|element|HTMLScriptElement \|undefined|The script element (for load/error callbacks) Will be undefined for callback-only scripts|-|Optional|
|
|
285
|
+
|error|Error \|undefined|Error information (for error callbacks)|-|Optional|
|
|
286
|
+
|
|
287
|
+
#### `onConsentChange`
|
|
288
|
+
|
|
289
|
+
Callback executed whenever the consent store is changed. This callback only applies to scripts already loaded.
|
|
290
|
+
|
|
291
|
+
|Property|Type|Description|Default|Required|
|
|
292
|
+
|:--|:--|:--|:--|:--:|
|
|
293
|
+
|id|string|The original script ID|-|✅ Required|
|
|
294
|
+
|elementId|string|The actual DOM element ID used (anonymized if enabled)|-|✅ Required|
|
|
295
|
+
|hasConsent|boolean|Has consent|-|✅ Required|
|
|
296
|
+
|consents|ConsentState|The current consent state|-|✅ Required|
|
|
297
|
+
|element|HTMLScriptElement \|undefined|The script element (for load/error callbacks) Will be undefined for callback-only scripts|-|Optional|
|
|
298
|
+
|error|Error \|undefined|Error information (for error callbacks)|-|Optional|
|
|
299
|
+
|
|
300
|
+
### VendorManifest
|
|
301
|
+
|
|
302
|
+
|Property|Type|Description|Default|Required|
|
|
303
|
+
|:--|:--|:--|:--|:--:|
|
|
304
|
+
|kind|"c15t.vendor-manifest"|Manifest contract identifier.|-|✅ Required|
|
|
305
|
+
|schemaVersion|1|Manifest schema version.|-|✅ Required|
|
|
306
|
+
|vendor|string|Unique vendor identifier (used as Script.id)|-|✅ Required|
|
|
307
|
+
|category|ManifestCategoryCondition|Consent category or condition required to load this vendor|-|✅ Required|
|
|
308
|
+
|alwaysLoad|string \|boolean \|undefined|Load regardless of consent state (vendor manages its own consent internally)|-|Optional|
|
|
309
|
+
|persistAfterConsentRevoked|string \|boolean \|undefined|Keep script in DOM after consent revocation (vendor has a consent API)|-|Optional|
|
|
310
|
+
|bootstrap|ManifestStep \|undefined|Steps that must execute before default consent signaling. This is primarily used for integrations such as Google tags where a stub global must exist before calling the vendor's consent API.|-|Optional|
|
|
311
|
+
|install|ManifestStep|Steps to execute when installing the vendor.|-|✅ Required|
|
|
312
|
+
|afterLoad|ManifestStep \|undefined|Steps to execute after the main script loads|-|Optional|
|
|
313
|
+
|onBeforeLoadGranted|ManifestStep \|undefined|Steps to execute before load when the vendor has consent|-|Optional|
|
|
314
|
+
|onBeforeLoadDenied|ManifestStep \|undefined|Steps to execute before load when the vendor does not have consent|-|Optional|
|
|
315
|
+
|onLoadGranted|ManifestStep \|undefined|Steps to execute after load when the vendor has consent|-|Optional|
|
|
316
|
+
|onLoadDenied|ManifestStep \|undefined|Steps to execute after load when the vendor does not have consent|-|Optional|
|
|
317
|
+
|onConsentChange|ManifestStep \|undefined|Steps to run on any consent state change|-|Optional|
|
|
318
|
+
|onConsentGranted|ManifestStep \|undefined|Steps to run when this vendor's category consent is granted|-|Optional|
|
|
319
|
+
|onConsentDenied|ManifestStep \|undefined|Steps to run when this vendor's category consent is denied|-|Optional|
|
|
320
|
+
|consentMapping|Record\<string, string\[]> \|undefined|Maps c15t consent categories to vendor-specific consent type names. Used with \`consentSignal\` to translate c15t consent state into the vendor's consent API format.|-|Optional|
|
|
321
|
+
|consentSignal|"gtag" \|undefined|How to signal consent state to the vendor|-|Optional|
|
|
322
|
+
|consentSignalTarget|string \|undefined|Target global for consent signaling (defaults based on signal type)|-|Optional|
|
|
323
|
+
|
|
324
|
+
#### `bootstrap` ManifestStep
|
|
325
|
+
|
|
326
|
+
Steps that must execute before default consent signaling. This is primarily used for integrations such as Google tags where a stub global must exist before calling the vendor's consent API.
|
|
327
|
+
|
|
328
|
+
|Property|Type|Description|Default|Required|
|
|
329
|
+
|:--|:--|:--|:--|:--:|
|
|
330
|
+
|type|Object|-|-|✅ Required|
|
|
331
|
+
|
|
332
|
+
#### `install` ManifestStep
|
|
333
|
+
|
|
334
|
+
Steps to execute when installing the vendor.
|
|
335
|
+
|
|
336
|
+
* If a \`loadScript\` step exists, its \`src\` becomes \`Script.src\`
|
|
337
|
+
* All non-\`loadScript\` steps run as part of \`onBeforeLoad\`
|
|
338
|
+
|
|
339
|
+
|Property|Type|Description|Default|Required|
|
|
340
|
+
|:--|:--|:--|:--|:--:|
|
|
341
|
+
|type|Object|-|-|✅ Required|
|
|
342
|
+
|
|
343
|
+
#### `afterLoad` ManifestStep
|
|
344
|
+
|
|
345
|
+
Steps to execute after the main script loads
|
|
346
|
+
|
|
347
|
+
|Property|Type|Description|Default|Required|
|
|
348
|
+
|:--|:--|:--|:--|:--:|
|
|
349
|
+
|type|Object|-|-|✅ Required|
|
|
350
|
+
|
|
351
|
+
#### `onBeforeLoadGranted` ManifestStep
|
|
352
|
+
|
|
353
|
+
Steps to execute before load when the vendor has consent
|
|
354
|
+
|
|
355
|
+
|Property|Type|Description|Default|Required|
|
|
356
|
+
|:--|:--|:--|:--|:--:|
|
|
357
|
+
|type|Object|-|-|✅ Required|
|
|
358
|
+
|
|
359
|
+
#### `onBeforeLoadDenied` ManifestStep
|
|
360
|
+
|
|
361
|
+
Steps to execute before load when the vendor does not have consent
|
|
362
|
+
|
|
363
|
+
|Property|Type|Description|Default|Required|
|
|
364
|
+
|:--|:--|:--|:--|:--:|
|
|
365
|
+
|type|Object|-|-|✅ Required|
|
|
366
|
+
|
|
367
|
+
#### `onLoadGranted` ManifestStep
|
|
368
|
+
|
|
369
|
+
Steps to execute after load when the vendor has consent
|
|
370
|
+
|
|
371
|
+
|Property|Type|Description|Default|Required|
|
|
372
|
+
|:--|:--|:--|:--|:--:|
|
|
373
|
+
|type|Object|-|-|✅ Required|
|
|
374
|
+
|
|
375
|
+
#### `onLoadDenied` ManifestStep
|
|
376
|
+
|
|
377
|
+
Steps to execute after load when the vendor does not have consent
|
|
378
|
+
|
|
379
|
+
|Property|Type|Description|Default|Required|
|
|
380
|
+
|:--|:--|:--|:--|:--:|
|
|
381
|
+
|type|Object|-|-|✅ Required|
|
|
382
|
+
|
|
383
|
+
#### `onConsentChange` ManifestStep
|
|
384
|
+
|
|
385
|
+
Steps to run on any consent state change
|
|
386
|
+
|
|
387
|
+
|Property|Type|Description|Default|Required|
|
|
388
|
+
|:--|:--|:--|:--|:--:|
|
|
389
|
+
|type|Object|-|-|✅ Required|
|
|
390
|
+
|
|
391
|
+
#### `onConsentGranted` ManifestStep
|
|
392
|
+
|
|
393
|
+
Steps to run when this vendor's category consent is granted
|
|
394
|
+
|
|
395
|
+
|Property|Type|Description|Default|Required|
|
|
396
|
+
|:--|:--|:--|:--|:--:|
|
|
397
|
+
|type|Object|-|-|✅ Required|
|
|
398
|
+
|
|
399
|
+
#### `onConsentDenied` ManifestStep
|
|
400
|
+
|
|
401
|
+
Steps to run when this vendor's category consent is denied
|
|
402
|
+
|
|
403
|
+
|Property|Type|Description|Default|Required|
|
|
404
|
+
|:--|:--|:--|:--|:--:|
|
|
405
|
+
|type|Object|-|-|✅ Required|
|