@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
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Share consent controls across frameworks
|
|
3
|
+
description: Use the same c15t script lifecycle, external consent source, and
|
|
4
|
+
event controls in every framework.
|
|
5
|
+
group: guides
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Choose one consent authority
|
|
9
|
+
|
|
10
|
+
c15t owns script loading, consent gates, lifecycle callbacks, and optional cleanup
|
|
11
|
+
through its framework-independent core. React, Vue, Svelte, Astro, and the browser
|
|
12
|
+
client connect to that core. Next.js and TanStack Start use the React provider;
|
|
13
|
+
Nuxt uses Vue; SvelteKit uses Svelte. None requires Astro for these controls.
|
|
14
|
+
|
|
15
|
+
With c15t as the consent authority, keep your framework's hosted, self-hosted, or
|
|
16
|
+
offline setup. Offline mode keeps choices in the browser; a hosted backend can
|
|
17
|
+
store records. The script SDK and event dispatcher work with either mode.
|
|
18
|
+
|
|
19
|
+
To keep another CMP, provide a `consentSource`. It owns the banner, preferences,
|
|
20
|
+
records, expiration, privacy signals, and category mapping. c15t follows its
|
|
21
|
+
current permissions without creating a second choice record. Optional categories
|
|
22
|
+
start denied, including during SSR. An unavailable source or a failed read denies
|
|
23
|
+
them again. Initialize the CMP independently, or register its loader as an
|
|
24
|
+
explicitly early-loading script so it does not wait for its own consent.
|
|
25
|
+
|
|
26
|
+
The source contract is exported from `@c15t/core/runtime`:
|
|
27
|
+
|
|
28
|
+
```ts title="src/consent-source.ts — adapter skeleton"
|
|
29
|
+
import type { ExternalConsentSource } from 'c15t/runtime';
|
|
30
|
+
import { provider } from './existing-cmp';
|
|
31
|
+
|
|
32
|
+
export const consentSource: ExternalConsentSource = {
|
|
33
|
+
getPermissions: () => provider.getCategoryPermissions(),
|
|
34
|
+
subscribe: (notify) => provider.subscribe(notify),
|
|
35
|
+
openPreferences: () => provider.openPreferences(),
|
|
36
|
+
};
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
`provider` is your application's adapter for the existing CMP, not a c15t export.
|
|
40
|
+
Map its categories to c15t's `measurement`, `marketing`, `functionality`, and
|
|
41
|
+
`experience` booleans. Missing categories are denied; `necessary` stays true.
|
|
42
|
+
Return `null` until the CMP is ready. `subscribe` must notify on initialization,
|
|
43
|
+
changes, withdrawal, and expiration, and return a function that removes listeners.
|
|
44
|
+
Keep browser access inside these functions so importing the adapter during SSR is safe.
|
|
45
|
+
|
|
46
|
+
If `subscribe` throws, c15t reports the failure through `callbacks.onError` and
|
|
47
|
+
continues startup with optional categories denied. The failed connection ignores
|
|
48
|
+
later notifications and does not forward preference requests. Recreate the owner
|
|
49
|
+
after the CMP is available to connect again.
|
|
50
|
+
|
|
51
|
+
## Pass the controls to your framework
|
|
52
|
+
|
|
53
|
+
The `consentSource` option is available at these registration points. Register your SDK configurations through the same owner's
|
|
54
|
+
`scripts` option. Do not create an additional runtime beside an existing provider.
|
|
55
|
+
|
|
56
|
+
| Framework | Registration point |
|
|
57
|
+
| --------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
|
|
58
|
+
| React | `ConsentProvider options={{ mode, consentSource, scripts }}` |
|
|
59
|
+
| Next.js / TanStack Start | `ConsentRoot options={{ consentSource }}` with `scripts` as a top-level prop; `ConsentProvider` also accepts the React options |
|
|
60
|
+
| Vue | `app.use(c15tVue, { consentSource, scripts })` |
|
|
61
|
+
| Nuxt | `app.config.ts` → `c15t: { consentSource, scripts }` |
|
|
62
|
+
| Svelte / SvelteKit | `ConsentManagerProvider` options or corresponding top-level props |
|
|
63
|
+
| Astro | `clientOptions.consentSource` |
|
|
64
|
+
| Browser client | `createConsentClient({ consentSource, scripts })` |
|
|
65
|
+
| Headless JavaScript / Solid | `createConsentRuntime({ mode, consentSource, scripts })` |
|
|
66
|
+
|
|
67
|
+
For example, a React client boundary can use the source directly:
|
|
68
|
+
|
|
69
|
+
```tsx title="src/Consent.tsx"
|
|
70
|
+
'use client';
|
|
71
|
+
|
|
72
|
+
import type { ReactNode } from 'react';
|
|
73
|
+
import { ConsentProvider, offline, useSetActiveUI } from 'c15t/react';
|
|
74
|
+
import { googleTagManager } from '@c15t/scripts/google-tag-manager';
|
|
75
|
+
import { consentSource } from './consent-source';
|
|
76
|
+
|
|
77
|
+
const mode = offline();
|
|
78
|
+
const scripts = [googleTagManager({ id: 'GTM-EXAMPLE' })];
|
|
79
|
+
|
|
80
|
+
function Preferences() {
|
|
81
|
+
const setActiveUI = useSetActiveUI();
|
|
82
|
+
return <button type="button" onClick={() => setActiveUI('dialog')}>Privacy settings</button>;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function Consent({ children }: { children: ReactNode }) {
|
|
86
|
+
return (
|
|
87
|
+
<ConsentProvider options={{ mode, consentSource, scripts }}>
|
|
88
|
+
{children}
|
|
89
|
+
<Preferences />
|
|
90
|
+
</ConsentProvider>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Replace the container ID. `mode` remains required by the provider API, but an
|
|
96
|
+
external source bypasses c15t backend initialization and persistence. Omit c15t's
|
|
97
|
+
banner and dialog. Preference links, hooks, and `kernel.set.activeUI('dialog')`
|
|
98
|
+
delegate to the source. Preference-opening failures reach `callbacks.onError`;
|
|
99
|
+
`kernel.commands.save()` rejects instead of recording a second choice.
|
|
100
|
+
|
|
101
|
+
In Next.js, construct the source in the client boundary; do not pass functions
|
|
102
|
+
from a Server Component. Existing `ConsentRoot` state can stay serializable, but
|
|
103
|
+
c15t records do not establish external permissions. A client-owned
|
|
104
|
+
`ConsentProvider` avoids a redundant server consent fetch for external-only setups.
|
|
105
|
+
For Nuxt, use `app.config.ts` for the functions, not serialized public runtime
|
|
106
|
+
configuration; the module skips its consent fetch and record hydration when a
|
|
107
|
+
source is configured. Browser access remains deferred until mount.
|
|
108
|
+
|
|
109
|
+
Solid currently ships UI primitives, not a lifecycle provider. Create the core
|
|
110
|
+
runtime once, call `start()` from `onMount`, and `dispose()` from `onCleanup`.
|
|
111
|
+
Other frameworks' providers perform that lifecycle automatically. A provider given
|
|
112
|
+
an existing `runtime` borrows it: configure controls on the runtime owner, which
|
|
113
|
+
also owns starting and disposing it.
|
|
114
|
+
|
|
115
|
+
## Handle withdrawal and application events
|
|
116
|
+
|
|
117
|
+
When the source withdraws an optional category that was granted, c15t reloads
|
|
118
|
+
the page, as it does when a visitor revokes consent in c15t's own UI. Removing a
|
|
119
|
+
script element cannot stop JavaScript that already ran, so the reload starts a
|
|
120
|
+
page with only permitted code. The reload runs in the next task, after
|
|
121
|
+
synchronous consent callbacks and `onBeforeConsentRevocationReload`. Disposing
|
|
122
|
+
the owner cancels a pending reload.
|
|
123
|
+
|
|
124
|
+
c15t cannot tell a visitor's withdrawal from expiry or a reset in the CMP, so
|
|
125
|
+
any notification that turns off a granted category reloads. The CMP owns
|
|
126
|
+
persistence: store the new decision before notifying c15t, or the reloaded page
|
|
127
|
+
reads the old one. Set `reloadOnConsentRevoked: false` to handle withdrawal
|
|
128
|
+
yourself. c15t still updates gates and calls script consent callbacks.
|
|
129
|
+
|
|
130
|
+
`createEventDispatcher` from `@c15t/scripts/events` also has no framework dependency:
|
|
131
|
+
|
|
132
|
+
```ts title="src/events.ts — attach to an existing runtime"
|
|
133
|
+
import { createEventDispatcher } from '@c15t/scripts/events';
|
|
134
|
+
|
|
135
|
+
const events = createEventDispatcher({
|
|
136
|
+
scripts,
|
|
137
|
+
getSnapshot: () => runtime.kernel.getSnapshot(),
|
|
138
|
+
});
|
|
139
|
+
events.track('docs_search', { resultCount: 4 });
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Here `scripts` is the same configuration registered with the existing `runtime`.
|
|
143
|
+
For a provider-owned kernel, use that kernel's live `getSnapshot` instead. The
|
|
144
|
+
dispatcher sends only to configured integrations with supported event APIs when
|
|
145
|
+
measurement and the script's own consent condition allow it. It discards denied
|
|
146
|
+
events, isolates vendor failures, and deduplicates explicitly configured SPA
|
|
147
|
+
pageviews. It does not subscribe to a framework router: notify it from your
|
|
148
|
+
router's navigation hook. Use vendor-specific helpers for APIs outside the shared
|
|
149
|
+
event contract.
|
|
150
|
+
|
|
151
|
+
## Verify the integration
|
|
152
|
+
|
|
153
|
+
Test an undecided visitor, an existing grant, withdrawal, expiry, and a source
|
|
154
|
+
that cannot be read. Check that only permitted scripts execute, the preference
|
|
155
|
+
control opens the existing CMP, c15t does not render another banner or persist
|
|
156
|
+
another receipt, and unmounting removes the source listeners. Test your actual
|
|
157
|
+
CMP category mapping and tag-manager container; shared gates do not validate
|
|
158
|
+
those configurations or establish compliance by themselves.
|
|
@@ -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 '
|
|
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 '
|
|
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 '
|
|
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 '
|
|
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 '
|
|
197
|
+
import type { C15tClientOptionsExtension } from 'c15t/astro';
|
|
198
198
|
import { scripts } from './consent-scripts';
|
|
199
199
|
|
|
200
200
|
export default { scripts } satisfies C15tClientOptionsExtension;
|
|
@@ -249,7 +249,7 @@ clientEntrypoint: fileURLToPath(new URL('./src/c15t.client.ts', import.meta.url)
|
|
|
249
249
|
Export the scripts from that module:
|
|
250
250
|
|
|
251
251
|
```ts title="src/c15t.client.ts"
|
|
252
|
-
import type { C15tClientOptionsExtension } from '
|
|
252
|
+
import type { C15tClientOptionsExtension } from 'c15t/astro';
|
|
253
253
|
import { scripts } from './consent-scripts';
|
|
254
254
|
|
|
255
255
|
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 '
|
|
197
|
+
import type { C15tClientOptionsExtension } from 'c15t/astro';
|
|
198
198
|
import { scripts } from './consent-scripts';
|
|
199
199
|
|
|
200
200
|
export default { scripts } satisfies C15tClientOptionsExtension;
|
|
@@ -200,7 +200,7 @@ clientEntrypoint: fileURLToPath(new URL('./src/c15t.client.ts', import.meta.url)
|
|
|
200
200
|
Export the scripts from that module:
|
|
201
201
|
|
|
202
202
|
```ts title="src/c15t.client.ts"
|
|
203
|
-
import type { C15tClientOptionsExtension } from '
|
|
203
|
+
import type { C15tClientOptionsExtension } from 'c15t/astro';
|
|
204
204
|
import { scripts } from './consent-scripts';
|
|
205
205
|
|
|
206
206
|
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 '
|
|
197
|
+
import type { C15tClientOptionsExtension } from 'c15t/astro';
|
|
198
198
|
import { scripts } from './consent-scripts';
|
|
199
199
|
|
|
200
200
|
export default { scripts } satisfies C15tClientOptionsExtension;
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Front Chat
|
|
3
|
+
description: Load the Front Chat widget with functionality permission, forward
|
|
4
|
+
CSP nonces and clear the session on revocation.
|
|
5
|
+
group: integrations
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Configure Front Chat
|
|
9
|
+
|
|
10
|
+
Copy the `chatId` from the widget snippet in your Front Chat channel's
|
|
11
|
+
**Installation** tab. The helper loads Front's SDK once functionality permission
|
|
12
|
+
is granted, then calls `FrontChat('init')` with your chat ID.
|
|
13
|
+
|
|
14
|
+
| Package manager | Command |
|
|
15
|
+
| :-------------- | :-------------------------- |
|
|
16
|
+
| npm | `npm install @c15t/scripts` |
|
|
17
|
+
| pnpm | `pnpm add @c15t/scripts` |
|
|
18
|
+
| yarn | `yarn add @c15t/scripts` |
|
|
19
|
+
| bun | `bun add @c15t/scripts` |
|
|
20
|
+
|
|
21
|
+
```ts title="src/consent-scripts.ts"
|
|
22
|
+
import { frontChat } from '@c15t/scripts/front-chat';
|
|
23
|
+
|
|
24
|
+
export const scripts = [frontChat({ chatId: 'YOUR_FRONT_CHAT_ID' })];
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Register the scripts
|
|
28
|
+
|
|
29
|
+
Complete your [framework quickstart](https://c15t.com/docs/frameworks) first. Keep its Inth
|
|
30
|
+
endpoint, policy, styles and consent UI. Remove the vendor's original script,
|
|
31
|
+
SDK initializer or tag-manager entry so c15t owns loading once.
|
|
32
|
+
|
|
33
|
+
The `scripts` export in `src/consent-scripts.ts` is a configuration, not an
|
|
34
|
+
initializer. Add it to your existing consent owner using the registration point
|
|
35
|
+
below. These are partial edits to that owner, not additional providers.
|
|
36
|
+
|
|
37
|
+
**Next.js**
|
|
38
|
+
|
|
39
|
+
Import the configuration into the client boundary from your router guide:
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import { ConsentRoot } from 'c15t/next';
|
|
43
|
+
import { scripts } from './consent-scripts';
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Keep the server-resolved `state` and shared `consentConfig` from your
|
|
47
|
+
router guide. Its manifest, init and save URLs stay in effect. Add
|
|
48
|
+
`scripts` as a top-level prop on the existing root:
|
|
49
|
+
|
|
50
|
+
```tsx
|
|
51
|
+
<ConsentRoot state={state} config={consentConfig} scripts={scripts}>
|
|
52
|
+
{children}
|
|
53
|
+
</ConsentRoot>
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
For a Pages Router or static-export setup using `ConsentProvider`, add
|
|
57
|
+
`scripts` to its existing `options` instead. Keep the router-specific setup
|
|
58
|
+
from [Next.js script loading](../frameworks/next/script-loader.md).
|
|
59
|
+
|
|
60
|
+
**TanStack Start**
|
|
61
|
+
|
|
62
|
+
In your existing root route component, import the scripts alongside
|
|
63
|
+
`ConsentRoot`. Keep the server loader from the [TanStack Start quickstart](https://c15t.com/docs/frameworks/tanstack-start/quickstart).
|
|
64
|
+
|
|
65
|
+
```tsx
|
|
66
|
+
import { Outlet } from '@tanstack/react-router';
|
|
67
|
+
import { ConsentRoot } from 'c15t/tanstack-start';
|
|
68
|
+
import { scripts } from '../consent-scripts';
|
|
69
|
+
|
|
70
|
+
function Root() {
|
|
71
|
+
const state = Route.useLoaderData();
|
|
72
|
+
return (
|
|
73
|
+
<ConsentRoot state={state} backendURL={backendURL} initRoute={false} scripts={scripts}>
|
|
74
|
+
<Outlet />
|
|
75
|
+
{/* Keep your consent banner, dialog and preferences link here. */}
|
|
76
|
+
</ConsentRoot>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
This edits the existing route. `Route` and `backendURL` come from its setup;
|
|
82
|
+
keep the document shell and head components if they are part of your root.
|
|
83
|
+
`initRoute={false}` keeps the quickstart's direct-backend initialization.
|
|
84
|
+
If your app mounts a consent server route, retain its existing `initRoute`
|
|
85
|
+
instead. Do not return script callbacks from a server function or route loader.
|
|
86
|
+
|
|
87
|
+
**React**
|
|
88
|
+
|
|
89
|
+
Import the scripts into your existing provider component:
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
import { ConsentProvider } from 'c15t/react';
|
|
93
|
+
import { scripts } from './consent-scripts';
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Keep the existing options and add `scripts`:
|
|
97
|
+
|
|
98
|
+
```tsx
|
|
99
|
+
<ConsentProvider options={{ ...consentOptions, scripts }}>
|
|
100
|
+
{children}
|
|
101
|
+
</ConsentProvider>
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Here `consentOptions` is your existing configuration, including
|
|
105
|
+
`mode: hosted({ url: backendURL })`. Keep the banner, dialog and preferences
|
|
106
|
+
link inside the provider. See [React script loading](../frameworks/react/script-loader.md).
|
|
107
|
+
|
|
108
|
+
**Nuxt**
|
|
109
|
+
|
|
110
|
+
Attach one loader from the root `app.vue`, after the Nuxt module has
|
|
111
|
+
started its browser runtime. This keeps vendor callbacks in application code rather
|
|
112
|
+
than serialized `nuxt.config.ts` runtime configuration.
|
|
113
|
+
|
|
114
|
+
```vue title="app/app.vue"
|
|
115
|
+
<script setup lang="ts">
|
|
116
|
+
import { onUnmounted } from 'vue';
|
|
117
|
+
import { createScriptLoader } from 'c15t/modules/script-loader';
|
|
118
|
+
import { scripts } from '../src/consent-scripts';
|
|
119
|
+
|
|
120
|
+
const nuxtApp = useNuxtApp();
|
|
121
|
+
const kernel = useConsentKernel();
|
|
122
|
+
let loader: ReturnType<typeof createScriptLoader> | undefined;
|
|
123
|
+
|
|
124
|
+
const removeMountedHook = nuxtApp.hook('app:mounted', () => {
|
|
125
|
+
loader = createScriptLoader({ kernel, scripts });
|
|
126
|
+
});
|
|
127
|
+
onUnmounted(() => {
|
|
128
|
+
removeMountedHook();
|
|
129
|
+
loader?.dispose();
|
|
130
|
+
});
|
|
131
|
+
</script>
|
|
132
|
+
|
|
133
|
+
<template>
|
|
134
|
+
<ConsentRoot />
|
|
135
|
+
<NuxtPage />
|
|
136
|
+
</template>
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Merge the setup code into your root and retain its footer and preferences
|
|
140
|
+
link. `useConsentKernel` is auto-imported by the c15t Nuxt module. Adjust the
|
|
141
|
+
relative script import if your `app.vue` is at the project root. This loader
|
|
142
|
+
waits until the module has applied browser persistence and privacy signals,
|
|
143
|
+
then reads the current snapshot and observes future changes. Do not also register these scripts
|
|
144
|
+
in another loader. See the [Nuxt quickstart](https://c15t.com/docs/frameworks/nuxt/quickstart).
|
|
145
|
+
|
|
146
|
+
**Vue**
|
|
147
|
+
|
|
148
|
+
Use the kernel already provided by the Vue plugin. Merge this setup into
|
|
149
|
+
`App.vue`, whose lifetime covers the application:
|
|
150
|
+
|
|
151
|
+
```vue title="src/App.vue"
|
|
152
|
+
<script setup lang="ts">
|
|
153
|
+
import { onMounted, onUnmounted } from 'vue';
|
|
154
|
+
import { createScriptLoader } from 'c15t/modules/script-loader';
|
|
155
|
+
import { useConsentKernel } from 'c15t/vue/vue-plugin';
|
|
156
|
+
import ConsentRoot from 'c15t/vue/consent-root';
|
|
157
|
+
import { scripts } from './consent-scripts';
|
|
158
|
+
|
|
159
|
+
const kernel = useConsentKernel();
|
|
160
|
+
let loader: ReturnType<typeof createScriptLoader> | undefined;
|
|
161
|
+
|
|
162
|
+
onMounted(() => {
|
|
163
|
+
loader = createScriptLoader({ kernel, scripts });
|
|
164
|
+
});
|
|
165
|
+
onUnmounted(() => loader?.dispose());
|
|
166
|
+
</script>
|
|
167
|
+
|
|
168
|
+
<template>
|
|
169
|
+
<ConsentRoot />
|
|
170
|
+
<main>Your application</main>
|
|
171
|
+
</template>
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Keep your existing page content and preferences link. The plugin still owns
|
|
175
|
+
the kernel and persistence; this component owns only the vendor loader.
|
|
176
|
+
Do not register the same scripts in plugin configuration as well. See the
|
|
177
|
+
[Vue quickstart](https://c15t.com/docs/frameworks/vue/quickstart).
|
|
178
|
+
|
|
179
|
+
**Astro**
|
|
180
|
+
|
|
181
|
+
Point the existing Astro integration at a client module. Keep its `mode`,
|
|
182
|
+
`ui` and framework integration from the [Astro quickstart](https://c15t.com/docs/frameworks/astro/quickstart).
|
|
183
|
+
Import `fileURLToPath` in your Astro configuration:
|
|
184
|
+
|
|
185
|
+
```js title="astro.config.mjs"
|
|
186
|
+
import { fileURLToPath } from 'node:url';
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Add this option to the existing `c15t({ ... })` call. Resolve the path from
|
|
190
|
+
the configuration file because Astro injects the import into a virtual module:
|
|
191
|
+
|
|
192
|
+
```js
|
|
193
|
+
clientEntrypoint: fileURLToPath(new URL('./src/c15t.client.ts', import.meta.url)),
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Export the scripts from that module:
|
|
197
|
+
|
|
198
|
+
```ts title="src/c15t.client.ts"
|
|
199
|
+
import type { C15tClientOptionsExtension } from 'c15t/astro';
|
|
200
|
+
import { scripts } from './consent-scripts';
|
|
201
|
+
|
|
202
|
+
export default { scripts } satisfies C15tClientOptionsExtension;
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
The integration passes this extension to its shared browser runtime. Vendor
|
|
206
|
+
helpers contain callbacks, so do not put them in the serialized `scripts`
|
|
207
|
+
option in `astro.config.mjs`. Keep one runtime across consent islands and
|
|
208
|
+
`ClientRouter` navigation.
|
|
209
|
+
|
|
210
|
+
**Svelte**
|
|
211
|
+
|
|
212
|
+
Import the scripts in the component that owns your existing provider and
|
|
213
|
+
pass them as a top-level prop:
|
|
214
|
+
|
|
215
|
+
```svelte title="src/App.svelte"
|
|
216
|
+
<script lang="ts">
|
|
217
|
+
import { ConsentManagerProvider, hosted } from '@c15t/svelte';
|
|
218
|
+
import { scripts } from './consent-scripts';
|
|
219
|
+
|
|
220
|
+
const backendURL = import.meta.env.VITE_C15T_BACKEND_URL;
|
|
221
|
+
if (!backendURL) throw new Error('Set VITE_C15T_BACKEND_URL');
|
|
222
|
+
const mode = hosted({ url: backendURL });
|
|
223
|
+
</script>
|
|
224
|
+
|
|
225
|
+
<ConsentManagerProvider {mode} {scripts}>
|
|
226
|
+
<!-- Keep your application, consent UI and preferences link here. -->
|
|
227
|
+
</ConsentManagerProvider>
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
Retain the styles and consent UI from the [Svelte quickstart](https://c15t.com/docs/frameworks/svelte/quickstart).
|
|
231
|
+
The provider owns the loader and disposes it on unmount.
|
|
232
|
+
|
|
233
|
+
**SvelteKit**
|
|
234
|
+
|
|
235
|
+
Add the scripts to the existing root layout provider. Keep the server load
|
|
236
|
+
and its serializable prefetch data from the [SvelteKit quickstart](https://c15t.com/docs/frameworks/sveltekit/quickstart).
|
|
237
|
+
|
|
238
|
+
```svelte title="src/routes/+layout.svelte"
|
|
239
|
+
<script lang="ts">
|
|
240
|
+
import { ConsentManagerProvider, hosted } from '@c15t/svelte';
|
|
241
|
+
import { scripts } from '../consent-scripts';
|
|
242
|
+
|
|
243
|
+
let { children, data } = $props();
|
|
244
|
+
const mode = hosted({ url: data.backendURL });
|
|
245
|
+
</script>
|
|
246
|
+
|
|
247
|
+
<ConsentManagerProvider {mode} {scripts} prefetch={data.prefetch}>
|
|
248
|
+
{@render children()}
|
|
249
|
+
<!-- Keep your consent UI and preferences link here. -->
|
|
250
|
+
</ConsentManagerProvider>
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
Import vendor helpers in the layout component, not in `+layout.server.ts`.
|
|
254
|
+
For static hosting, keep your browser-only `mode` setup and omit request
|
|
255
|
+
prefetch; the `scripts` prop stays the same. If you pass an externally owned
|
|
256
|
+
`runtime` to the provider, register scripts when creating that runtime instead.
|
|
257
|
+
|
|
258
|
+
**JavaScript**
|
|
259
|
+
|
|
260
|
+
Attach the loader to your existing kernel before calling
|
|
261
|
+
`kernel.commands.init()`:
|
|
262
|
+
|
|
263
|
+
```ts
|
|
264
|
+
import { createScriptLoader } from 'c15t/modules/script-loader';
|
|
265
|
+
import { scripts } from './consent-scripts';
|
|
266
|
+
|
|
267
|
+
const loader = createScriptLoader({ kernel, scripts });
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
Call `loader.dispose()` when that application instance is destroyed.
|
|
271
|
+
`kernel` is the hosted kernel from your quickstart. A provider-owned kernel
|
|
272
|
+
already has a loader; do not attach a second one. See
|
|
273
|
+
[JavaScript script loading](../frameworks/javascript/script-loader.md).
|
|
274
|
+
|
|
275
|
+
## Options
|
|
276
|
+
|
|
277
|
+
| Option | Behavior |
|
|
278
|
+
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
279
|
+
| `chatId` | Required public chat ID. An empty value throws. |
|
|
280
|
+
| `useDefaultLauncher` | Shows Front's launcher. Defaults to `true`. With `false`, open the widget from your own launcher through Front's [SDK](https://dev.frontapp.com/docs/chat-sdk-reference). |
|
|
281
|
+
| `nonce` | CSP nonce for the loader and Front's generated scripts. A loader-level nonce from your provider is forwarded too. |
|
|
282
|
+
| `scriptSrc` | Defaults to `https://chat-assets.frontapp.com/v1/chat.bundle.js`. A proxy here does not proxy the widget's other requests. |
|
|
283
|
+
|
|
284
|
+
Front creates more resources for the widget. Follow Front's
|
|
285
|
+
[CSP instructions](https://help.front.com/en/articles/2049) for the rest of the
|
|
286
|
+
policy.
|
|
287
|
+
|
|
288
|
+
## Consent behavior
|
|
289
|
+
|
|
290
|
+
The widget waits for functionality permission. When a visitor revokes it, c15t
|
|
291
|
+
reloads the page, which removes the running widget. Keep
|
|
292
|
+
`reloadOnConsentRevoked` enabled: removing the loader cannot stop a widget that
|
|
293
|
+
already initialized.
|
|
294
|
+
|
|
295
|
+
To also clear the visitor's Front session, call `shutdownFrontChat()` from
|
|
296
|
+
`onBeforeConsentRevocationReload`:
|
|
297
|
+
|
|
298
|
+
```ts
|
|
299
|
+
import { shutdownFrontChat } from '@c15t/scripts/front-chat';
|
|
300
|
+
|
|
301
|
+
const callbacks = {
|
|
302
|
+
onBeforeConsentRevocationReload: ({ preferences }) => {
|
|
303
|
+
if (!preferences.functionality) {
|
|
304
|
+
shutdownFrontChat();
|
|
305
|
+
}
|
|
306
|
+
},
|
|
307
|
+
};
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
It sends Front's `shutdown` command with `clearSession: true` when the SDK has
|
|
311
|
+
loaded. Front returns no completion signal, so the reload does not wait for the
|
|
312
|
+
session to clear.
|
|
313
|
+
|
|
314
|
+
## Verify the integration
|
|
315
|
+
|
|
316
|
+
Reject functionality permission and confirm the loader is absent. Grant it and
|
|
317
|
+
confirm the widget opens and connects to your Front inbox. Then revoke it and
|
|
318
|
+
confirm the page reloads without the widget. Keep another support contact
|
|
319
|
+
available while chat is blocked.
|
|
320
|
+
|
|
321
|
+
Removing a script cannot undo requests that already ran. Follow the
|
|
322
|
+
[consent verification guide](../guides/verify-consent.md).
|
|
@@ -175,7 +175,7 @@ Add this component to pages using your consent-enabled base layout:
|
|
|
175
175
|
<c15t-consent-embed style="display: block"></c15t-consent-embed>
|
|
176
176
|
|
|
177
177
|
<script>
|
|
178
|
-
import { getConsentClient } from '
|
|
178
|
+
import { getConsentClient } from 'c15t/astro/client';
|
|
179
179
|
import { mountConsentEmbed } from '../consent-embed';
|
|
180
180
|
|
|
181
181
|
class ConsentEmbed extends HTMLElement {
|
|
@@ -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 '
|
|
199
|
+
import type { C15tClientOptionsExtension } from 'c15t/astro';
|
|
200
200
|
import { scripts } from './consent-scripts';
|
|
201
201
|
|
|
202
202
|
export default { scripts } satisfies C15tClientOptionsExtension;
|
|
@@ -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 '
|
|
201
|
+
import type { C15tClientOptionsExtension } from 'c15t/astro';
|
|
202
202
|
import { scripts } from './consent-scripts';
|
|
203
203
|
|
|
204
204
|
export default { scripts } satisfies C15tClientOptionsExtension;
|
|
@@ -80,7 +80,9 @@ loads = category condition satisfied AND vendor not denied
|
|
|
80
80
|
```
|
|
81
81
|
|
|
82
82
|
The category is evaluated first, so an unknown category still throws as a
|
|
83
|
-
configuration error.
|
|
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
|
|
84
86
|
marketing denied, `meta-pixel` stays blocked whatever its own switch says.
|
|
85
87
|
A script with `alwaysLoad` still mounts, as it does for a denied category;
|
|
86
88
|
its callbacks receive the vendor result in `info.vendor.granted` so a
|
|
@@ -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 '
|
|
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 '
|
|
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 '
|
|
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 '
|
|
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 '
|
|
197
|
+
import type { C15tClientOptionsExtension } from 'c15t/astro';
|
|
198
198
|
import { scripts } from './consent-scripts';
|
|
199
199
|
|
|
200
200
|
export default { scripts } satisfies C15tClientOptionsExtension;
|