@c15t/react 3.0.0-alpha.8 → 3.0.0
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 +10 -12
- package/README.md +41 -70
- package/SKILL.md +1 -1
- package/dist/aggregate-components.js +1 -1
- package/dist/components/consent-gate/atoms.js +1 -1
- package/dist/components/consent-gate/frame.js +2 -0
- package/dist/components/consent-gate/index.js +1 -1
- package/dist/components/iab-panel/atoms/root.js +1 -1
- package/dist/components/iab-panel/iab-panel.js +1 -1
- package/dist/components/iab-prompt/atoms/root.js +1 -1
- package/dist/components/iab-prompt/iab-prompt.js +1 -1
- package/dist/components/panel/atoms/root.js +1 -1
- package/dist/components/panel-trigger/atoms/root.js +1 -1
- package/dist/components/panel-trigger/panel-trigger.js +1 -1
- package/dist/components/panel-trigger/toolbar-loader.js +2 -0
- package/dist/components/preferences/atoms/root.js +1 -1
- package/dist/components/prompt/atoms/early-tap-script.js +2 -0
- package/dist/components/prompt/atoms/root.js +1 -1
- package/dist/components/prompt/prompt.js +1 -1
- package/dist/components/shared/dialog-sheets.js +1 -0
- package/dist/components/shared/first-paint-sheets.js +1 -0
- package/dist/components/shared/iab-dialog-sheets.js +1 -0
- package/dist/components/shared/iab-first-paint-sheets.js +1 -0
- package/dist/components/shared/primitives/button.js +1 -1
- package/dist/components/shared/surface-styles.js +2 -0
- package/dist/consent-gate.js +1 -1
- package/dist/context/index.js +1 -1
- package/dist/devtools.js +1 -1
- package/dist/hooks/use-iab-policy-guard.js +1 -0
- package/dist/iab/styles.tw3.css +2 -2
- package/dist/iab-context.js +1 -1
- package/dist/iab-dialog-deferred.js +2 -0
- package/dist/iab.js +1 -1
- package/dist/index-parts/consent-gate.js +1 -1
- package/dist/index-parts/core.js +1 -1
- package/dist/index-parts/frame.js +1 -0
- package/dist/index-parts/hosted.js +1 -0
- package/dist/index-parts/offline.js +1 -0
- package/dist/index-parts/presets.js +1 -0
- package/dist/index.js +1 -1
- package/dist/modes.js +1 -0
- package/dist/panel-link.js +1 -1
- package/dist/panel-trigger.js +1 -1
- package/dist/provider.js +1 -1
- package/dist/styles.tw3.css +2 -2
- package/dist/transports/hosted.js +1 -0
- package/dist/transports/manifest.js +1 -0
- package/dist/utils/deferred-module.js +1 -1
- package/dist/version.js +1 -1
- package/dist-types/chunk-warming.d.ts +7 -6
- package/dist-types/components/consent-gate/frame.d.ts +19 -0
- package/dist-types/components/consent-gate/index.d.ts +3 -19
- package/dist-types/components/iab-prompt/iab-prompt.d.ts +1 -1
- package/dist-types/components/panel/index.d.ts +1 -1
- package/dist-types/components/panel-trigger/toolbar-loader.d.ts +34 -0
- package/dist-types/components/preferences/index.d.ts +1 -1
- package/dist-types/components/prompt/atoms/early-tap-script.d.ts +17 -0
- package/dist-types/components/prompt/index.d.ts +1 -1
- package/dist-types/components/shared/dialog-sheets.d.ts +9 -0
- package/dist-types/components/shared/first-paint-sheets.d.ts +8 -0
- package/dist-types/components/shared/iab-dialog-sheets.d.ts +3 -0
- package/dist-types/components/shared/iab-first-paint-sheets.d.ts +3 -0
- package/dist-types/components/shared/surface-styles.d.ts +60 -0
- package/dist-types/consent-gate.d.ts +1 -1
- package/dist-types/context/index.d.ts +3 -3
- package/dist-types/context.d.ts +2 -0
- package/dist-types/gpp.d.ts +1 -1
- package/dist-types/hooks/use-iab-policy-guard.d.ts +35 -0
- package/dist-types/iab-dialog-deferred.d.ts +36 -0
- package/dist-types/iab.d.ts +3 -2
- package/dist-types/index-parts/consent-gate.d.ts +1 -1
- package/dist-types/index-parts/core.d.ts +1 -2
- package/dist-types/index-parts/frame.d.ts +7 -0
- package/dist-types/index-parts/hosted.d.ts +7 -0
- package/dist-types/index-parts/offline.d.ts +7 -0
- package/dist-types/index-parts/presets.d.ts +7 -0
- package/dist-types/index.d.ts +5 -1
- package/dist-types/modes.d.ts +26 -0
- package/dist-types/panel-link.d.ts +1 -1
- package/dist-types/panel-trigger.d.ts +1 -1
- package/dist-types/provider.d.ts +22 -4
- package/dist-types/transports/hosted.d.ts +36 -0
- package/dist-types/transports/manifest.d.ts +48 -0
- package/dist-types/ui-config-context.d.ts +4 -0
- package/dist-types/version.d.ts +1 -1
- package/docs/README.md +10 -12
- package/docs/concepts/choose-your-setup.md +45 -8
- package/docs/concepts/consent-categories.md +1 -1
- package/docs/concepts/consent-state.md +5 -2
- package/docs/concepts/data-fetching.md +100 -40
- package/docs/concepts/modes.md +281 -0
- package/docs/customization/dark-mode.md +1 -1
- package/docs/customization/motion.md +2 -2
- package/docs/customization/overview.md +3 -2
- package/docs/customization/recipes.md +4 -4
- package/docs/customization/slots.md +25 -25
- package/docs/customization/stylesheets.md +161 -50
- package/docs/customization/tailwind.md +71 -50
- package/docs/customization/tokens.md +42 -13
- package/docs/frameworks/react/components/consent-banner.md +14 -12
- package/docs/frameworks/react/components/consent-dialog.md +15 -13
- package/docs/frameworks/react/components/consent-provider.md +51 -46
- package/docs/frameworks/react/components.md +16 -13
- package/docs/frameworks/react/compose.md +3 -3
- package/docs/frameworks/react/content-security-policy.md +35 -12
- package/docs/frameworks/react/customize.md +21 -13
- package/docs/frameworks/react/hooks.md +2 -2
- package/docs/frameworks/react/iab.md +56 -6
- package/docs/frameworks/react/quickstart.md +65 -99
- package/docs/frameworks/react/rendering.md +170 -94
- package/docs/frameworks/react/scripts.md +19 -30
- package/docs/frameworks/react/troubleshooting.md +100 -32
- package/docs/frameworks/react/upgrade-v3.md +133 -79
- package/docs/frameworks/react/vendor-consent.md +19 -7
- package/docs/guides/banner-experiments.md +21 -8
- package/docs/guides/troubleshooting.md +90 -26
- package/docs/guides/verify-consent.md +23 -8
- package/docs/integrations/adobe-analytics.md +60 -64
- package/docs/integrations/ahrefs-analytics.md +58 -63
- package/docs/integrations/amplitude.md +60 -64
- package/docs/integrations/clearbit.md +59 -63
- package/docs/integrations/cloudflare-web-analytics.md +56 -60
- package/docs/integrations/cloudflare-zaraz.md +55 -57
- package/docs/integrations/crisp.md +64 -69
- package/docs/integrations/databuddy.md +62 -64
- package/docs/integrations/fathom-analytics.md +56 -60
- package/docs/integrations/front-chat.md +56 -60
- package/docs/integrations/google-maps.md +25 -13
- package/docs/integrations/google-tag-manager.md +153 -77
- package/docs/integrations/google-tag.md +134 -78
- package/docs/integrations/heap.md +56 -60
- package/docs/integrations/hightouch.md +55 -60
- package/docs/integrations/hotjar.md +60 -64
- package/docs/integrations/intercom.md +55 -60
- package/docs/integrations/klaviyo.md +65 -66
- package/docs/integrations/linkedin-insights.md +58 -63
- package/docs/integrations/logrocket.md +55 -60
- package/docs/integrations/matomo-analytics.md +58 -60
- package/docs/integrations/meta-pixel.md +56 -60
- package/docs/integrations/microsoft-clarity.md +57 -60
- package/docs/integrations/microsoft-uet.md +58 -61
- package/docs/integrations/mixpanel-analytics.md +73 -75
- package/docs/integrations/one-dollar-stats.md +53 -59
- package/docs/integrations/openai-pixel.md +58 -60
- package/docs/integrations/overview.md +59 -42
- package/docs/integrations/pinterest-tag.md +56 -60
- package/docs/integrations/pirsch.md +54 -60
- package/docs/integrations/plausible-analytics.md +55 -60
- package/docs/integrations/posthog.md +56 -60
- package/docs/integrations/promptwatch.md +57 -63
- package/docs/integrations/reddit-pixel.md +57 -60
- package/docs/integrations/rudderstack.md +65 -67
- package/docs/integrations/rybbit-analytics.md +70 -75
- package/docs/integrations/segment.md +56 -60
- package/docs/integrations/sentry.md +65 -60
- package/docs/integrations/snapchat-pixel.md +54 -60
- package/docs/integrations/tiktok-pixel.md +59 -63
- package/docs/integrations/umami-analytics.md +54 -60
- package/docs/integrations/vercel-analytics.md +53 -59
- package/docs/integrations/vercel-speed-insights.md +317 -0
- package/docs/integrations/x-pixel.md +57 -63
- package/docs/integrations/youtube.md +25 -13
- package/package.json +18 -8
- package/docs/upgrade-v3.md +0 -429
|
@@ -2,22 +2,31 @@
|
|
|
2
2
|
title: Plausible Analytics
|
|
3
3
|
description: Load the Plausible Analytics tracker only after measurement consent
|
|
4
4
|
with the c15t plausibleAnalytics helper, and check it in DevTools.
|
|
5
|
+
seoTitle: Plausible Analytics cookie consent with c15t
|
|
6
|
+
seoDescription: Load Plausible Analytics only with measurement consent. Set it
|
|
7
|
+
up with the c15t plausibleAnalytics helper and check it in DevTools.
|
|
5
8
|
icon: plausible
|
|
6
9
|
group: integrations
|
|
7
10
|
---
|
|
8
11
|
|
|
12
|
+
The c15t `plausibleAnalytics` helper keeps Plausible Analytics off the page
|
|
13
|
+
until `measurement` has consent. Until then, c15t does not define
|
|
14
|
+
`window.plausible`. The helper sends no consent signal to Plausible. If the
|
|
15
|
+
visitor withdraws consent, c15t removes the script element. By default, c15t
|
|
16
|
+
also reloads the page.
|
|
17
|
+
|
|
9
18
|
## Configure Plausible Analytics
|
|
10
19
|
|
|
11
20
|
Copy the script ID from your Plausible installation snippet. It is the part of
|
|
12
21
|
the `pa-<id>.js` file name. Sites that still use the legacy domain-based
|
|
13
22
|
snippet can pass `domain` instead of `scriptId`.
|
|
14
23
|
|
|
15
|
-
| Package manager | Command
|
|
16
|
-
| :-------------- |
|
|
17
|
-
| npm | `npm install @c15t/integrations
|
|
18
|
-
| pnpm | `pnpm add @c15t/integrations
|
|
19
|
-
| yarn | `yarn add @c15t/integrations
|
|
20
|
-
| bun | `bun add @c15t/integrations
|
|
24
|
+
| Package manager | Command |
|
|
25
|
+
| :-------------- | :------------------------------- |
|
|
26
|
+
| npm | `npm install @c15t/integrations` |
|
|
27
|
+
| pnpm | `pnpm add @c15t/integrations` |
|
|
28
|
+
| yarn | `yarn add @c15t/integrations` |
|
|
29
|
+
| bun | `bun add @c15t/integrations` |
|
|
21
30
|
|
|
22
31
|
```ts title="src/consent-scripts.ts"
|
|
23
32
|
import { plausibleAnalytics } from '@c15t/integrations/plausible-analytics';
|
|
@@ -32,51 +41,41 @@ endpoint, policy, styles and consent UI. Remove the vendor's original script,
|
|
|
32
41
|
SDK initializer or tag-manager entry, so the vendor loads only through c15t.
|
|
33
42
|
|
|
34
43
|
The vendor pages put the helper in `src/consent-scripts.ts`. If your framework
|
|
35
|
-
quickstart already
|
|
36
|
-
Next.js guide, add the helper to that array instead of creating a
|
|
44
|
+
quickstart already has a `scripts` array, such as the one in `c15t.config.ts`
|
|
45
|
+
in the Next.js guide, add the helper to that array instead of creating a
|
|
46
|
+
second file.
|
|
37
47
|
The `scripts` export is a configuration, not an initializer. Add it to the c15t provider you already have, at the registration
|
|
38
48
|
point for your framework below. These are edits to that provider, not a second
|
|
39
49
|
provider.
|
|
40
50
|
|
|
41
51
|
**Next.js**
|
|
42
52
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
```ts
|
|
46
|
-
import { ConsentRoot } from 'c15t/next';
|
|
47
|
-
import { scripts } from './consent-scripts';
|
|
48
|
-
```
|
|
53
|
+
Add the configuration to `scripts` in `c15t.config.ts`, next to
|
|
54
|
+
`next.config.ts`:
|
|
49
55
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
56
|
+
```ts title="c15t.config.ts"
|
|
57
|
+
import { defineConsentConfig } from 'c15t/next';
|
|
58
|
+
import { scripts } from './src/consent-scripts';
|
|
53
59
|
|
|
54
|
-
|
|
55
|
-
<ConsentRoot state={state} config={consentConfig} scripts={scripts}>
|
|
56
|
-
{children}
|
|
57
|
-
</ConsentRoot>
|
|
60
|
+
export default defineConsentConfig({ scripts });
|
|
58
61
|
```
|
|
59
62
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
+
Keep the rest of your config, such as `mode` and `routePrefix`, in the
|
|
64
|
+
same call. `ConsentRoot` reads the config in the browser, so the layout
|
|
65
|
+
keeps passing only `state`. App Router, Pages Router and static export all
|
|
66
|
+
read the same file. See
|
|
63
67
|
[Next.js scripts and embeds](https://c15t.com/docs/frameworks/next/scripts).
|
|
64
68
|
|
|
65
69
|
**TanStack Start**
|
|
66
70
|
|
|
67
71
|
Import the configuration into your root route and pass it to the existing
|
|
68
|
-
`ConsentRoot` as a top-level prop. Keep the loader
|
|
69
|
-
|
|
72
|
+
`ConsentRoot` as a top-level prop. Keep the loader from the
|
|
73
|
+
[TanStack Start quickstart](https://c15t.com/docs/frameworks/tanstack-start/quickstart):
|
|
70
74
|
|
|
71
75
|
```tsx title="src/routes/__root.tsx"
|
|
72
76
|
import { scripts } from '../consent-scripts';
|
|
73
77
|
|
|
74
|
-
<ConsentRoot
|
|
75
|
-
state={consent}
|
|
76
|
-
backendURL={backendURL}
|
|
77
|
-
initRoute={false}
|
|
78
|
-
scripts={scripts}
|
|
79
|
-
>
|
|
78
|
+
<ConsentRoot state={consent} scripts={scripts}>
|
|
80
79
|
```
|
|
81
80
|
|
|
82
81
|
Import vendor helpers in the root route module, not in a server function.
|
|
@@ -95,8 +94,8 @@ import { scripts } from './consent-scripts';
|
|
|
95
94
|
<ConsentProvider options={{ mode, scripts }}>
|
|
96
95
|
```
|
|
97
96
|
|
|
98
|
-
`mode` is the `
|
|
99
|
-
|
|
97
|
+
`mode` is the `manifest()` value from the
|
|
98
|
+
[React quickstart](../frameworks/react/quickstart.md). Keep the banner,
|
|
100
99
|
dialog and preferences link inside the provider. See
|
|
101
100
|
[React scripts and embeds](../frameworks/react/scripts.md).
|
|
102
101
|
|
|
@@ -125,15 +124,16 @@ callbacks. Write the vendor IDs into `consent-scripts.ts`. See
|
|
|
125
124
|
Pass the scripts to the existing `c15tVue` plugin call in `src/main.ts`:
|
|
126
125
|
|
|
127
126
|
```ts title="src/main.ts"
|
|
127
|
+
import { c15tVue, manifest } from 'c15t/vue/vue-plugin';
|
|
128
128
|
import { scripts } from './consent-scripts';
|
|
129
129
|
|
|
130
130
|
app.use(c15tVue, {
|
|
131
|
-
|
|
131
|
+
mode: manifest(),
|
|
132
132
|
scripts,
|
|
133
133
|
});
|
|
134
134
|
```
|
|
135
135
|
|
|
136
|
-
Keep your existing
|
|
136
|
+
Keep your existing `mode` and other options. The plugin starts one
|
|
137
137
|
script loader when the app mounts, after it has applied the visitor's stored
|
|
138
138
|
choice. Do not also call `createScriptLoader` from a component. See
|
|
139
139
|
[Vue scripts and embeds](https://c15t.com/docs/frameworks/vue/scripts).
|
|
@@ -141,12 +141,11 @@ choice. Do not also call `createScriptLoader` from a component. See
|
|
|
141
141
|
**Astro**
|
|
142
142
|
|
|
143
143
|
Add the scripts to the client entrypoint from the
|
|
144
|
-
[Astro quickstart](https://c15t.com/docs/frameworks/astro/quickstart),
|
|
145
|
-
integration
|
|
146
|
-
|
|
147
|
-
already exports scripts, combine the two arrays.
|
|
144
|
+
[Astro quickstart](https://c15t.com/docs/frameworks/astro/quickstart), `src/c15t.client.ts`,
|
|
145
|
+
which the integration finds on its own. Keep `astro.config.mjs` as it is.
|
|
146
|
+
If the module already exports scripts, combine the two arrays.
|
|
148
147
|
|
|
149
|
-
```ts title="src/
|
|
148
|
+
```ts title="src/c15t.client.ts"
|
|
150
149
|
import type { C15tClientOptionsExtension } from 'c15t/astro';
|
|
151
150
|
import { scripts } from './consent-scripts';
|
|
152
151
|
|
|
@@ -166,15 +165,13 @@ pass them as a top-level prop:
|
|
|
166
165
|
|
|
167
166
|
```svelte title="src/App.svelte"
|
|
168
167
|
<script lang="ts">
|
|
169
|
-
import {
|
|
168
|
+
import { ConsentProvider, manifest } from '@c15t/svelte';
|
|
170
169
|
import { scripts } from './consent-scripts';
|
|
171
|
-
|
|
172
|
-
const mode = hosted({ url: 'https://your-project.inth.app' });
|
|
173
170
|
</script>
|
|
174
171
|
|
|
175
|
-
<
|
|
172
|
+
<ConsentProvider mode={manifest()} {scripts}>
|
|
176
173
|
<!-- Keep your application, consent UI and preferences link here. -->
|
|
177
|
-
</
|
|
174
|
+
</ConsentProvider>
|
|
178
175
|
```
|
|
179
176
|
|
|
180
177
|
Retain the styles and consent UI from the [Svelte quickstart](https://c15t.com/docs/frameworks/svelte/quickstart).
|
|
@@ -182,22 +179,21 @@ The provider owns the loader and disposes it on unmount.
|
|
|
182
179
|
|
|
183
180
|
**SvelteKit**
|
|
184
181
|
|
|
185
|
-
Add the scripts to the existing root layout
|
|
186
|
-
and
|
|
182
|
+
Add the scripts to the existing `ConsentRoot` in the root layout. Keep the
|
|
183
|
+
handle and the layout load from the [SvelteKit quickstart](https://c15t.com/docs/frameworks/sveltekit/quickstart).
|
|
187
184
|
|
|
188
185
|
```svelte title="src/routes/+layout.svelte"
|
|
189
186
|
<script lang="ts">
|
|
190
|
-
import {
|
|
187
|
+
import { ConsentRoot } from '@c15t/svelte';
|
|
191
188
|
import { scripts } from '../consent-scripts';
|
|
192
189
|
|
|
193
190
|
let { children, data } = $props();
|
|
194
|
-
const mode = hosted({ url: 'https://your-project.inth.app' });
|
|
195
191
|
</script>
|
|
196
192
|
|
|
197
|
-
<
|
|
193
|
+
<ConsentRoot state={data.consent} {scripts}>
|
|
198
194
|
{@render children()}
|
|
199
195
|
<!-- Keep your consent UI and preferences link here. -->
|
|
200
|
-
</
|
|
196
|
+
</ConsentRoot>
|
|
201
197
|
```
|
|
202
198
|
|
|
203
199
|
Import vendor helpers in the layout component, not in `+layout.server.ts`:
|
|
@@ -224,20 +220,19 @@ to a pasted snippet. See [HTML scripts](https://c15t.com/docs/frameworks/html/sc
|
|
|
224
220
|
|
|
225
221
|
**JavaScript**
|
|
226
222
|
|
|
227
|
-
Pass the scripts to `init()` from `@c15t/browser`, next to your
|
|
228
|
-
URL:
|
|
223
|
+
Pass the scripts to `init()` from `@c15t/browser`, next to your mode:
|
|
229
224
|
|
|
230
225
|
```ts
|
|
231
|
-
import { init } from '@c15t/browser';
|
|
226
|
+
import { init, manifest } from '@c15t/browser';
|
|
232
227
|
import { scripts } from './consent-scripts';
|
|
233
228
|
|
|
234
229
|
const consent = init({
|
|
235
|
-
|
|
230
|
+
mode: manifest(),
|
|
236
231
|
scripts,
|
|
237
232
|
});
|
|
238
233
|
```
|
|
239
234
|
|
|
240
|
-
Keep the
|
|
235
|
+
Keep the mode from your quickstart. With
|
|
241
236
|
`createConsentRuntime` from `c15t/runtime`, pass `scripts` to it instead.
|
|
242
237
|
A kernel you create yourself needs a loader from
|
|
243
238
|
`c15t/modules/script-loader`. Attach one loader per kernel. See
|
|
@@ -248,7 +243,7 @@ A kernel you create yourself needs a loader from
|
|
|
248
243
|
| Option | Default | Behavior |
|
|
249
244
|
| ---------------------- | ------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
250
245
|
| `scriptId` | None | Script ID for the `pa-<scriptId>.js` loader. Takes precedence over `domain` and `extension`. |
|
|
251
|
-
| `domain` | None | Legacy site domain, set as `data-domain`.
|
|
246
|
+
| `domain` | None | Legacy site domain, set as `data-domain`. When neither `scriptId` nor `domain` has a non-empty value, the helper logs an error and the script does not load. |
|
|
252
247
|
| `extension` | None | Legacy script extension or array of extensions, such as `['file-downloads', 'outbound-links']`. The helper joins them into `script.<extensions>.js`. Ignored with `scriptId`. |
|
|
253
248
|
| `customProperties` | None | Properties sent with each page view. |
|
|
254
249
|
| `endpoint` | None | Custom event endpoint. With `domain`, the helper also sets it as `data-api`. |
|
|
@@ -302,8 +297,8 @@ permission before each of your own event calls. The reload does not delete
|
|
|
302
297
|
cookies the vendor already set; see
|
|
303
298
|
[clear on revocation for your framework](./overview.md#vendor-switches-and-cookie-cleanup).
|
|
304
299
|
|
|
305
|
-
The helper
|
|
306
|
-
|
|
300
|
+
The helper lists its vendor by name in the preference dialog, so a visitor can
|
|
301
|
+
turn it off inside an allowed category. See
|
|
307
302
|
[vendor consent for your framework](./overview.md#vendor-switches-and-cookie-cleanup). The
|
|
308
303
|
[consent verification guide](../guides/verify-consent.md) covers navigation,
|
|
309
304
|
expiry and hosting checks.
|
|
@@ -3,22 +3,32 @@ title: PostHog
|
|
|
3
3
|
description: Load PostHog before or after measurement consent with the c15t
|
|
4
4
|
posthog helper, choose its cookieless behavior, turn off PostHog modules you
|
|
5
5
|
do not use, and sync consent with an SDK you already initialize.
|
|
6
|
+
seoTitle: PostHog cookie consent with c15t
|
|
7
|
+
seoDescription: Opt PostHog out without measurement consent, with cookieless
|
|
8
|
+
capture or a full wait for consent. Set it up with the c15t posthog helper.
|
|
6
9
|
icon: posthog
|
|
7
10
|
group: integrations
|
|
8
11
|
---
|
|
9
12
|
|
|
13
|
+
By default, the c15t `posthog` helper loads PostHog's `array.js` on every page,
|
|
14
|
+
before the visitor chooses. While `measurement` has no consent, the helper calls
|
|
15
|
+
`opt_out_capturing()`. This is also true before the visitor chooses. While
|
|
16
|
+
`measurement` has consent, the helper calls `opt_in_capturing()`. The default
|
|
17
|
+
`cookieless_mode: 'on_reject'` changes PostHog to cookieless capture after an
|
|
18
|
+
opt-out. To wait for consent before the load, set `loadMode: 'after-consent'`.
|
|
19
|
+
|
|
10
20
|
## Configure PostHog
|
|
11
21
|
|
|
12
22
|
Use the project token that starts with `phc_`, and the region of your PostHog
|
|
13
23
|
project. This example waits for measurement permission before requesting the
|
|
14
24
|
SDK, and turns off cookieless capture after a refusal.
|
|
15
25
|
|
|
16
|
-
| Package manager | Command
|
|
17
|
-
| :-------------- |
|
|
18
|
-
| npm | `npm install @c15t/integrations
|
|
19
|
-
| pnpm | `pnpm add @c15t/integrations
|
|
20
|
-
| yarn | `yarn add @c15t/integrations
|
|
21
|
-
| bun | `bun add @c15t/integrations
|
|
26
|
+
| Package manager | Command |
|
|
27
|
+
| :-------------- | :------------------------------- |
|
|
28
|
+
| npm | `npm install @c15t/integrations` |
|
|
29
|
+
| pnpm | `pnpm add @c15t/integrations` |
|
|
30
|
+
| yarn | `yarn add @c15t/integrations` |
|
|
31
|
+
| bun | `bun add @c15t/integrations` |
|
|
22
32
|
|
|
23
33
|
```ts title="src/consent-scripts.ts"
|
|
24
34
|
import { posthog } from '@c15t/integrations/posthog';
|
|
@@ -44,51 +54,41 @@ endpoint, policy, styles and consent UI. Remove the vendor's original script,
|
|
|
44
54
|
SDK initializer or tag-manager entry, so the vendor loads only through c15t.
|
|
45
55
|
|
|
46
56
|
The vendor pages put the helper in `src/consent-scripts.ts`. If your framework
|
|
47
|
-
quickstart already
|
|
48
|
-
Next.js guide, add the helper to that array instead of creating a
|
|
57
|
+
quickstart already has a `scripts` array, such as the one in `c15t.config.ts`
|
|
58
|
+
in the Next.js guide, add the helper to that array instead of creating a
|
|
59
|
+
second file.
|
|
49
60
|
The `scripts` export is a configuration, not an initializer. Add it to the c15t provider you already have, at the registration
|
|
50
61
|
point for your framework below. These are edits to that provider, not a second
|
|
51
62
|
provider.
|
|
52
63
|
|
|
53
64
|
**Next.js**
|
|
54
65
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
```ts
|
|
58
|
-
import { ConsentRoot } from 'c15t/next';
|
|
59
|
-
import { scripts } from './consent-scripts';
|
|
60
|
-
```
|
|
66
|
+
Add the configuration to `scripts` in `c15t.config.ts`, next to
|
|
67
|
+
`next.config.ts`:
|
|
61
68
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
69
|
+
```ts title="c15t.config.ts"
|
|
70
|
+
import { defineConsentConfig } from 'c15t/next';
|
|
71
|
+
import { scripts } from './src/consent-scripts';
|
|
65
72
|
|
|
66
|
-
|
|
67
|
-
<ConsentRoot state={state} config={consentConfig} scripts={scripts}>
|
|
68
|
-
{children}
|
|
69
|
-
</ConsentRoot>
|
|
73
|
+
export default defineConsentConfig({ scripts });
|
|
70
74
|
```
|
|
71
75
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
76
|
+
Keep the rest of your config, such as `mode` and `routePrefix`, in the
|
|
77
|
+
same call. `ConsentRoot` reads the config in the browser, so the layout
|
|
78
|
+
keeps passing only `state`. App Router, Pages Router and static export all
|
|
79
|
+
read the same file. See
|
|
75
80
|
[Next.js scripts and embeds](https://c15t.com/docs/frameworks/next/scripts).
|
|
76
81
|
|
|
77
82
|
**TanStack Start**
|
|
78
83
|
|
|
79
84
|
Import the configuration into your root route and pass it to the existing
|
|
80
|
-
`ConsentRoot` as a top-level prop. Keep the loader
|
|
81
|
-
|
|
85
|
+
`ConsentRoot` as a top-level prop. Keep the loader from the
|
|
86
|
+
[TanStack Start quickstart](https://c15t.com/docs/frameworks/tanstack-start/quickstart):
|
|
82
87
|
|
|
83
88
|
```tsx title="src/routes/__root.tsx"
|
|
84
89
|
import { scripts } from '../consent-scripts';
|
|
85
90
|
|
|
86
|
-
<ConsentRoot
|
|
87
|
-
state={consent}
|
|
88
|
-
backendURL={backendURL}
|
|
89
|
-
initRoute={false}
|
|
90
|
-
scripts={scripts}
|
|
91
|
-
>
|
|
91
|
+
<ConsentRoot state={consent} scripts={scripts}>
|
|
92
92
|
```
|
|
93
93
|
|
|
94
94
|
Import vendor helpers in the root route module, not in a server function.
|
|
@@ -107,8 +107,8 @@ import { scripts } from './consent-scripts';
|
|
|
107
107
|
<ConsentProvider options={{ mode, scripts }}>
|
|
108
108
|
```
|
|
109
109
|
|
|
110
|
-
`mode` is the `
|
|
111
|
-
|
|
110
|
+
`mode` is the `manifest()` value from the
|
|
111
|
+
[React quickstart](../frameworks/react/quickstart.md). Keep the banner,
|
|
112
112
|
dialog and preferences link inside the provider. See
|
|
113
113
|
[React scripts and embeds](../frameworks/react/scripts.md).
|
|
114
114
|
|
|
@@ -137,15 +137,16 @@ callbacks. Write the vendor IDs into `consent-scripts.ts`. See
|
|
|
137
137
|
Pass the scripts to the existing `c15tVue` plugin call in `src/main.ts`:
|
|
138
138
|
|
|
139
139
|
```ts title="src/main.ts"
|
|
140
|
+
import { c15tVue, manifest } from 'c15t/vue/vue-plugin';
|
|
140
141
|
import { scripts } from './consent-scripts';
|
|
141
142
|
|
|
142
143
|
app.use(c15tVue, {
|
|
143
|
-
|
|
144
|
+
mode: manifest(),
|
|
144
145
|
scripts,
|
|
145
146
|
});
|
|
146
147
|
```
|
|
147
148
|
|
|
148
|
-
Keep your existing
|
|
149
|
+
Keep your existing `mode` and other options. The plugin starts one
|
|
149
150
|
script loader when the app mounts, after it has applied the visitor's stored
|
|
150
151
|
choice. Do not also call `createScriptLoader` from a component. See
|
|
151
152
|
[Vue scripts and embeds](https://c15t.com/docs/frameworks/vue/scripts).
|
|
@@ -153,12 +154,11 @@ choice. Do not also call `createScriptLoader` from a component. See
|
|
|
153
154
|
**Astro**
|
|
154
155
|
|
|
155
156
|
Add the scripts to the client entrypoint from the
|
|
156
|
-
[Astro quickstart](https://c15t.com/docs/frameworks/astro/quickstart),
|
|
157
|
-
integration
|
|
158
|
-
|
|
159
|
-
already exports scripts, combine the two arrays.
|
|
157
|
+
[Astro quickstart](https://c15t.com/docs/frameworks/astro/quickstart), `src/c15t.client.ts`,
|
|
158
|
+
which the integration finds on its own. Keep `astro.config.mjs` as it is.
|
|
159
|
+
If the module already exports scripts, combine the two arrays.
|
|
160
160
|
|
|
161
|
-
```ts title="src/
|
|
161
|
+
```ts title="src/c15t.client.ts"
|
|
162
162
|
import type { C15tClientOptionsExtension } from 'c15t/astro';
|
|
163
163
|
import { scripts } from './consent-scripts';
|
|
164
164
|
|
|
@@ -178,15 +178,13 @@ pass them as a top-level prop:
|
|
|
178
178
|
|
|
179
179
|
```svelte title="src/App.svelte"
|
|
180
180
|
<script lang="ts">
|
|
181
|
-
import {
|
|
181
|
+
import { ConsentProvider, manifest } from '@c15t/svelte';
|
|
182
182
|
import { scripts } from './consent-scripts';
|
|
183
|
-
|
|
184
|
-
const mode = hosted({ url: 'https://your-project.inth.app' });
|
|
185
183
|
</script>
|
|
186
184
|
|
|
187
|
-
<
|
|
185
|
+
<ConsentProvider mode={manifest()} {scripts}>
|
|
188
186
|
<!-- Keep your application, consent UI and preferences link here. -->
|
|
189
|
-
</
|
|
187
|
+
</ConsentProvider>
|
|
190
188
|
```
|
|
191
189
|
|
|
192
190
|
Retain the styles and consent UI from the [Svelte quickstart](https://c15t.com/docs/frameworks/svelte/quickstart).
|
|
@@ -194,22 +192,21 @@ The provider owns the loader and disposes it on unmount.
|
|
|
194
192
|
|
|
195
193
|
**SvelteKit**
|
|
196
194
|
|
|
197
|
-
Add the scripts to the existing root layout
|
|
198
|
-
and
|
|
195
|
+
Add the scripts to the existing `ConsentRoot` in the root layout. Keep the
|
|
196
|
+
handle and the layout load from the [SvelteKit quickstart](https://c15t.com/docs/frameworks/sveltekit/quickstart).
|
|
199
197
|
|
|
200
198
|
```svelte title="src/routes/+layout.svelte"
|
|
201
199
|
<script lang="ts">
|
|
202
|
-
import {
|
|
200
|
+
import { ConsentRoot } from '@c15t/svelte';
|
|
203
201
|
import { scripts } from '../consent-scripts';
|
|
204
202
|
|
|
205
203
|
let { children, data } = $props();
|
|
206
|
-
const mode = hosted({ url: 'https://your-project.inth.app' });
|
|
207
204
|
</script>
|
|
208
205
|
|
|
209
|
-
<
|
|
206
|
+
<ConsentRoot state={data.consent} {scripts}>
|
|
210
207
|
{@render children()}
|
|
211
208
|
<!-- Keep your consent UI and preferences link here. -->
|
|
212
|
-
</
|
|
209
|
+
</ConsentRoot>
|
|
213
210
|
```
|
|
214
211
|
|
|
215
212
|
Import vendor helpers in the layout component, not in `+layout.server.ts`:
|
|
@@ -236,20 +233,19 @@ to a pasted snippet. See [HTML scripts](https://c15t.com/docs/frameworks/html/sc
|
|
|
236
233
|
|
|
237
234
|
**JavaScript**
|
|
238
235
|
|
|
239
|
-
Pass the scripts to `init()` from `@c15t/browser`, next to your
|
|
240
|
-
URL:
|
|
236
|
+
Pass the scripts to `init()` from `@c15t/browser`, next to your mode:
|
|
241
237
|
|
|
242
238
|
```ts
|
|
243
|
-
import { init } from '@c15t/browser';
|
|
239
|
+
import { init, manifest } from '@c15t/browser';
|
|
244
240
|
import { scripts } from './consent-scripts';
|
|
245
241
|
|
|
246
242
|
const consent = init({
|
|
247
|
-
|
|
243
|
+
mode: manifest(),
|
|
248
244
|
scripts,
|
|
249
245
|
});
|
|
250
246
|
```
|
|
251
247
|
|
|
252
|
-
Keep the
|
|
248
|
+
Keep the mode from your quickstart. With
|
|
253
249
|
`createConsentRuntime` from `c15t/runtime`, pass `scripts` to it instead.
|
|
254
250
|
A kernel you create yourself needs a loader from
|
|
255
251
|
`c15t/modules/script-loader`. Attach one loader per kernel. See
|
|
@@ -259,7 +255,7 @@ A kernel you create yourself needs a loader from
|
|
|
259
255
|
|
|
260
256
|
| Option | Default | Behavior |
|
|
261
257
|
| ----------------------- | ---------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
262
|
-
| `id` | Required | Project token, starting with `phc_`. The helper trims it. Empty or whitespace-only values
|
|
258
|
+
| `id` | Required | Project token, starting with `phc_`. The helper trims it. Empty or whitespace-only values log an error and the script does not load. |
|
|
263
259
|
| `region` | `'eu'` | `'eu'` or `'us'`. Picks the API, UI and loader hosts when you do not set them. |
|
|
264
260
|
| `apiHost` | `https://eu.i.posthog.com` | API host for a proxy or self-hosted PostHog. Without `scriptUrl`, the loader URL becomes `<apiHost>/static/array.js`. |
|
|
265
261
|
| `uiHost` | The region's UI host | UI host, for example `https://eu.posthog.com`. A custom `apiHost` with no `region` uses the API host. |
|
|
@@ -463,8 +459,8 @@ permission before each of your own event calls. The reload does not delete
|
|
|
463
459
|
cookies the vendor already set; see
|
|
464
460
|
[clear on revocation for your framework](./overview.md#vendor-switches-and-cookie-cleanup).
|
|
465
461
|
|
|
466
|
-
The helper
|
|
467
|
-
|
|
462
|
+
The helper lists its vendor by name in the preference dialog, so a visitor can
|
|
463
|
+
turn it off inside an allowed category. See
|
|
468
464
|
[vendor consent for your framework](./overview.md#vendor-switches-and-cookie-cleanup). The
|
|
469
465
|
[consent verification guide](../guides/verify-consent.md) covers navigation,
|
|
470
466
|
expiry and hosting checks.
|