@c15t/scripts 2.2.0 → 3.0.0-alpha.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.
Files changed (197) hide show
  1. package/AGENTS.md +74 -48
  2. package/README.md +3 -3
  3. package/dist/e2e-test-utils.js +60 -24
  4. package/dist/engine/compile.js +45 -45
  5. package/dist/engine/runtime.js +119 -119
  6. package/dist/registry.js +186 -176
  7. package/dist/resolve.js +12 -12
  8. package/dist/vendors/_shared/attributes.js +5 -5
  9. package/dist/vendors/_shared/google-consent.js +10 -10
  10. package/dist/vendors/_shared/install-builders.js +9 -9
  11. package/dist/vendors/_shared/script-url.js +12 -12
  12. package/dist/vendors/ads-and-pixels/linkedin-insights.js +16 -16
  13. package/dist/vendors/ads-and-pixels/meta-pixel.js +82 -82
  14. package/dist/vendors/ads-and-pixels/microsoft-uet.js +57 -57
  15. package/dist/vendors/ads-and-pixels/openai-pixel.js +88 -0
  16. package/dist/vendors/ads-and-pixels/reddit-pixel.js +39 -39
  17. package/dist/vendors/ads-and-pixels/snapchat-pixel.js +25 -25
  18. package/dist/vendors/ads-and-pixels/tiktok-pixel.js +31 -31
  19. package/dist/vendors/ads-and-pixels/x-pixel.js +17 -17
  20. package/dist/vendors/analytics/adobe-analytics.js +17 -17
  21. package/dist/vendors/analytics/ahrefs-analytics.js +8 -8
  22. package/dist/vendors/analytics/amplitude.js +39 -39
  23. package/dist/vendors/analytics/clearbit.js +11 -11
  24. package/dist/vendors/analytics/cloudflare-web-analytics.js +13 -13
  25. package/dist/vendors/analytics/databuddy.js +45 -45
  26. package/dist/vendors/analytics/fathom-analytics.js +15 -15
  27. package/dist/vendors/analytics/google-tag.js +23 -23
  28. package/dist/vendors/analytics/heap.js +37 -37
  29. package/dist/vendors/analytics/hightouch.js +30 -30
  30. package/dist/vendors/analytics/hotjar.js +14 -14
  31. package/dist/vendors/analytics/logrocket.js +24 -24
  32. package/dist/vendors/analytics/matomo-analytics.js +51 -51
  33. package/dist/vendors/analytics/microsoft-clarity.js +31 -31
  34. package/dist/vendors/analytics/mixpanel-analytics.js +31 -31
  35. package/dist/vendors/analytics/pirsch.js +27 -27
  36. package/dist/vendors/analytics/plausible-analytics.js +24 -24
  37. package/dist/vendors/analytics/posthog.js +84 -79
  38. package/dist/vendors/analytics/promptwatch.js +8 -8
  39. package/dist/vendors/analytics/rudderstack.js +50 -50
  40. package/dist/vendors/analytics/rybbit-analytics.js +30 -30
  41. package/dist/vendors/analytics/segment.js +16 -16
  42. package/dist/vendors/analytics/umami-analytics.js +16 -16
  43. package/dist/vendors/analytics/vercel-analytics.js +22 -22
  44. package/dist/vendors/functional/crisp.js +49 -51
  45. package/dist/vendors/functional/intercom.js +18 -18
  46. package/dist/vendors/tag-managers/google-tag-manager.js +20 -20
  47. package/dist-types/__tests__/helpers.d.ts +10 -10
  48. package/dist-types/engine/compile.d.ts +2 -2
  49. package/dist-types/engine/runtime.d.ts +3 -3
  50. package/dist-types/registry.d.ts +182 -173
  51. package/dist-types/resolve.d.ts +2 -2
  52. package/dist-types/types.d.ts +2 -2
  53. package/dist-types/vendors/_shared/attributes.d.ts +2 -2
  54. package/dist-types/vendors/_shared/google-consent.d.ts +2 -2
  55. package/dist-types/vendors/_shared/install-builders.d.ts +1 -1
  56. package/dist-types/vendors/_shared/script-url.d.ts +6 -6
  57. package/dist-types/vendors/ads-and-pixels/linkedin-insights.d.ts +14 -14
  58. package/dist-types/vendors/ads-and-pixels/meta-pixel.d.ts +27 -27
  59. package/dist-types/vendors/ads-and-pixels/microsoft-uet.d.ts +40 -40
  60. package/dist-types/vendors/ads-and-pixels/openai-pixel.d.ts +211 -0
  61. package/dist-types/vendors/ads-and-pixels/reddit-pixel.d.ts +28 -29
  62. package/dist-types/vendors/ads-and-pixels/snapchat-pixel.d.ts +23 -23
  63. package/dist-types/vendors/ads-and-pixels/tiktok-pixel.d.ts +22 -22
  64. package/dist-types/vendors/ads-and-pixels/x-pixel.d.ts +15 -15
  65. package/dist-types/vendors/analytics/adobe-analytics.d.ts +3 -3
  66. package/dist-types/vendors/analytics/ahrefs-analytics.d.ts +5 -5
  67. package/dist-types/vendors/analytics/amplitude.d.ts +24 -24
  68. package/dist-types/vendors/analytics/clearbit.d.ts +5 -5
  69. package/dist-types/vendors/analytics/cloudflare-web-analytics.d.ts +6 -6
  70. package/dist-types/vendors/analytics/databuddy.d.ts +34 -31
  71. package/dist-types/vendors/analytics/fathom-analytics.d.ts +8 -8
  72. package/dist-types/vendors/analytics/google-tag.d.ts +17 -17
  73. package/dist-types/vendors/analytics/heap.d.ts +17 -17
  74. package/dist-types/vendors/analytics/hightouch.d.ts +15 -15
  75. package/dist-types/vendors/analytics/hotjar.d.ts +9 -9
  76. package/dist-types/vendors/analytics/logrocket.d.ts +11 -11
  77. package/dist-types/vendors/analytics/matomo-analytics.d.ts +3 -3
  78. package/dist-types/vendors/analytics/microsoft-clarity.d.ts +12 -13
  79. package/dist-types/vendors/analytics/mixpanel-analytics.d.ts +20 -20
  80. package/dist-types/vendors/analytics/pirsch.d.ts +10 -10
  81. package/dist-types/vendors/analytics/plausible-analytics.d.ts +13 -13
  82. package/dist-types/vendors/analytics/posthog.d.ts +35 -32
  83. package/dist-types/vendors/analytics/promptwatch.d.ts +5 -5
  84. package/dist-types/vendors/analytics/rudderstack.d.ts +16 -16
  85. package/dist-types/vendors/analytics/rybbit-analytics.d.ts +15 -15
  86. package/dist-types/vendors/analytics/segment.d.ts +11 -11
  87. package/dist-types/vendors/analytics/umami-analytics.d.ts +9 -9
  88. package/dist-types/vendors/analytics/vercel-analytics.d.ts +13 -13
  89. package/dist-types/vendors/functional/crisp.d.ts +9 -9
  90. package/dist-types/vendors/functional/intercom.d.ts +12 -12
  91. package/dist-types/vendors/tag-managers/google-tag-manager.d.ts +16 -16
  92. package/docs/README.md +74 -48
  93. package/docs/assets/v3/brand-bar.png +0 -0
  94. package/docs/assets/v3/brand-card.png +0 -0
  95. package/docs/assets/v3/choice-wall.png +0 -0
  96. package/docs/assets/v3/mobile-card.png +0 -0
  97. package/docs/assets/v3/preferences.png +0 -0
  98. package/docs/customization/overview.md +45 -0
  99. package/docs/customization/recipes.md +79 -0
  100. package/docs/customization/slots.md +55 -0
  101. package/docs/customization/tokens.md +76 -0
  102. package/docs/customization/translations.md +49 -0
  103. package/docs/frameworks/javascript/script-loader.md +30 -339
  104. package/docs/frameworks/next/script-loader.md +134 -467
  105. package/docs/frameworks/react/script-loader.md +35 -535
  106. package/docs/guides/consent-state.md +60 -0
  107. package/docs/guides/data-fetching.md +163 -0
  108. package/docs/guides/deployment-modes.md +63 -0
  109. package/docs/guides/troubleshooting.md +68 -0
  110. package/docs/guides/verify-consent.md +62 -0
  111. package/docs/integrations/adobe-analytics.md +239 -105
  112. package/docs/integrations/ahrefs-analytics.md +238 -104
  113. package/docs/integrations/amplitude.md +219 -157
  114. package/docs/integrations/building-integrations.md +32 -224
  115. package/docs/integrations/clearbit.md +247 -86
  116. package/docs/integrations/cloudflare-web-analytics.md +250 -84
  117. package/docs/integrations/crisp.md +251 -97
  118. package/docs/integrations/databuddy.md +259 -153
  119. package/docs/integrations/fathom-analytics.md +239 -96
  120. package/docs/integrations/google-maps.md +328 -207
  121. package/docs/integrations/google-tag-manager.md +248 -96
  122. package/docs/integrations/google-tag.md +261 -90
  123. package/docs/integrations/heap.md +222 -149
  124. package/docs/integrations/hightouch.md +225 -131
  125. package/docs/integrations/hotjar.md +239 -90
  126. package/docs/integrations/intercom.md +239 -98
  127. package/docs/integrations/linkedin-insights.md +243 -113
  128. package/docs/integrations/logrocket.md +241 -123
  129. package/docs/integrations/matomo-analytics.md +256 -111
  130. package/docs/integrations/meta-pixel.md +197 -324
  131. package/docs/integrations/microsoft-clarity.md +233 -114
  132. package/docs/integrations/microsoft-uet.md +245 -110
  133. package/docs/integrations/mixpanel-analytics.md +252 -87
  134. package/docs/integrations/openai-pixel.md +441 -0
  135. package/docs/integrations/overview.md +95 -133
  136. package/docs/integrations/pirsch.md +249 -96
  137. package/docs/integrations/plausible-analytics.md +241 -100
  138. package/docs/integrations/posthog.md +353 -214
  139. package/docs/integrations/promptwatch.md +251 -81
  140. package/docs/integrations/reddit-pixel.md +226 -173
  141. package/docs/integrations/rudderstack.md +244 -187
  142. package/docs/integrations/rybbit-analytics.md +244 -91
  143. package/docs/integrations/segment.md +238 -92
  144. package/docs/integrations/snapchat-pixel.md +240 -110
  145. package/docs/integrations/tiktok-pixel.md +249 -81
  146. package/docs/integrations/umami-analytics.md +242 -95
  147. package/docs/integrations/vercel-analytics.md +242 -90
  148. package/docs/integrations/x-pixel.md +238 -104
  149. package/docs/integrations/youtube.md +354 -142
  150. package/docs/upgrade-v3.md +334 -0
  151. package/package.json +85 -78
  152. package/readme.json +2 -2
  153. package/dist/e2e-test-utils.cjs +0 -166
  154. package/dist/engine/compile.cjs +0 -130
  155. package/dist/engine/runtime.cjs +0 -475
  156. package/dist/registry.cjs +0 -423
  157. package/dist/resolve.cjs +0 -71
  158. package/dist/types.cjs +0 -69
  159. package/dist/vendors/_shared/attributes.cjs +0 -55
  160. package/dist/vendors/_shared/google-consent.cjs +0 -69
  161. package/dist/vendors/_shared/install-builders.cjs +0 -59
  162. package/dist/vendors/_shared/script-url.cjs +0 -78
  163. package/dist/vendors/ads-and-pixels/linkedin-insights.cjs +0 -89
  164. package/dist/vendors/ads-and-pixels/meta-pixel.cjs +0 -206
  165. package/dist/vendors/ads-and-pixels/microsoft-uet.cjs +0 -151
  166. package/dist/vendors/ads-and-pixels/reddit-pixel.cjs +0 -151
  167. package/dist/vendors/ads-and-pixels/snapchat-pixel.cjs +0 -131
  168. package/dist/vendors/ads-and-pixels/tiktok-pixel.cjs +0 -130
  169. package/dist/vendors/ads-and-pixels/x-pixel.cjs +0 -92
  170. package/dist/vendors/analytics/adobe-analytics.cjs +0 -90
  171. package/dist/vendors/analytics/ahrefs-analytics.cjs +0 -68
  172. package/dist/vendors/analytics/amplitude.cjs +0 -193
  173. package/dist/vendors/analytics/clearbit.cjs +0 -69
  174. package/dist/vendors/analytics/cloudflare-web-analytics.cjs +0 -73
  175. package/dist/vendors/analytics/databuddy.cjs +0 -144
  176. package/dist/vendors/analytics/fathom-analytics.cjs +0 -76
  177. package/dist/vendors/analytics/google-tag.cjs +0 -107
  178. package/dist/vendors/analytics/heap.cjs +0 -181
  179. package/dist/vendors/analytics/hightouch.cjs +0 -153
  180. package/dist/vendors/analytics/hotjar.cjs +0 -85
  181. package/dist/vendors/analytics/logrocket.cjs +0 -99
  182. package/dist/vendors/analytics/matomo-analytics.cjs +0 -232
  183. package/dist/vendors/analytics/microsoft-clarity.cjs +0 -138
  184. package/dist/vendors/analytics/mixpanel-analytics.cjs +0 -134
  185. package/dist/vendors/analytics/pirsch.cjs +0 -108
  186. package/dist/vendors/analytics/plausible-analytics.cjs +0 -122
  187. package/dist/vendors/analytics/posthog.cjs +0 -236
  188. package/dist/vendors/analytics/promptwatch.cjs +0 -70
  189. package/dist/vendors/analytics/rudderstack.cjs +0 -227
  190. package/dist/vendors/analytics/rybbit-analytics.cjs +0 -104
  191. package/dist/vendors/analytics/segment.cjs +0 -97
  192. package/dist/vendors/analytics/umami-analytics.cjs +0 -80
  193. package/dist/vendors/analytics/vercel-analytics.cjs +0 -94
  194. package/dist/vendors/functional/crisp.cjs +0 -143
  195. package/dist/vendors/functional/intercom.cjs +0 -89
  196. package/dist/vendors/tag-managers/google-tag-manager.cjs +0 -100
  197. package/docs/shared/react/guides/script-loader.md +0 -311
@@ -1,258 +1,397 @@
1
1
  ---
2
2
  title: PostHog
3
- description: PostHog is an open-source product analytics platform for tracking
4
- user behavior, session replays, feature flags, and A/B testing. It supports
5
- cookieless tracking, allowing analytics to continue even without cookie
6
- consent.
7
- icon: posthog
3
+ description: Choose PostHog loading and cookieless behavior, configure the
4
+ region, and synchronize v3 permissions.
8
5
  group: integrations
9
6
  ---
10
- PostHog is an open-source product analytics platform that helps you understand user behavior, track events, and analyze product usage. Unlike traditional analytics tools, PostHog supports both cookieless and cookie-based tracking. This means you can sync c15t with PostHog and, when your PostHog project is configured for cookieless tracking, continue collecting privacy-preserving analytics after a user rejects measurement consent.
11
7
 
12
- c15t exposes two integration patterns for PostHog. Pick the one that matches how you already load the SDK:
8
+ ## Configure PostHog
13
9
 
14
- * **PostHog SDK** your app loads `posthog-js` itself; c15t only synchronizes consent. Recommended for most React apps.
15
- * **PostHog Script** c15t loads PostHog's array bootstrap as a managed `Script`.
10
+ Use the browser project token beginning with `phc_`. Select the region matching
11
+ your PostHog project. This example waits for measurement permission before
12
+ requesting the SDK.
16
13
 
17
- ## Integrate with c15t
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` |
18
20
 
19
- ### SDK pattern
21
+ ```ts title="src/consent-scripts.ts"
22
+ import { posthog } from '@c15t/scripts/posthog';
20
23
 
21
- This is the recommended approach if you're using the PostHog JS SDK; it's commonly used in React projects.
24
+ export const scripts = [
25
+ posthog({
26
+ id: 'phc_YOUR_PROJECT_TOKEN',
27
+ region: 'eu',
28
+ loadMode: 'after-consent',
29
+ initOptions: { cookieless_mode: 'never' },
30
+ }),
31
+ ];
32
+ ```
22
33
 
23
- 1. **Enable cookieless tracking in PostHog** Before using `cookieless_mode`, enable **Cookieless server hash mode** in your PostHog project under **Project Settings** > **Web analytics**. PostHog ignores cookieless events unless this project setting is enabled.
34
+ The helper initializes PostHog. Remove a separate `posthog-js` initializer,
35
+ framework plugin or array snippet before using this setup.
24
36
 
25
- 2. **Initialize PostHog** When you initialize PostHog, set `cookieless_mode` to `on_reject`. This keeps PostHog from writing cookies or local/session storage until the user grants measurement consent. If the user rejects measurement consent, c15t calls `opt_out_capturing()` and PostHog switches to cookieless capture.
37
+ ## Register the scripts
26
38
 
27
- ```ts
28
- posthog.init("phc_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", {
29
- api_host: "https://eu.i.posthog.com",
30
- defaults: "2026-01-30",
31
- cookieless_mode: 'on_reject'
32
- })
39
+ Complete your [framework quickstart](https://c15t.com/docs/frameworks) first. Keep its Inth
40
+ endpoint, policy, styles and consent UI. Remove the vendor's original script,
41
+ SDK initializer or tag-manager entry so c15t owns loading once.
33
42
 
34
- posthog.opt_out_capturing() // Avoids cookie-based capture until c15t syncs consent
35
- ```
43
+ The `scripts` export in `src/consent-scripts.ts` is a configuration, not an
44
+ initializer. Add it to your existing consent owner using the registration point
45
+ below. These are partial edits to that owner, not additional providers.
36
46
 
37
- 3. **Sync settled consent once, then subscribe to real changes** The recommended PostHog SDK approach uses two phases: run one initial sync after c15t has finished resolving consent, then subscribe to future real preference changes with `subscribeToConsentChanges()`.
47
+ **Next.js**
38
48
 
39
- With cookieless\_mode: 'on\_reject', denied measurement consent does not mean "no events." It means PostHog records cookieless events without browser persistence. If your product needs denied consent to stop all PostHog event capture, do not use cookieless mode; load or call PostHog only after consent is granted.
49
+ Import the configuration into the client boundary from your router guide:
40
50
 
41
- > ⚠️ Warning:
42
- > Do not use posthog.has\_opted\_in\_capturing() or posthog.has\_opted\_out\_capturing() to decide whether to show your banner. In recent PostHog versions, has\_opted\_in\_capturing() can return true when consent is still pending. Use c15t's consent store as the source of truth, or use PostHog's get\_explicit\_consent\_status() when you specifically need PostHog's stored consent state.
43
- >
44
- > ℹ️ Info:
45
- > To wrap this in your framework, pass the callbacks option to your ConsentManagerProvider the same way you would pass scripts — see the JavaScript, React, or Next.js script loader guide.
51
+ ```ts
52
+ import { ConsentRoot } from 'c15t/next';
53
+ import { scripts } from './consent-scripts';
54
+ ```
46
55
 
47
- ```ts
48
- import { getOrCreateConsentRuntime } from 'c15t';
49
- import posthog from 'posthog-js';
50
-
51
- function syncPostHogMeasurementConsent(hasMeasurementConsent: boolean) {
52
- if (hasMeasurementConsent) {
53
- posthog.opt_in_capturing();
54
- } else {
55
- posthog.opt_out_capturing();
56
- }
57
- }
58
-
59
- const runtime = getOrCreateConsentRuntime({
60
- mode: 'hosted',
61
- callbacks: {
62
- onBannerFetched() {
63
- syncPostHogMeasurementConsent(
64
- runtime.consentStore.getState().has('measurement')
65
- );
66
- },
67
- },
68
- });
69
-
70
- runtime.consentStore
71
- .getState()
72
- .subscribeToConsentChanges(({ allowedCategories }) => {
73
- syncPostHogMeasurementConsent(
74
- allowedCategories.includes('measurement')
75
- );
76
- });
77
- ```
78
-
79
- > ℹ️ Info:
80
- > Avoid using onConsentSet plus manual deduplication for PostHog. subscribeToConsentChanges() already gives you the exact change-only semantics most analytics SDKs need.
81
-
82
- ### Script helper pattern
83
-
84
- If you want to load PostHog via a script tag, it's recommended to use this approach.
85
-
86
- 1. **Choose a region and loading mode** The c15t helper seeds PostHog's initialization queue, loads the bootstrap script, and synchronizes consent through `posthog.opt_in_capturing()` / `posthog.opt_out_capturing()`. You do not need to call `posthog.init()` separately.
87
-
88
- Use region to keep PostHog's API, UI, and bootstrap script hosts aligned. c15t defaults to region: 'eu'; set region: 'us' for PostHog Cloud US. You can still pass apiHost, uiHost, or scriptUrl for self-hosted or proxied setups.
89
-
90
- The helper supports three loading modes:
91
-
92
- * `loadMode: 'always'` — the backwards-compatible default. PostHog loads immediately and c15t synchronizes measurement consent through PostHog's APIs. Use this when you intentionally want PostHog cookieless behavior after rejection.
93
- * `loadMode: 'after-consent'` — PostHog is not requested until measurement consent is granted. This is the recommended GDPR/EU cookie-banner default when your policy requires no PostHog network activity before consent.
94
- * `loadMode: 'disabled'` — returns an inert callback-only script with no PostHog network request. Use this for environment flags or temporary rollouts.
95
-
96
- > ℹ️ Info:
97
- > For a privacy-first GDPR/EU cookie-banner setup, use region: 'eu' with loadMode: 'after-consent'. This keeps PostHog Cloud in the EU region and prevents any PostHog script request until measurement consent is granted.
98
-
99
- The helper includes these PostHog init defaults:
100
-
101
- ```ts
102
- const initOptions = {
103
- api_host: 'https://eu.i.posthog.com',
104
- ui_host: 'https://eu.posthog.com',
105
- defaults: '2026-01-30',
106
- cookieless_mode: 'on_reject',
107
- };
108
- ```
109
-
110
- You can still override any of these through initOptions. Keep cookieless\_mode: 'on\_reject' when you want PostHog to use cookieless capture after a consent rejection.
111
-
112
- 2. **Enable cookieless tracking in PostHog** Enable **Cookieless server hash mode** in your PostHog project under **Project Settings** > **Web analytics** when you use `loadMode: 'always'` and want rejected-consent traffic to be recorded cookielessly. This is required by PostHog before cookieless events are accepted.
113
-
114
- 3. **Add the script helper**
115
-
116
- import \{ type ReactNode } from 'react';
117
- import \{ ConsentManagerProvider } from '@c15t/react';
118
- import \{ posthog } from '@c15t/scripts/posthog';
119
-
120
- const scripts = \[
121
-  posthog(\{
122
-  id: 'phc\_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
123
-  region: 'eu',
124
-  loadMode: 'after-consent',
125
-  }),
126
- ];
127
-
128
- export function ConsentProvider(\{ children }: \{ children: ReactNode }) \{
129
-  return (
130
- &#x20;\<ConsentManagerProvider
131
- &#x20;options=\{\{
132
- &#x20;mode: 'hosted',
133
- &#x20;backendURL: 'https\://your-instance.c15t.dev',
134
- &#x20;scripts,
135
- &#x20;}}
136
- &#x20;\>
137
- &#x20;\{children}
138
- &#x20;\</ConsentManagerProvider>
139
- &#x20;);
140
- }'use client';
141
-
142
- import \{ type ReactNode } from 'react';
143
- import \{ ConsentManagerProvider } from '@c15t/nextjs';
144
- import \{ posthog } from '@c15t/scripts/posthog';
145
-
146
- const scripts = \[
147
- &#x20;posthog(\{
148
- &#x20;id: 'phc\_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
149
- &#x20;region: 'eu',
150
- &#x20;loadMode: 'after-consent',
151
- &#x20;}),
152
- ];
153
-
154
- export function ConsentProvider(\{ children }: \{ children: ReactNode }) \{
155
- &#x20;return (
156
- &#x20;\<ConsentManagerProvider
157
- &#x20;options=\{\{
158
- &#x20;mode: 'hosted',
159
- &#x20;backendURL: '/api/c15t',
160
- &#x20;scripts,
161
- &#x20;}}
162
- &#x20;\>
163
- &#x20;\{children}
164
- &#x20;\</ConsentManagerProvider>
165
- &#x20;);
166
- }import \{ getOrCreateConsentRuntime } from 'c15t';
167
- import \{ posthog } from '@c15t/scripts/posthog';
168
-
169
- getOrCreateConsentRuntime(\{
170
- &#x20;mode: 'hosted',
171
- &#x20;backendURL: 'https\://your-instance.c15t.dev',
172
- &#x20;scripts: \[
173
- &#x20;posthog(\{
174
- &#x20;id: 'phc\_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
175
- &#x20;region: 'eu',
176
- &#x20;loadMode: 'after-consent',
177
- &#x20;}),
178
- &#x20;],
179
- });
180
-
181
- ### No PostHog request before consent
182
-
183
- If your policy requires PostHog to be completely absent until the user grants measurement consent, use `loadMode: 'after-consent'`:
56
+ Keep the server-resolved `state` and shared `consentConfig` from your
57
+ router guide. Its manifest, init and save URLs stay in effect. Add
58
+ `scripts` as a top-level prop on the existing root:
184
59
 
185
- ```ts
186
- import { posthog } from '@c15t/scripts/posthog';
60
+ ```tsx
61
+ <ConsentRoot state={state} config={consentConfig} scripts={scripts}>
62
+ {children}
63
+ </ConsentRoot>
64
+ ```
187
65
 
188
- const scripts = [
189
- posthog({
190
- id: 'phc_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
191
- region: 'eu',
192
- loadMode: 'after-consent',
193
- }),
194
- ];
66
+ For a Pages Router or static-export setup using `ConsentProvider`, add
67
+ `scripts` to its existing `options` instead. Keep the router-specific setup
68
+ from [Next.js script loading](../frameworks/next/script-loader.md).
69
+
70
+ **TanStack Start**
71
+
72
+ In your existing root route component, import the scripts alongside
73
+ `ConsentRoot`. Keep the server loader from the [TanStack Start quickstart](https://c15t.com/docs/frameworks/tanstack-start/quickstart).
74
+
75
+ ```tsx
76
+ import { Outlet } from '@tanstack/react-router';
77
+ import { ConsentRoot } from 'c15t/tanstack-start';
78
+ import { scripts } from '../consent-scripts';
79
+
80
+ function Root() {
81
+ const state = Route.useLoaderData();
82
+ return (
83
+ <ConsentRoot state={state} backendURL={backendURL} initRoute={false} scripts={scripts}>
84
+ <Outlet />
85
+ {/* Keep your consent banner, dialog and preferences link here. */}
86
+ </ConsentRoot>
87
+ );
88
+ }
195
89
  ```
196
90
 
197
- With this mode, c15t does not inject the PostHog script until `measurement` consent is granted. PostHog cannot record cookieless rejected-consent events because the SDK has not loaded.
91
+ This edits the existing route. `Route` and `backendURL` come from its setup;
92
+ keep the document shell and head components if they are part of your root.
93
+ `initRoute={false}` keeps the quickstart's direct-backend initialization.
94
+ If your app mounts a consent server route, retain its existing `initRoute`
95
+ instead. Do not return script callbacks from a server function or route loader.
198
96
 
199
- For PostHog Cloud US, switch the region:
97
+ **React**
98
+
99
+ Import the scripts into your existing provider component:
200
100
 
201
101
  ```ts
202
- posthog({
203
- id: 'phc_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
204
- region: 'us',
102
+ import { ConsentProvider } from 'c15t/react';
103
+ import { scripts } from './consent-scripts';
104
+ ```
105
+
106
+ Keep the existing options and add `scripts`:
107
+
108
+ ```tsx
109
+ <ConsentProvider options={{ ...consentOptions, scripts }}>
110
+ {children}
111
+ </ConsentProvider>
112
+ ```
113
+
114
+ Here `consentOptions` is your existing configuration, including
115
+ `mode: hosted({ url: backendURL })`. Keep the banner, dialog and preferences
116
+ link inside the provider. See [React script loading](../frameworks/react/script-loader.md).
117
+
118
+ **Nuxt**
119
+
120
+ Attach one loader from the root `app.vue`, after the Nuxt module has
121
+ started its browser runtime. This keeps vendor callbacks in application code rather
122
+ than serialized `nuxt.config.ts` runtime configuration.
123
+
124
+ ```vue title="app/app.vue"
125
+ <script setup lang="ts">
126
+ import { onUnmounted } from 'vue';
127
+ import { createScriptLoader } from 'c15t/modules/script-loader';
128
+ import { scripts } from '../src/consent-scripts';
129
+
130
+ const nuxtApp = useNuxtApp();
131
+ const kernel = useConsentKernel();
132
+ let loader: ReturnType<typeof createScriptLoader> | undefined;
133
+
134
+ const removeMountedHook = nuxtApp.hook('app:mounted', () => {
135
+ loader = createScriptLoader({ kernel, scripts });
136
+ });
137
+ onUnmounted(() => {
138
+ removeMountedHook();
139
+ loader?.dispose();
140
+ });
141
+ </script>
142
+
143
+ <template>
144
+ <ConsentRoot />
145
+ <NuxtPage />
146
+ </template>
147
+ ```
148
+
149
+ Merge the setup code into your root and retain its footer and preferences
150
+ link. `useConsentKernel` is auto-imported by the c15t Nuxt module. Adjust the
151
+ relative script import if your `app.vue` is at the project root. This loader
152
+ waits until the module has applied browser persistence and privacy signals,
153
+ then reads the current snapshot and observes future changes. Do not also register these scripts
154
+ in another loader. See the [Nuxt quickstart](https://c15t.com/docs/frameworks/nuxt/quickstart).
155
+
156
+ **Vue**
157
+
158
+ Use the kernel already provided by the Vue plugin. Merge this setup into
159
+ `App.vue`, whose lifetime covers the application:
160
+
161
+ ```vue title="src/App.vue"
162
+ <script setup lang="ts">
163
+ import { onMounted, onUnmounted } from 'vue';
164
+ import { createScriptLoader } from 'c15t/modules/script-loader';
165
+ import { useConsentKernel } from 'c15t/vue/vue-plugin';
166
+ import ConsentRoot from 'c15t/vue/consent-root';
167
+ import { scripts } from './consent-scripts';
168
+
169
+ const kernel = useConsentKernel();
170
+ let loader: ReturnType<typeof createScriptLoader> | undefined;
171
+
172
+ onMounted(() => {
173
+ loader = createScriptLoader({ kernel, scripts });
205
174
  });
175
+ onUnmounted(() => loader?.dispose());
176
+ </script>
177
+
178
+ <template>
179
+ <ConsentRoot />
180
+ <main>Your application</main>
181
+ </template>
206
182
  ```
207
183
 
208
- ## How c15t loads it
184
+ Keep your existing page content and preferences link. The plugin still owns
185
+ the kernel and persistence; this component owns only the vendor loader.
186
+ Do not register the same scripts in plugin configuration as well. See the
187
+ [Vue quickstart](https://c15t.com/docs/frameworks/vue/quickstart).
209
188
 
210
- * **Category:** `measurement` (Analytics)
211
- * **SDK pattern:** your app loads `posthog-js`; c15t synchronizes
212
- measurement consent with PostHog opt-in and opt-out APIs.
213
- * **Script helper pattern:** by default, c15t loads PostHog on page start with
214
- [`alwaysLoad`](/docs/frameworks/react/script-loader#always-load), then
215
- switches PostHog between cookie-based and cookieless capture as consent
216
- changes. Set `loadMode: 'after-consent'` to block the script request until
217
- measurement consent is granted.
189
+ **Astro**
218
190
 
219
- ## Tracking events in your app
191
+ Point the existing Astro integration at a client module. Keep its `mode`,
192
+ `ui` and framework integration from the [Astro quickstart](https://c15t.com/docs/frameworks/astro/quickstart).
193
+ Import `fileURLToPath` in your Astro configuration:
220
194
 
221
- The behavior depends on which pattern you chose:
195
+ ```js title="astro.config.mjs"
196
+ import { fileURLToPath } from 'node:url';
197
+ ```
222
198
 
223
- * **SDK Implementation** your app loaded `posthog-js` itself, so `posthog.capture(...)` is available once your SDK setup has run. c15t calls `opt_in_capturing()` / `opt_out_capturing()` for you. Pending events before c15t syncs consent may be dropped; after denial, PostHog captures cookieless events.
224
- * **Script Implementation with `loadMode: 'always'`** — `window.posthog` is defined early as a queue. Calls to `posthog.capture(...)` before the bootstrap finishes are replayed after the SDK installs instead of being dropped. c15t queues the current consent decision ahead of those calls, then keeps calling `opt_in_capturing()` / `opt_out_capturing()` as consent changes. After denial, PostHog captures cookieless events when your PostHog project supports cookieless mode.
225
- * **Script Implementation with `loadMode: 'after-consent'`** — PostHog is unavailable until measurement consent is granted. Guard `posthog.capture(...)` calls or call them only after consent.
199
+ Add this option to the existing `c15t({ ... })` call. Resolve the path from
200
+ the configuration file because Astro injects the import into a virtual module:
226
201
 
227
- > ⚠️ **Warning:**
228
- > PostHog may start a new session when a user moves between cookieless and cookie-based capture. This can split pre-consent and post-consent activity into separate sessions, which may inflate session counts or affect funnels around the consent boundary. Treat this as a PostHog analytics limitation, not a c15t consent sync issue. See the upstream PostHog session continuity issue.
202
+ ```js
203
+ clientEntrypoint: fileURLToPath(new URL('./src/c15t.client.ts', import.meta.url)),
204
+ ```
229
205
 
230
- ```ts
231
- posthog.capture('signup');
206
+ Export the scripts from that module:
207
+
208
+ ```ts title="src/c15t.client.ts"
209
+ import type { C15tClientOptionsExtension } from '@c15t/astro';
210
+ import { scripts } from './consent-scripts';
211
+
212
+ export default { scripts } satisfies C15tClientOptionsExtension;
213
+ ```
214
+
215
+ The integration passes this extension to its shared browser runtime. Vendor
216
+ helpers contain callbacks, so do not put them in the serialized `scripts`
217
+ option in `astro.config.mjs`. Keep one runtime across consent islands and
218
+ `ClientRouter` navigation.
219
+
220
+ **Svelte**
221
+
222
+ Import the scripts in the component that owns your existing provider and
223
+ pass them as a top-level prop:
224
+
225
+ ```svelte title="src/App.svelte"
226
+ <script lang="ts">
227
+ import { ConsentManagerProvider, hosted } from '@c15t/svelte';
228
+ import { scripts } from './consent-scripts';
229
+
230
+ const backendURL = import.meta.env.VITE_C15T_BACKEND_URL;
231
+ if (!backendURL) throw new Error('Set VITE_C15T_BACKEND_URL');
232
+ const mode = hosted({ url: backendURL });
233
+ </script>
234
+
235
+ <ConsentManagerProvider {mode} {scripts}>
236
+ <!-- Keep your application, consent UI and preferences link here. -->
237
+ </ConsentManagerProvider>
232
238
  ```
233
239
 
234
- You do not need to guard these calls with `useConsentManager().has('measurement')` when cookieless measurement after rejection is acceptable. Add your own guard if denied consent should mean no PostHog event capture at all.
240
+ Retain the styles and consent UI from the [Svelte quickstart](https://c15t.com/docs/frameworks/svelte/quickstart).
241
+ The provider owns the loader and disposes it on unmount.
235
242
 
236
- ## Consent and privacy
243
+ **SvelteKit**
237
244
 
238
- PostHog's GDPR guidance recommends using PostHog Cloud EU for robust GDPR compliance, configuring consent clearly, and limiting what personal data is collected. Cookieless mode helps avoid browser persistence when measurement consent is rejected, but it does not replace your own legal basis, consent language, data minimization, IP capture settings, or right-to-be-forgotten process.
245
+ Add the scripts to the existing root layout provider. Keep the server load
246
+ and its serializable prefetch data from the [SvelteKit quickstart](https://c15t.com/docs/frameworks/sveltekit/quickstart).
239
247
 
240
- ## Types
248
+ ```svelte title="src/routes/+layout.svelte"
249
+ <script lang="ts">
250
+ import { ConsentManagerProvider, hosted } from '@c15t/svelte';
251
+ import { scripts } from '../consent-scripts';
241
252
 
242
- ### PosthogConsentOptions
253
+ let { children, data } = $props();
254
+ const mode = hosted({ url: data.backendURL });
255
+ </script>
256
+
257
+ <ConsentManagerProvider {mode} {scripts} prefetch={data.prefetch}>
258
+ {@render children()}
259
+ <!-- Keep your consent UI and preferences link here. -->
260
+ </ConsentManagerProvider>
261
+ ```
243
262
 
244
- |Property|Value|
245
- |:--|:--|
246
- |Type Name|\`PosthogConsentOptions\`|
247
- |Source Path|\`./packages/scripts/src/vendors/analytics/posthog.ts\`|
263
+ Import vendor helpers in the layout component, not in `+layout.server.ts`.
264
+ For static hosting, keep your browser-only `mode` setup and omit request
265
+ prefetch; the `scripts` prop stays the same. If you pass an externally owned
266
+ `runtime` to the provider, register scripts when creating that runtime instead.
248
267
 
249
- \*ExtractedTypeTable: Could not extract "PosthogConsentOptions" from "./packages/scripts/src/vendors/analytics/posthog.ts" using base path "/home/runner/work/c15t/c15t". Verify the path/name and that the file is included by your tsconfig.\*
268
+ **JavaScript**
250
269
 
251
- ### Script
270
+ Attach the loader to your existing kernel before calling
271
+ `kernel.commands.init()`:
252
272
 
253
- |Property|Value|
254
- |:--|:--|
255
- |Type Name|\`Script\`|
256
- |Source Path|\`./packages/core/src/libs/script-loader/types.ts\`|
273
+ ```ts
274
+ import { createScriptLoader } from 'c15t/modules/script-loader';
275
+ import { scripts } from './consent-scripts';
276
+
277
+ const loader = createScriptLoader({ kernel, scripts });
278
+ ```
279
+
280
+ Call `loader.dispose()` when that application instance is destroyed.
281
+ `kernel` is the hosted kernel from your quickstart. A provider-owned kernel
282
+ already has a loader; do not attach a second one. See
283
+ [JavaScript script loading](../frameworks/javascript/script-loader.md).
284
+
285
+ ## Choose loading and capture behavior separately
286
+
287
+ | `loadMode` | SDK loading | Consent handling |
288
+ | ------------------------------ | ------------------------------------- | --------------------------------------------------------------- |
289
+ | `'after-consent'` | Waits for measurement permission | Calls PostHog opt-in and opt-out APIs after load and on changes |
290
+ | `'always'`, the helper default | Loads even while permission is denied | Calls the same consent APIs |
291
+ | `'disabled'` | Does not load PostHog | Does not synchronize consent with an SDK loaded elsewhere |
292
+
293
+ The helper defaults `initOptions.cookieless_mode` to `'on_reject'`. In that
294
+ mode, PostHog can continue cookieless capture after denial. It requires the
295
+ project's cookieless server hash setting. See
296
+ [PostHog's cookieless guide](https://posthog.com/tutorials/cookieless-tracking).
297
+
298
+ The example overrides this with `'never'` so opting out is not a switch to
299
+ cookieless capture. Loading after consent only controls the initial request;
300
+ for later revocation, verify PostHog's opt-out behavior and stop application
301
+ capture calls too. SDK code that already executed cannot be undone by removing
302
+ its script element.
303
+
304
+ ## Configure hosts and initialization
305
+
306
+ | Option | Behavior |
307
+ | ------------------------------ | ---------------------------------------------------------------------------------------- |
308
+ | `id` | Browser project token. |
309
+ | `region` | `'eu'` by default; use `'us'` for a US project. |
310
+ | `apiHost / uiHost / scriptUrl` | Explicit overrides for proxy or self-hosted PostHog deployments. Keep all hosts aligned. |
311
+ | `loadMode` | Defaults to `'always'`; choose deliberately. |
312
+ | `initOptions` | Additional serializable SDK options, including the cookieless override. |
313
+
314
+ The helper applies the resolved API and UI hosts after `initOptions`; use the
315
+ top-level host fields to change them. A global `posthog` queue may exist before
316
+ the SDK is ready. Neither API presence nor SDK readiness is a consent grant.
317
+
318
+ ## Keep application events behind permission
319
+
320
+ With the script helper registered, a React client component can guard an event
321
+ using the current effective permission:
322
+
323
+ ```tsx title="src/signup-event.tsx"
324
+ 'use client';
325
+
326
+ import { useConsent } from 'c15t/react';
327
+
328
+ export function SignupEvent() {
329
+ const allowed = useConsent('measurement');
330
+
331
+ return (
332
+ <button
333
+ type="button"
334
+ onClick={() => {
335
+ if (allowed) window.posthog?.capture('signup_started');
336
+ }}
337
+ >
338
+ Start signup
339
+ </button>
340
+ );
341
+ }
342
+ ```
343
+
344
+ This is an event-call example, not a signup implementation. Next.js client
345
+ components can import `useConsent` from `c15t/next`.
346
+
347
+ ## Use an existing PostHog SDK
348
+
349
+ If your app already initializes `posthog-js`, keep that SDK owner and attach a
350
+ callback-only script instead of the loading helper. Initialize your SDK with
351
+ `opt_out_capturing_by_default: true` and `cookieless_mode: 'never'` before
352
+ mounting c15t when denied permission must stop capture.
353
+
354
+ ```ts title="src/posthog-consent.ts"
355
+ import type { Script, ScriptCallbackInfo } from 'c15t/modules/script-loader';
356
+
357
+ type PostHogConsentApi = {
358
+ opt_in_capturing: () => unknown;
359
+ opt_out_capturing: () => unknown;
360
+ };
361
+
362
+ export function posthogConsent(instance: PostHogConsentApi): Script {
363
+ const sync = ({ hasConsent }: ScriptCallbackInfo) => {
364
+ if (hasConsent) instance.opt_in_capturing();
365
+ else instance.opt_out_capturing();
366
+ };
367
+
368
+ return {
369
+ id: 'posthog-sdk-consent',
370
+ category: 'measurement',
371
+ callbackOnly: true,
372
+ alwaysLoad: true,
373
+ onBeforeLoad: sync,
374
+ onConsentChange: sync,
375
+ };
376
+ }
377
+ ```
257
378
 
258
- \*ExtractedTypeTable: Could not extract "Script" from "./packages/core/src/libs/script-loader/types.ts" using base path "/home/runner/work/c15t/c15t". Verify the path/name and that the file is included by your tsconfig.\*
379
+ Pass `posthogConsent(posthog)` in the existing provider's `scripts` array, using
380
+ your initialized SDK instance. The callback-only entry synchronizes initial
381
+ and changed effective permissions without loading a second SDK. It does not
382
+ block the SDK import or its initial request. `loadMode: 'disabled'` on the
383
+ loading helper is not a substitute, because it performs no synchronization.
384
+
385
+ Keep c15t as the source of truth for the banner and saved choices. Effective
386
+ permission can come from policy defaults; a synchronization callback is not
387
+ proof that the visitor explicitly accepted. Do not reuse v2
388
+ `getOrCreateConsentRuntime` or `onBannerFetched` examples with v3.
389
+
390
+ ## Verify the integration
391
+
392
+ With the example above, a fresh opt-in session should make no PostHog SDK
393
+ request until measurement is allowed. Grant, capture one test event, revoke,
394
+ and confirm later application calls stop. Repeat with persisted consent and
395
+ client navigation. If you choose cookieless capture, verify that behavior
396
+ explicitly in the project rather than expecting silence after denial. See
397
+ [consent verification](../guides/verify-consent.md).