@c15t/scripts 2.1.0 → 2.2.0-canary-20260804162155

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 (140) hide show
  1. package/AGENTS.md +62 -0
  2. package/README.md +32 -20
  3. package/dist/e2e-test-utils.cjs +51 -10
  4. package/dist/e2e-test-utils.js +37 -3
  5. package/dist/engine/compile.cjs +9 -5
  6. package/dist/engine/runtime.cjs +103 -17
  7. package/dist/engine/runtime.js +94 -12
  8. package/dist/registry.cjs +97 -12
  9. package/dist/registry.js +80 -0
  10. package/dist/resolve.cjs +9 -5
  11. package/dist/types.cjs +17 -13
  12. package/dist/vendors/_shared/attributes.cjs +13 -9
  13. package/dist/vendors/_shared/google-consent.cjs +14 -9
  14. package/dist/vendors/_shared/install-builders.cjs +12 -8
  15. package/dist/vendors/_shared/script-url.cjs +16 -12
  16. package/dist/vendors/ads-and-pixels/linkedin-insights.cjs +9 -5
  17. package/dist/vendors/ads-and-pixels/meta-pixel.cjs +13 -9
  18. package/dist/vendors/ads-and-pixels/microsoft-uet.cjs +11 -7
  19. package/dist/vendors/ads-and-pixels/reddit-pixel.cjs +9 -5
  20. package/dist/vendors/ads-and-pixels/snapchat-pixel.cjs +11 -7
  21. package/dist/vendors/ads-and-pixels/tiktok-pixel.cjs +9 -5
  22. package/dist/vendors/ads-and-pixels/x-pixel.cjs +9 -5
  23. package/dist/vendors/analytics/adobe-analytics.cjs +90 -0
  24. package/dist/vendors/analytics/adobe-analytics.js +49 -0
  25. package/dist/vendors/analytics/ahrefs-analytics.cjs +11 -7
  26. package/dist/vendors/analytics/amplitude.cjs +193 -0
  27. package/dist/vendors/analytics/amplitude.js +134 -0
  28. package/dist/vendors/analytics/clearbit.cjs +69 -0
  29. package/dist/vendors/analytics/clearbit.js +28 -0
  30. package/dist/vendors/analytics/cloudflare-web-analytics.cjs +11 -7
  31. package/dist/vendors/analytics/databuddy.cjs +11 -7
  32. package/dist/vendors/analytics/fathom-analytics.cjs +11 -7
  33. package/dist/vendors/analytics/google-tag.cjs +11 -7
  34. package/dist/vendors/analytics/heap.cjs +181 -0
  35. package/dist/vendors/analytics/heap.js +134 -0
  36. package/dist/vendors/analytics/hightouch.cjs +153 -0
  37. package/dist/vendors/analytics/hightouch.js +109 -0
  38. package/dist/vendors/analytics/hotjar.cjs +11 -7
  39. package/dist/vendors/analytics/logrocket.cjs +99 -0
  40. package/dist/vendors/analytics/logrocket.js +58 -0
  41. package/dist/vendors/analytics/matomo-analytics.cjs +9 -5
  42. package/dist/vendors/analytics/microsoft-clarity.cjs +75 -47
  43. package/dist/vendors/analytics/microsoft-clarity.js +64 -40
  44. package/dist/vendors/analytics/mixpanel-analytics.cjs +31 -16
  45. package/dist/vendors/analytics/mixpanel-analytics.js +22 -11
  46. package/dist/vendors/analytics/pirsch.cjs +108 -0
  47. package/dist/vendors/analytics/pirsch.js +67 -0
  48. package/dist/vendors/analytics/plausible-analytics.cjs +9 -5
  49. package/dist/vendors/analytics/posthog.cjs +63 -27
  50. package/dist/vendors/analytics/posthog.js +52 -20
  51. package/dist/vendors/analytics/promptwatch.cjs +11 -7
  52. package/dist/vendors/analytics/rudderstack.cjs +227 -0
  53. package/dist/vendors/analytics/rudderstack.js +183 -0
  54. package/dist/vendors/analytics/rybbit-analytics.cjs +9 -5
  55. package/dist/vendors/analytics/segment.cjs +9 -5
  56. package/dist/vendors/analytics/umami-analytics.cjs +9 -5
  57. package/dist/vendors/analytics/vercel-analytics.cjs +11 -7
  58. package/dist/vendors/functional/crisp.cjs +9 -5
  59. package/dist/vendors/functional/intercom.cjs +11 -7
  60. package/dist/vendors/tag-managers/google-tag-manager.cjs +11 -7
  61. package/dist-types/registry.d.ts +313 -241
  62. package/dist-types/types.d.ts +46 -4
  63. package/dist-types/vendors/ads-and-pixels/linkedin-insights.d.ts +18 -18
  64. package/dist-types/vendors/ads-and-pixels/meta-pixel.d.ts +21 -21
  65. package/dist-types/vendors/ads-and-pixels/microsoft-uet.d.ts +32 -32
  66. package/dist-types/vendors/ads-and-pixels/reddit-pixel.d.ts +19 -19
  67. package/dist-types/vendors/ads-and-pixels/snapchat-pixel.d.ts +16 -16
  68. package/dist-types/vendors/ads-and-pixels/tiktok-pixel.d.ts +28 -28
  69. package/dist-types/vendors/ads-and-pixels/x-pixel.d.ts +13 -13
  70. package/dist-types/vendors/analytics/adobe-analytics.d.ts +75 -0
  71. package/dist-types/vendors/analytics/ahrefs-analytics.d.ts +7 -7
  72. package/dist-types/vendors/analytics/amplitude.d.ts +234 -0
  73. package/dist-types/vendors/analytics/clearbit.d.ts +60 -0
  74. package/dist-types/vendors/analytics/cloudflare-web-analytics.d.ts +7 -7
  75. package/dist-types/vendors/analytics/databuddy.d.ts +25 -25
  76. package/dist-types/vendors/analytics/fathom-analytics.d.ts +11 -11
  77. package/dist-types/vendors/analytics/google-tag.d.ts +17 -17
  78. package/dist-types/vendors/analytics/heap.d.ts +316 -0
  79. package/dist-types/vendors/analytics/hightouch.d.ts +285 -0
  80. package/dist-types/vendors/analytics/hotjar.d.ts +14 -14
  81. package/dist-types/vendors/analytics/logrocket.d.ts +101 -0
  82. package/dist-types/vendors/analytics/microsoft-clarity.d.ts +42 -30
  83. package/dist-types/vendors/analytics/mixpanel-analytics.d.ts +40 -28
  84. package/dist-types/vendors/analytics/pirsch.d.ts +96 -0
  85. package/dist-types/vendors/analytics/plausible-analytics.d.ts +13 -13
  86. package/dist-types/vendors/analytics/posthog.d.ts +63 -45
  87. package/dist-types/vendors/analytics/promptwatch.d.ts +7 -7
  88. package/dist-types/vendors/analytics/rudderstack.d.ts +330 -0
  89. package/dist-types/vendors/analytics/rybbit-analytics.d.ts +18 -18
  90. package/dist-types/vendors/analytics/segment.d.ts +13 -13
  91. package/dist-types/vendors/analytics/umami-analytics.d.ts +12 -12
  92. package/dist-types/vendors/analytics/vercel-analytics.d.ts +16 -16
  93. package/dist-types/vendors/functional/crisp.d.ts +11 -11
  94. package/dist-types/vendors/functional/intercom.d.ts +16 -16
  95. package/dist-types/vendors/tag-managers/google-tag-manager.d.ts +18 -18
  96. package/docs/README.md +62 -0
  97. package/docs/frameworks/javascript/script-loader.md +356 -0
  98. package/docs/frameworks/next/script-loader.md +501 -0
  99. package/docs/frameworks/react/script-loader.md +555 -0
  100. package/docs/integrations/adobe-analytics.md +160 -0
  101. package/docs/integrations/ahrefs-analytics.md +157 -0
  102. package/docs/integrations/amplitude.md +230 -0
  103. package/docs/integrations/building-integrations.md +239 -0
  104. package/docs/integrations/clearbit.md +130 -0
  105. package/docs/integrations/cloudflare-web-analytics.md +126 -0
  106. package/docs/integrations/crisp.md +140 -0
  107. package/docs/integrations/databuddy.md +205 -0
  108. package/docs/integrations/fathom-analytics.md +150 -0
  109. package/docs/integrations/google-maps.md +263 -0
  110. package/docs/integrations/google-tag-manager.md +154 -0
  111. package/docs/integrations/google-tag.md +134 -0
  112. package/docs/integrations/heap.md +219 -0
  113. package/docs/integrations/hightouch.md +199 -0
  114. package/docs/integrations/hotjar.md +143 -0
  115. package/docs/integrations/intercom.md +144 -0
  116. package/docs/integrations/linkedin-insights.md +161 -0
  117. package/docs/integrations/logrocket.md +175 -0
  118. package/docs/integrations/matomo-analytics.md +171 -0
  119. package/docs/integrations/meta-pixel.md +412 -0
  120. package/docs/integrations/microsoft-clarity.md +173 -0
  121. package/docs/integrations/microsoft-uet.md +156 -0
  122. package/docs/integrations/mixpanel-analytics.md +130 -0
  123. package/docs/integrations/overview.md +149 -0
  124. package/docs/integrations/pirsch.md +142 -0
  125. package/docs/integrations/plausible-analytics.md +154 -0
  126. package/docs/integrations/posthog.md +258 -0
  127. package/docs/integrations/promptwatch.md +121 -0
  128. package/docs/integrations/reddit-pixel.md +241 -0
  129. package/docs/integrations/rudderstack.md +271 -0
  130. package/docs/integrations/rybbit-analytics.md +143 -0
  131. package/docs/integrations/segment.md +146 -0
  132. package/docs/integrations/snapchat-pixel.md +163 -0
  133. package/docs/integrations/tiktok-pixel.md +123 -0
  134. package/docs/integrations/umami-analytics.md +148 -0
  135. package/docs/integrations/vercel-analytics.md +141 -0
  136. package/docs/integrations/x-pixel.md +157 -0
  137. package/docs/integrations/youtube.md +193 -0
  138. package/docs/shared/react/guides/script-loader.md +311 -0
  139. package/package.json +61 -7
  140. package/readme.json +8 -4
@@ -0,0 +1,142 @@
1
+ ---
2
+ title: Pirsch
3
+ description: Privacy-friendly, cookieless analytics loaded with Pirsch's fixed
4
+ script id and identification-code attributes.
5
+ group: integrations
6
+ icon: pirsch
7
+ ---
8
+ [Pirsch](https://pirsch.io) provides privacy-friendly, cookieless web analytics. The official embed loads a single deferred script with an `id` of `pianjs` and your `data-code` identification code. c15t preserves that script id so the Pirsch loader can find its own element and read the configured attributes.
9
+
10
+ ## Integrate with c15t
11
+
12
+ **React**
13
+
14
+ ```tsx
15
+ import { type ReactNode } from 'react';
16
+ import { ConsentManagerProvider } from '@c15t/react';
17
+ import { pirsch } from '@c15t/scripts/pirsch';
18
+
19
+ const scripts = [
20
+ pirsch({
21
+ identificationCode: 'YOUR_IDENTIFICATION_CODE',
22
+ }),
23
+ ];
24
+
25
+ export function ConsentProvider({ children }: { children: ReactNode }) {
26
+ return (
27
+ <ConsentManagerProvider
28
+ options={{
29
+ mode: 'hosted',
30
+ backendURL: 'https://your-instance.c15t.dev',
31
+ scripts,
32
+ }}
33
+ >
34
+ {children}
35
+ </ConsentManagerProvider>
36
+ );
37
+ }
38
+ ```
39
+
40
+ **Next.js**
41
+
42
+ ```tsx
43
+ 'use client';
44
+
45
+ import { type ReactNode } from 'react';
46
+ import { ConsentManagerProvider } from '@c15t/nextjs';
47
+ import { pirsch } from '@c15t/scripts/pirsch';
48
+
49
+ const scripts = [
50
+ pirsch({
51
+ identificationCode: 'YOUR_IDENTIFICATION_CODE',
52
+ }),
53
+ ];
54
+
55
+ export function ConsentProvider({ children }: { children: ReactNode }) {
56
+ return (
57
+ <ConsentManagerProvider
58
+ options={{
59
+ mode: 'hosted',
60
+ backendURL: '/api/c15t',
61
+ scripts,
62
+ }}
63
+ >
64
+ {children}
65
+ </ConsentManagerProvider>
66
+ );
67
+ }
68
+ ```
69
+
70
+ **JavaScript**
71
+
72
+ ```ts
73
+ import { getOrCreateConsentRuntime } from 'c15t';
74
+ import { pirsch } from '@c15t/scripts/pirsch';
75
+
76
+ getOrCreateConsentRuntime({
77
+ mode: 'hosted',
78
+ backendURL: 'https://your-instance.c15t.dev',
79
+ scripts: [
80
+ pirsch({
81
+ identificationCode: 'YOUR_IDENTIFICATION_CODE',
82
+ }),
83
+ ],
84
+ });
85
+ ```
86
+
87
+ ## How c15t loads it
88
+
89
+ * **Category:** `measurement` (Analytics)
90
+ * **Loads when:** measurement consent is granted
91
+ * **On revocation:** unloaded — c15t removes the script element from the DOM. Pirsch is cookieless, so no client-side cookies need clearing.
92
+
93
+ The helper maps Pirsch's core script attributes:
94
+
95
+ ```ts
96
+ pirsch({
97
+ identificationCode: 'YOUR_IDENTIFICATION_CODE',
98
+ domain: 'rollup.example.com:ROLLUP_IDENTIFICATION_CODE',
99
+ dev: 'example.com',
100
+ hitEndpoint: 'https://analytics.example.com/hit',
101
+ eventEndpoint: 'https://analytics.example.com/event',
102
+ disablePageViews: true,
103
+ })
104
+ ```
105
+
106
+ Use the extended loader when you need Pirsch's extended script variant:
107
+
108
+ ```ts
109
+ pirsch({
110
+ identificationCode: 'YOUR_IDENTIFICATION_CODE',
111
+ extended: true,
112
+ })
113
+ ```
114
+
115
+ To proxy or self-host the loader, pass a custom URL:
116
+
117
+ ```ts
118
+ pirsch({
119
+ identificationCode: 'YOUR_IDENTIFICATION_CODE',
120
+ scriptUrl: 'https://analytics.example.com/pa.js',
121
+ })
122
+ ```
123
+
124
+ ## Types
125
+
126
+ ### PirschOptions
127
+
128
+ |Property|Value|
129
+ |:--|:--|
130
+ |Type Name|\`PirschOptions\`|
131
+ |Source Path|\`./packages/scripts/src/vendors/analytics/pirsch.ts\`|
132
+
133
+ \*ExtractedTypeTable: Could not extract "PirschOptions" from "./packages/scripts/src/vendors/analytics/pirsch.ts" using base path "/home/runner/work/c15t/c15t". Verify the path/name and that the file is included by your tsconfig.\*
134
+
135
+ ### Script
136
+
137
+ |Property|Value|
138
+ |:--|:--|
139
+ |Type Name|\`Script\`|
140
+ |Source Path|\`./packages/core/src/libs/script-loader/types.ts\`|
141
+
142
+ \*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.\*
@@ -0,0 +1,154 @@
1
+ ---
2
+ title: Plausible Analytics
3
+ description: Privacy-friendly cookieless analytics with a prebuilt helper that
4
+ preserves Plausible's queue bootstrap and loader attributes.
5
+ group: integrations
6
+ icon: plausible
7
+ ---
8
+ Plausible Analytics is a privacy-friendly, cookieless analytics product with a lightweight script loader. The `plausibleAnalytics()` helper models Plausible's queue bootstrap and script attributes as a c15t-managed script so early `window.plausible(...)` calls are buffered safely until the tracker loads.
9
+
10
+ ## Integrate with c15t
11
+
12
+ **React**
13
+
14
+ ```tsx
15
+ import { type ReactNode } from 'react';
16
+ import { ConsentManagerProvider } from '@c15t/react';
17
+ import { plausibleAnalytics } from '@c15t/scripts/plausible-analytics';
18
+
19
+ const scripts = [plausibleAnalytics({ domain: 'example.com' })];
20
+
21
+ export function ConsentProvider({ children }: { children: ReactNode }) {
22
+ return (
23
+ <ConsentManagerProvider
24
+ options={{
25
+ mode: 'hosted',
26
+ backendURL: 'https://your-instance.c15t.dev',
27
+ scripts,
28
+ }}
29
+ >
30
+ {children}
31
+ </ConsentManagerProvider>
32
+ );
33
+ }
34
+ ```
35
+
36
+ **Next.js**
37
+
38
+ ```tsx
39
+ 'use client';
40
+
41
+ import { type ReactNode } from 'react';
42
+ import { ConsentManagerProvider } from '@c15t/nextjs';
43
+ import { plausibleAnalytics } from '@c15t/scripts/plausible-analytics';
44
+
45
+ const scripts = [plausibleAnalytics({ domain: 'example.com' })];
46
+
47
+ export function ConsentProvider({ children }: { children: ReactNode }) {
48
+ return (
49
+ <ConsentManagerProvider
50
+ options={{
51
+ mode: 'hosted',
52
+ backendURL: '/api/c15t',
53
+ scripts,
54
+ }}
55
+ >
56
+ {children}
57
+ </ConsentManagerProvider>
58
+ );
59
+ }
60
+ ```
61
+
62
+ **JavaScript**
63
+
64
+ ```ts
65
+ import { getOrCreateConsentRuntime } from 'c15t';
66
+ import { plausibleAnalytics } from '@c15t/scripts/plausible-analytics';
67
+
68
+ getOrCreateConsentRuntime({
69
+ mode: 'hosted',
70
+ backendURL: 'https://your-instance.c15t.dev',
71
+ scripts: [plausibleAnalytics({ domain: 'example.com' })],
72
+ });
73
+ ```
74
+
75
+ ## How c15t loads it
76
+
77
+ * **Category:** `measurement` (Analytics)
78
+ * **Loads when:** measurement consent is granted
79
+ * **On revocation:** unloaded — c15t removes the script element from the DOM. Plausible is cookieless, so no client-side state needs clearing.
80
+
81
+ If you need script extensions or hash-based routing support, pass them through the helper:
82
+
83
+ ```ts
84
+ plausibleAnalytics({
85
+ domain: 'example.com',
86
+ extension: ['file-downloads', 'outbound-links'],
87
+ hashBasedRouting: true,
88
+ })
89
+ ```
90
+
91
+ The helper seeds a `window.plausible` queue stub during `onBeforeLoad`, so any calls made between the consent grant and the real script attaching get buffered into `plausible.q` and replayed. It also maps the legacy `data-domain` / `data-api` attributes and the new `scriptId`-based loader URL automatically.
92
+
93
+ ## Tracking events in your app
94
+
95
+ c15t gates the Plausible script from loading until `measurement` consent is granted. Your application code that calls Plausible is **not** automatically gated — `window.plausible` does not exist until the script is loaded, so unguarded calls before consent throw.
96
+
97
+ Guard event calls by checking consent state. From React:
98
+
99
+ ```tsx
100
+ import { useCallback } from 'react';
101
+ import { useConsentManager } from '@c15t/react';
102
+
103
+ function useTrackSignup() {
104
+ const { has } = useConsentManager();
105
+
106
+ return useCallback(() => {
107
+ if (has('measurement')) {
108
+ window.plausible?.('Signup');
109
+ }
110
+ }, [has]);
111
+ }
112
+
113
+ function SignupButton() {
114
+ const trackSignup = useTrackSignup();
115
+
116
+ return (
117
+ <button type="button" onClick={trackSignup}>
118
+ Sign up
119
+ </button>
120
+ );
121
+ }
122
+ ```
123
+
124
+ From plain JavaScript:
125
+
126
+ ```ts
127
+ import { getOrCreateConsentRuntime } from 'c15t';
128
+
129
+ const { consentStore } = getOrCreateConsentRuntime();
130
+
131
+ if (consentStore.getState().has('measurement')) {
132
+ window.plausible?.('Signup');
133
+ }
134
+ ```
135
+
136
+ ## Types
137
+
138
+ ### PlausibleAnalyticsOptions
139
+
140
+ |Property|Value|
141
+ |:--|:--|
142
+ |Type Name|\`PlausibleAnalyticsOptions\`|
143
+ |Source Path|\`./packages/scripts/src/vendors/analytics/plausible-analytics.ts\`|
144
+
145
+ \*ExtractedTypeTable: Could not extract "PlausibleAnalyticsOptions" from "./packages/scripts/src/vendors/analytics/plausible-analytics.ts" using base path "/home/runner/work/c15t/c15t". Verify the path/name and that the file is included by your tsconfig.\*
146
+
147
+ ### Script
148
+
149
+ |Property|Value|
150
+ |:--|:--|
151
+ |Type Name|\`Script\`|
152
+ |Source Path|\`./packages/core/src/libs/script-loader/types.ts\`|
153
+
154
+ \*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.\*
@@ -0,0 +1,258 @@
1
+ ---
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
8
+ group: integrations
9
+ ---
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
+
12
+ c15t exposes two integration patterns for PostHog. Pick the one that matches how you already load the SDK:
13
+
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`.
16
+
17
+ ## Integrate with c15t
18
+
19
+ ### SDK pattern
20
+
21
+ This is the recommended approach if you're using the PostHog JS SDK; it's commonly used in React projects.
22
+
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.
24
+
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.
26
+
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
+ })
33
+
34
+ posthog.opt_out_capturing() // Avoids cookie-based capture until c15t syncs consent
35
+ ```
36
+
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()`.
38
+
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.
40
+
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.
46
+
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
+ &#x20;posthog(\{
122
+ &#x20;id: 'phc\_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
123
+ &#x20;region: 'eu',
124
+ &#x20;loadMode: 'after-consent',
125
+ &#x20;}),
126
+ ];
127
+
128
+ export function ConsentProvider(\{ children }: \{ children: ReactNode }) \{
129
+ &#x20;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'`:
184
+
185
+ ```ts
186
+ import { posthog } from '@c15t/scripts/posthog';
187
+
188
+ const scripts = [
189
+ posthog({
190
+ id: 'phc_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
191
+ region: 'eu',
192
+ loadMode: 'after-consent',
193
+ }),
194
+ ];
195
+ ```
196
+
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.
198
+
199
+ For PostHog Cloud US, switch the region:
200
+
201
+ ```ts
202
+ posthog({
203
+ id: 'phc_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
204
+ region: 'us',
205
+ });
206
+ ```
207
+
208
+ ## How c15t loads it
209
+
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.
218
+
219
+ ## Tracking events in your app
220
+
221
+ The behavior depends on which pattern you chose:
222
+
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.
226
+
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.
229
+
230
+ ```ts
231
+ posthog.capture('signup');
232
+ ```
233
+
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.
235
+
236
+ ## Consent and privacy
237
+
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.
239
+
240
+ ## Types
241
+
242
+ ### PosthogConsentOptions
243
+
244
+ |Property|Value|
245
+ |:--|:--|
246
+ |Type Name|\`PosthogConsentOptions\`|
247
+ |Source Path|\`./packages/scripts/src/vendors/analytics/posthog.ts\`|
248
+
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.\*
250
+
251
+ ### Script
252
+
253
+ |Property|Value|
254
+ |:--|:--|
255
+ |Type Name|\`Script\`|
256
+ |Source Path|\`./packages/core/src/libs/script-loader/types.ts\`|
257
+
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.\*
@@ -0,0 +1,121 @@
1
+ ---
2
+ title: Promptwatch
3
+ description: Promptwatch analyzes traffic on your site for Artificial
4
+ Intelligence (AI) traffic and usage insights. Data is stored in the EU without
5
+ user-identifiable information.
6
+ group: integrations
7
+ icon: promptwatch
8
+ ---
9
+ [Promptwatch](https://promptwatch.com) provides analytics focused on AI-related traffic and usage. The official embed loads a single script with your `data-project-id`. By default, c15t loads this script when `measurement` consent is granted.
10
+
11
+ ## Integrate with c15t
12
+
13
+ **React**
14
+
15
+ ```tsx
16
+ import { type ReactNode } from 'react';
17
+ import { ConsentManagerProvider } from '@c15t/react';
18
+ import { promptwatch } from '@c15t/scripts/promptwatch';
19
+
20
+ const scripts = [
21
+ promptwatch({
22
+ projectId: '7d60345b-27bb-4779-a385-d4fc19ce732c',
23
+ }),
24
+ ];
25
+
26
+ export function ConsentProvider({ children }: { children: ReactNode }) {
27
+ return (
28
+ <ConsentManagerProvider
29
+ options={{
30
+ mode: 'hosted',
31
+ backendURL: 'https://your-instance.c15t.dev',
32
+ scripts,
33
+ }}
34
+ >
35
+ {children}
36
+ </ConsentManagerProvider>
37
+ );
38
+ }
39
+ ```
40
+
41
+ **Next.js**
42
+
43
+ ```tsx
44
+ 'use client';
45
+
46
+ import { type ReactNode } from 'react';
47
+ import { ConsentManagerProvider } from '@c15t/nextjs';
48
+ import { promptwatch } from '@c15t/scripts/promptwatch';
49
+
50
+ const scripts = [
51
+ promptwatch({
52
+ projectId: '7d60345b-27bb-4779-a385-d4fc19ce732c',
53
+ }),
54
+ ];
55
+
56
+ export function ConsentProvider({ children }: { children: ReactNode }) {
57
+ return (
58
+ <ConsentManagerProvider
59
+ options={{
60
+ mode: 'hosted',
61
+ backendURL: '/api/c15t',
62
+ scripts,
63
+ }}
64
+ >
65
+ {children}
66
+ </ConsentManagerProvider>
67
+ );
68
+ }
69
+ ```
70
+
71
+ **JavaScript**
72
+
73
+ ```ts
74
+ import { getOrCreateConsentRuntime } from 'c15t';
75
+ import { promptwatch } from '@c15t/scripts/promptwatch';
76
+
77
+ getOrCreateConsentRuntime({
78
+ mode: 'hosted',
79
+ backendURL: 'https://your-instance.c15t.dev',
80
+ scripts: [
81
+ promptwatch({
82
+ projectId: '7d60345b-27bb-4779-a385-d4fc19ce732c',
83
+ }),
84
+ ],
85
+ });
86
+ ```
87
+
88
+ ## How c15t loads it
89
+
90
+ * **Category:** `measurement` (Analytics)
91
+ * **Loads when:** measurement consent is granted
92
+ * **On revocation:** unloaded - c15t removes the script from the DOM and pauses Promptwatch data collection until consent is granted again.
93
+
94
+ To use a custom loader URL:
95
+
96
+ ```ts
97
+ promptwatch({
98
+ projectId: '7d60345b-27bb-4779-a385-d4fc19ce732c',
99
+ scriptUrl: 'https://cdn.example.com/promptwatch.js',
100
+ });
101
+ ```
102
+
103
+ ## Types
104
+
105
+ ### PromptwatchOptions
106
+
107
+ |Property|Value|
108
+ |:--|:--|
109
+ |Type Name|\`PromptwatchOptions\`|
110
+ |Source Path|\`./packages/scripts/src/vendors/analytics/promptwatch.ts\`|
111
+
112
+ \*ExtractedTypeTable: Could not extract "PromptwatchOptions" from "./packages/scripts/src/vendors/analytics/promptwatch.ts" using base path "/home/runner/work/c15t/c15t". Verify the path/name and that the file is included by your tsconfig.\*
113
+
114
+ ### Script
115
+
116
+ |Property|Value|
117
+ |:--|:--|
118
+ |Type Name|\`Script\`|
119
+ |Source Path|\`./packages/core/src/libs/script-loader/types.ts\`|
120
+
121
+ \*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.\*