c15t 2.0.4 → 2.1.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 (34) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/dist/index.cjs +2 -2
  3. package/dist/index.js +2 -2
  4. package/dist-types/index.d.ts +1 -1
  5. package/dist-types/version.d.ts +1 -1
  6. package/docs/integrations/ahrefs-analytics.md +224 -0
  7. package/docs/integrations/cloudflare-web-analytics.md +194 -0
  8. package/docs/integrations/crisp.md +214 -0
  9. package/docs/integrations/databuddy.md +136 -65
  10. package/docs/integrations/fathom-analytics.md +221 -0
  11. package/docs/integrations/google-tag-manager.md +84 -15
  12. package/docs/integrations/google-tag.md +89 -8
  13. package/docs/integrations/hotjar.md +211 -0
  14. package/docs/integrations/intercom.md +214 -0
  15. package/docs/integrations/linkedin-insights.md +130 -11
  16. package/docs/integrations/matomo-analytics.md +246 -0
  17. package/docs/integrations/meta-pixel.md +377 -24
  18. package/docs/integrations/microsoft-clarity.md +241 -0
  19. package/docs/integrations/microsoft-uet.md +120 -9
  20. package/docs/integrations/mixpanel-analytics.md +198 -0
  21. package/docs/integrations/overview.md +69 -74
  22. package/docs/integrations/plausible-analytics.md +237 -0
  23. package/docs/integrations/posthog.md +172 -41
  24. package/docs/integrations/promptwatch.md +187 -0
  25. package/docs/integrations/reddit-pixel.md +336 -0
  26. package/docs/integrations/rybbit-analytics.md +222 -0
  27. package/docs/integrations/segment.md +213 -0
  28. package/docs/integrations/snapchat-pixel.md +244 -0
  29. package/docs/integrations/tiktok-pixel.md +88 -10
  30. package/docs/integrations/umami-analytics.md +220 -0
  31. package/docs/integrations/vercel-analytics.md +213 -0
  32. package/docs/integrations/x-pixel.md +99 -10
  33. package/docs/script-loader.md +168 -51
  34. package/package.json +3 -3
@@ -0,0 +1,214 @@
1
+ ---
2
+ title: Crisp
3
+ description: Load Crisp live chat with website ID, runtime, cookie, and session options.
4
+ lastModified: 2026-05-11
5
+ icon: crisp
6
+ ---
7
+ Crisp adds the Crisp live chat widget and exposes the `$crisp` queue for
8
+ chatbox actions such as opening the chat, setting user details, and resetting
9
+ sessions.
10
+
11
+ ## Official Crisp documentation
12
+
13
+ * [Web Chat SDK](https://docs.crisp.chat/guides/chatbox-sdks/web-sdk/)
14
+ * [$crisp methods](https://docs.crisp.chat/guides/chatbox-sdks/web-sdk/dollar-crisp/)
15
+ * [Identity verification](https://docs.crisp.chat/guides/chatbox-sdks/web-sdk/identity-verification/)
16
+ * [Cookie policies](https://docs.crisp.chat/guides/chatbox-sdks/web-sdk/cookie-policies/)
17
+ * [Session continuity](https://docs.crisp.chat/guides/chatbox-sdks/web-sdk/session-continuity/)
18
+ * [Language customization](https://docs.crisp.chat/guides/chatbox-sdks/web-sdk/language-customization/)
19
+
20
+ ## Integrate with c15t
21
+
22
+ **React**
23
+
24
+ ```tsx
25
+ import { type ReactNode } from 'react';
26
+ import { ConsentManagerProvider } from '@c15t/react';
27
+ import { crisp } from '@c15t/scripts/crisp';
28
+
29
+ const scripts = [crisp({ websiteId: 'crisp-123' })];
30
+
31
+ export function ConsentProvider({ children }: { children: ReactNode }) {
32
+ return (
33
+ <ConsentManagerProvider
34
+ options={{
35
+ mode: 'hosted',
36
+ backendURL: 'https://your-instance.c15t.dev',
37
+ scripts,
38
+ }}
39
+ >
40
+ {children}
41
+ </ConsentManagerProvider>
42
+ );
43
+ }
44
+ ```
45
+
46
+ **Next.js**
47
+
48
+ ```tsx
49
+ 'use client';
50
+
51
+ import { type ReactNode } from 'react';
52
+ import { ConsentManagerProvider } from '@c15t/nextjs';
53
+ import { crisp } from '@c15t/scripts/crisp';
54
+
55
+ const scripts = [crisp({ websiteId: 'crisp-123' })];
56
+
57
+ export function ConsentProvider({ children }: { children: ReactNode }) {
58
+ return (
59
+ <ConsentManagerProvider
60
+ options={{
61
+ mode: 'hosted',
62
+ backendURL: '/api/c15t',
63
+ scripts,
64
+ }}
65
+ >
66
+ {children}
67
+ </ConsentManagerProvider>
68
+ );
69
+ }
70
+ ```
71
+
72
+ **JavaScript**
73
+
74
+ ```ts
75
+ import { getOrCreateConsentRuntime } from 'c15t';
76
+ import { crisp } from '@c15t/scripts/crisp';
77
+
78
+ getOrCreateConsentRuntime({
79
+ mode: 'hosted',
80
+ backendURL: 'https://your-instance.c15t.dev',
81
+ scripts: [crisp({ websiteId: 'crisp-123' })],
82
+ });
83
+ ```
84
+
85
+ ## How c15t loads it
86
+
87
+ * **Category:** `functionality` (Functional)
88
+ * **Loads when:** functionality consent is granted
89
+ * **Before load:** c15t seeds `window.$crisp`, `CRISP_WEBSITE_ID`, and any
90
+ optional Crisp runtime globals
91
+ * **On revocation:** c15t follows the default script loader behavior for
92
+ non-persistent scripts
93
+
94
+ ## Configure the integration
95
+
96
+ The helper seeds Crisp's documented globals before loading
97
+ `https://client.crisp.chat/l.js`.
98
+
99
+ ```ts
100
+ crisp({
101
+ websiteId: 'crisp-123',
102
+ locale: 'fr',
103
+ cookieDomain: 'app.example.com',
104
+ cookieExpiry: 3600,
105
+ tokenId: 'secure-user-token',
106
+ sessionMerge: true,
107
+ safeMode: true,
108
+ })
109
+ ```
110
+
111
+ `locale` and `sessionMerge` are written to `CRISP_RUNTIME_CONFIG`.
112
+ `cookieDomain` maps to `CRISP_COOKIE_DOMAIN`, `cookieExpiry` maps to
113
+ `CRISP_COOKIE_EXPIRE`, and `tokenId` maps to `CRISP_TOKEN_ID`. `safeMode`
114
+ queues `['safe', true]` on `window.$crisp` before the loader runs so Crisp
115
+ starts in safe mode.
116
+
117
+ For session continuity, generate `tokenId` on your backend with a secure random
118
+ value. Do not use emails, hashes of emails, timestamps, or incrementing IDs as
119
+ Crisp session tokens. If you verify user emails, generate the HMAC signature on
120
+ your backend and set it with Crisp's `$crisp` API after the helper loads.
121
+
122
+ ## Types
123
+
124
+ ### CrispOptions
125
+
126
+ |Property|Type|Description|Default|Required|
127
+ |:--|:--|:--|:--|:--:|
128
+ |websiteId|string|Your Crisp website ID.|-|✅ Required|
129
+ |locale|string \|undefined|Optional locale passed through \`window\.CRISP\_RUNTIME\_CONFIG\`.|-|Optional|
130
+ |cookieDomain|string \|undefined|Optional cookie domain override for Crisp.|-|Optional|
131
+ |cookieExpiry|number \|undefined|Optional cookie expiration in seconds.|-|Optional|
132
+ |tokenId|string \|undefined|Optional Crisp token ID for session continuity.|-|Optional|
133
+ |sessionMerge|boolean \|undefined|Whether to merge anonymous sessions into token-backed sessions.|-|Optional|
134
+ |safeMode|boolean \|undefined|Whether to enable \`$crisp\` safe mode before other queued calls.|-|Optional|
135
+ |scriptSrc|string \|undefined|Crisp loader URL.|-|Optional|
136
+
137
+ ### Script
138
+
139
+ |Property|Type|Description|Default|Required|
140
+ |:--|:--|:--|:--|:--:|
141
+ |id|string|Unique identifier for the script|-|✅ Required|
142
+ |src|string \|undefined|URL of the script to load|-|Optional|
143
+ |textContent|string \|undefined|Inline JavaScript code to execute|-|Optional|
144
+ |category|HasCondition\<AllConsentNames>|Consent category or condition required to load this script|-|✅ Required|
145
+ |callbackOnly|boolean \|undefined|Whether this is a callback-only script that doesn't need to load an external resource. When true, no script tag will be added to the DOM, only callbacks will be executed.|false|Optional|
146
+ |persistAfterConsentRevoked|boolean \|undefined|Whether the script should persist after consent is revoked.|false|Optional|
147
+ |alwaysLoad|boolean \|undefined|Whether the script should always load regardless of consent state. This is useful for scripts like Google Tag Manager or PostHog that manage their own consent state internally. The script will load immediately and never be unloaded based on consent changes. Note: When using this option, you are responsible for ensuring the script itself respects user consent preferences through its own consent management.|false|Optional|
148
+ |fetchPriority|"high" \|"low" \|"auto" \|undefined|Priority hint for browser resource loading|-|Optional|
149
+ |attributes|Record\<string, string> \|undefined|Additional attributes to add to the script element|-|Optional|
150
+ |async|boolean \|undefined|Whether to use async loading|-|Optional|
151
+ |defer|boolean \|undefined|Whether to defer script loading|-|Optional|
152
+ |nonce|string \|undefined|Content Security Policy nonce|-|Optional|
153
+ |anonymizeId|boolean \|undefined|Whether to use an anonymized ID for the script element, this helps ensure the script is not blocked by ad blockers|true|Optional|
154
+ |target|"head" \|"body" \|undefined|Where to inject the script element in the DOM. Options: \`'head'\`: Scripts are appended to \`\<head>\` (default); \`'body'\`: Scripts are appended to \`\<body>\`|'head'|Optional|
155
+ |onBeforeLoad|Object \|undefined|Callback executed before the script is loaded|-|Optional|
156
+ |onLoad|Object \|undefined|Callback executed when the script loads successfully|-|Optional|
157
+ |onError|Object \|undefined|Callback executed if the script fails to load|-|Optional|
158
+ |onConsentChange|Object \|undefined|Callback executed whenever the consent store is changed. This callback only applies to scripts already loaded.|-|Optional|
159
+ |vendorId|string \|number \|undefined|IAB TCF vendor ID - links script to a registered vendor. When in IAB mode, the script will only load if this vendor has consent. Takes precedence over \`category\` when in IAB mode. Use custom vendor IDs (string or number) to gate non-IAB vendors too.|-|Optional|
160
+ |iabPurposes|number\[] \|undefined|IAB TCF purpose IDs this script requires consent for. When in IAB mode and no vendorId is set, the script will only load if ALL specified purposes have consent.|-|Optional|
161
+ |iabLegIntPurposes|number\[] \|undefined|IAB TCF legitimate interest purpose IDs. These purposes can operate under legitimate interest instead of consent. The script loads if all iabPurposes have consent OR all iabLegIntPurposes have legitimate interest established.|-|Optional|
162
+ |iabSpecialFeatures|number\[] \|undefined|IAB TCF special feature IDs this script requires. Options: 1: Use precise geolocation data; 2: Actively scan device characteristics for identification|-|Optional|
163
+
164
+ #### `onBeforeLoad`
165
+
166
+ Callback executed before the script is loaded
167
+
168
+ |Property|Type|Description|Default|Required|
169
+ |:--|:--|:--|:--|:--:|
170
+ |id|string|The original script ID|-|✅ Required|
171
+ |elementId|string|The actual DOM element ID used (anonymized if enabled)|-|✅ Required|
172
+ |hasConsent|boolean|Has consent|-|✅ Required|
173
+ |consents|ConsentState|The current consent state|-|✅ Required|
174
+ |element|HTMLScriptElement \|undefined|The script element (for load/error callbacks) Will be undefined for callback-only scripts|-|Optional|
175
+ |error|Error \|undefined|Error information (for error callbacks)|-|Optional|
176
+
177
+ #### `onLoad`
178
+
179
+ Callback executed when the script loads successfully
180
+
181
+ |Property|Type|Description|Default|Required|
182
+ |:--|:--|:--|:--|:--:|
183
+ |id|string|The original script ID|-|✅ Required|
184
+ |elementId|string|The actual DOM element ID used (anonymized if enabled)|-|✅ Required|
185
+ |hasConsent|boolean|Has consent|-|✅ Required|
186
+ |consents|ConsentState|The current consent state|-|✅ Required|
187
+ |element|HTMLScriptElement \|undefined|The script element (for load/error callbacks) Will be undefined for callback-only scripts|-|Optional|
188
+ |error|Error \|undefined|Error information (for error callbacks)|-|Optional|
189
+
190
+ #### `onError`
191
+
192
+ Callback executed if the script fails to load
193
+
194
+ |Property|Type|Description|Default|Required|
195
+ |:--|:--|:--|:--|:--:|
196
+ |id|string|The original script ID|-|✅ Required|
197
+ |elementId|string|The actual DOM element ID used (anonymized if enabled)|-|✅ Required|
198
+ |hasConsent|boolean|Has consent|-|✅ Required|
199
+ |consents|ConsentState|The current consent state|-|✅ Required|
200
+ |element|HTMLScriptElement \|undefined|The script element (for load/error callbacks) Will be undefined for callback-only scripts|-|Optional|
201
+ |error|Error \|undefined|Error information (for error callbacks)|-|Optional|
202
+
203
+ #### `onConsentChange`
204
+
205
+ Callback executed whenever the consent store is changed. This callback only applies to scripts already loaded.
206
+
207
+ |Property|Type|Description|Default|Required|
208
+ |:--|:--|:--|:--|:--:|
209
+ |id|string|The original script ID|-|✅ Required|
210
+ |elementId|string|The actual DOM element ID used (anonymized if enabled)|-|✅ Required|
211
+ |hasConsent|boolean|Has consent|-|✅ Required|
212
+ |consents|ConsentState|The current consent state|-|✅ Required|
213
+ |element|HTMLScriptElement \|undefined|The script element (for load/error callbacks) Will be undefined for callback-only scripts|-|Optional|
214
+ |error|Error \|undefined|Error information (for error callbacks)|-|Optional|
@@ -2,79 +2,130 @@
2
2
  title: Databuddy
3
3
  description: Databuddy is a privacy-focused analytics platform that helps you understand user behavior and track events. It supports cookieless tracking and manages consent automatically through c15t's consent state synchronization.
4
4
  lastModified: 2025-10-31
5
-
6
5
  icon: databuddy
7
6
  ---
8
7
  The Databuddy script automatically respects consent preferences by toggling tracking on and off based on the user's consent state.
9
8
 
10
- ## Script Implementation
11
-
12
- 1. **Adding the Databuddy script to c15t**
13
-
14
- > ℹ️ Info:
15
- >
16
- > See the integration overview for how to pass scripts to your framework (JavaScript, React, or Next.js).
17
-
18
- ```ts
19
- import { databuddy } from '@c15t/scripts/databuddy';
20
-
21
- databuddy({
22
- clientId: 'your-client-id',
23
- scriptUrl: 'https://cdn.databuddy.cc/databuddy.js',
24
- apiUrl: 'https://basket.databuddy.cc',
25
- configWhenGranted: {
26
- clientId: 'your-client-id',
27
- apiUrl: 'https://basket.databuddy.cc',
28
- trackScreenViews: true,
29
- trackOutgoingLinks: true,
30
- disabled: false,
31
- },
32
- configWhenDenied: {
33
- clientId: 'your-client-id',
34
- apiUrl: 'https://basket.databuddy.cc',
35
- disabled: true,
36
- }
37
- })
38
- ```
39
-
40
- 2. **Using Databuddy in your application** Once initialized, Databuddy is available globally via window\.databuddy or window\.db:
41
-
42
- ```ts
43
- // Track a custom event
44
- window.databuddy?.trackCustomEvent('button_clicked', {
45
- button_id: 'signup',
46
- page: '/landing'
47
- });
48
-
49
- // Or use the shorthand
50
- window.db?.track('purchase_completed', {
51
- amount: 99.99,
52
- currency: 'USD'
53
- });
54
-
55
- // Track a screen view manually
56
- window.databuddy?.screenView('/dashboard', {
57
- user_role: 'admin'
58
- });
59
-
60
- // Set global properties for all events
61
- window.databuddy?.setGlobalProperties({
62
- app_version: '1.2.3',
63
- environment: 'production'
64
- });
65
- ```
66
-
67
- ## How Consent Management Works
9
+ ## Integrate with c15t
68
10
 
69
- The Databuddy integration automatically handles consent management:
11
+ **React**
70
12
 
71
- 1. **Before Script Load**: Sets `window.databuddyConfig.disabled` based on initial consent state
72
- 2. **On Consent Grant**: Enables tracking by setting `window.databuddy.options.disabled = false`
73
- 3. **On Consent Revoke**: Disables tracking by setting `window.databuddy.options.disabled = true`
13
+ ```tsx
14
+ import { type ReactNode } from 'react';
15
+ import { ConsentManagerProvider } from '@c15t/react';
16
+ import { databuddy } from '@c15t/scripts/databuddy';
74
17
 
75
- This ensures that no tracking occurs without user consent, keeping your analytics privacy-compliant.
18
+ const scripts = [
19
+ databuddy({
20
+ clientId: 'your-client-id',
21
+ scriptUrl: 'https://cdn.databuddy.cc/databuddy.js',
22
+ apiUrl: 'https://basket.databuddy.cc',
23
+ configWhenGranted: {
24
+ clientId: 'your-client-id',
25
+ apiUrl: 'https://basket.databuddy.cc',
26
+ disabled: false,
27
+ },
28
+ configWhenDenied: {
29
+ clientId: 'your-client-id',
30
+ apiUrl: 'https://basket.databuddy.cc',
31
+ disabled: true,
32
+ },
33
+ }),
34
+ ];
35
+
36
+ export function ConsentProvider({ children }: { children: ReactNode }) {
37
+ return (
38
+ <ConsentManagerProvider
39
+ options={{
40
+ mode: 'hosted',
41
+ backendURL: 'https://your-instance.c15t.dev',
42
+ scripts,
43
+ }}
44
+ >
45
+ {children}
46
+ </ConsentManagerProvider>
47
+ );
48
+ }
49
+ ```
50
+
51
+ **Next.js**
76
52
 
77
- ## Configuration Options
53
+ ```tsx
54
+ 'use client';
55
+
56
+ import { type ReactNode } from 'react';
57
+ import { ConsentManagerProvider } from '@c15t/nextjs';
58
+ import { databuddy } from '@c15t/scripts/databuddy';
59
+
60
+ const scripts = [
61
+ databuddy({
62
+ clientId: 'your-client-id',
63
+ scriptUrl: 'https://cdn.databuddy.cc/databuddy.js',
64
+ apiUrl: 'https://basket.databuddy.cc',
65
+ configWhenGranted: {
66
+ clientId: 'your-client-id',
67
+ apiUrl: 'https://basket.databuddy.cc',
68
+ disabled: false,
69
+ },
70
+ configWhenDenied: {
71
+ clientId: 'your-client-id',
72
+ apiUrl: 'https://basket.databuddy.cc',
73
+ disabled: true,
74
+ },
75
+ }),
76
+ ];
77
+
78
+ export function ConsentProvider({ children }: { children: ReactNode }) {
79
+ return (
80
+ <ConsentManagerProvider
81
+ options={{
82
+ mode: 'hosted',
83
+ backendURL: '/api/c15t',
84
+ scripts,
85
+ }}
86
+ >
87
+ {children}
88
+ </ConsentManagerProvider>
89
+ );
90
+ }
91
+ ```
92
+
93
+ **JavaScript**
94
+
95
+ ```ts
96
+ import { getOrCreateConsentRuntime } from 'c15t';
97
+ import { databuddy } from '@c15t/scripts/databuddy';
98
+
99
+ getOrCreateConsentRuntime({
100
+ mode: 'hosted',
101
+ backendURL: 'https://your-instance.c15t.dev',
102
+ scripts: [
103
+ databuddy({
104
+ clientId: 'your-client-id',
105
+ scriptUrl: 'https://cdn.databuddy.cc/databuddy.js',
106
+ apiUrl: 'https://basket.databuddy.cc',
107
+ configWhenGranted: {
108
+ clientId: 'your-client-id',
109
+ apiUrl: 'https://basket.databuddy.cc',
110
+ disabled: false,
111
+ },
112
+ configWhenDenied: {
113
+ clientId: 'your-client-id',
114
+ apiUrl: 'https://basket.databuddy.cc',
115
+ disabled: true,
116
+ },
117
+ }),
118
+ ],
119
+ });
120
+ ```
121
+
122
+ ## How c15t loads it
123
+
124
+ * **Category:** `measurement` (Analytics)
125
+ * **Loads when:** [`alwaysLoad`](/docs/frameworks/react/script-loader#always-load) — runs on page start regardless of consent state
126
+ * **On consent change:** c15t toggles `window.databuddy.options.disabled` so tracking turns on or off without removing the script
127
+
128
+ ## Configure the integration
78
129
 
79
130
  The Databuddy manifest expects explicit initial config objects for the granted
80
131
  and denied consent states:
@@ -111,6 +162,26 @@ databuddy({
111
162
  })
112
163
  ```
113
164
 
165
+ ## Tracking events in your app
166
+
167
+ Databuddy is `alwaysLoad: true`, so the script is in the DOM from page start regardless of consent. `window.databuddy` is therefore always defined and calls to `track`, `screenView`, or `setGlobalProperties` are safe to make at any time — when measurement consent is denied, c15t flips `window.databuddy.options.disabled = true` so the SDK becomes a no-op until consent is granted again.
168
+
169
+ ```ts
170
+ window.databuddy?.track('signup');
171
+ ```
172
+
173
+ You do not need to guard these calls with `useConsentManager().has('measurement')`, but doing so does no harm if you prefer the symmetry with other vendors.
174
+
175
+ ## Consent and privacy
176
+
177
+ The Databuddy integration automatically handles consent management:
178
+
179
+ 1. **Before Script Load**: Sets `window.databuddyConfig.disabled` based on initial consent state
180
+ 2. **On Consent Grant**: Enables tracking by setting `window.databuddy.options.disabled = false`
181
+ 3. **On Consent Revoke**: Disables tracking by setting `window.databuddy.options.disabled = true`
182
+
183
+ This ensures that no tracking occurs without user consent, keeping your analytics privacy-compliant.
184
+
114
185
  ## Types
115
186
 
116
187
  ### DatabuddyConsentOptions
@@ -0,0 +1,221 @@
1
+ ---
2
+ title: Fathom Analytics
3
+ description: Privacy-friendly cookieless analytics with a prebuilt helper that maps Fathom's data attributes into a c15t-managed script.
4
+ lastModified: 2026-05-10
5
+ icon: fathom-analytics
6
+ ---
7
+ Fathom Analytics is a lightweight, cookieless analytics product configured entirely through `data-*` attributes on its loader. The `fathomAnalytics()` helper serializes your site ID and tracking options into those attributes and hands the result to c15t's script loader.
8
+
9
+ ## Integrate with c15t
10
+
11
+ **React**
12
+
13
+ ```tsx
14
+ import { type ReactNode } from 'react';
15
+ import { ConsentManagerProvider } from '@c15t/react';
16
+ import { fathomAnalytics } from '@c15t/scripts/fathom-analytics';
17
+
18
+ const scripts = [fathomAnalytics({ site: 'SITE123' })];
19
+
20
+ export function ConsentProvider({ children }: { children: ReactNode }) {
21
+ return (
22
+ <ConsentManagerProvider
23
+ options={{
24
+ mode: 'hosted',
25
+ backendURL: 'https://your-instance.c15t.dev',
26
+ scripts,
27
+ }}
28
+ >
29
+ {children}
30
+ </ConsentManagerProvider>
31
+ );
32
+ }
33
+ ```
34
+
35
+ **Next.js**
36
+
37
+ ```tsx
38
+ 'use client';
39
+
40
+ import { type ReactNode } from 'react';
41
+ import { ConsentManagerProvider } from '@c15t/nextjs';
42
+ import { fathomAnalytics } from '@c15t/scripts/fathom-analytics';
43
+
44
+ const scripts = [fathomAnalytics({ site: 'SITE123' })];
45
+
46
+ export function ConsentProvider({ children }: { children: ReactNode }) {
47
+ return (
48
+ <ConsentManagerProvider
49
+ options={{
50
+ mode: 'hosted',
51
+ backendURL: '/api/c15t',
52
+ scripts,
53
+ }}
54
+ >
55
+ {children}
56
+ </ConsentManagerProvider>
57
+ );
58
+ }
59
+ ```
60
+
61
+ **JavaScript**
62
+
63
+ ```ts
64
+ import { getOrCreateConsentRuntime } from 'c15t';
65
+ import { fathomAnalytics } from '@c15t/scripts/fathom-analytics';
66
+
67
+ getOrCreateConsentRuntime({
68
+ mode: 'hosted',
69
+ backendURL: 'https://your-instance.c15t.dev',
70
+ scripts: [fathomAnalytics({ site: 'SITE123' })],
71
+ });
72
+ ```
73
+
74
+ ## How c15t loads it
75
+
76
+ * **Category:** `measurement` (Analytics)
77
+ * **Loads when:** measurement consent is granted
78
+ * **On revocation:** unloaded — c15t removes the script element from the DOM. Fathom is cookieless, so no client-side state needs clearing.
79
+
80
+ If you need to tune SPA tracking, canonical URL tracking, or Do Not Track handling:
81
+
82
+ ```ts
83
+ fathomAnalytics({
84
+ site: 'SITE123',
85
+ spa: 'history',
86
+ canonical: true,
87
+ honorDnt: true,
88
+ })
89
+ ```
90
+
91
+ Each option is mapped to Fathom's published `data-*` attribute (`data-site`, `data-spa`, `data-auto`, `data-canonical`, `data-honor-dnt`) and the script uses `defer` so it matches Fathom's recommended embed pattern.
92
+
93
+ ## Tracking events in your app
94
+
95
+ c15t gates the Fathom script from loading until `measurement` consent is granted. Your application code that calls Fathom's runtime API (`window.fathom.trackEvent`, `trackPageview`, `trackGoal`) is **not** automatically gated — `window.fathom` does not exist until the script is loaded, so unguarded calls before consent will throw errors.
96
+
97
+ Guard event calls by checking consent state. From React:
98
+
99
+ ```tsx
100
+ import { useConsentManager } from '@c15t/react';
101
+
102
+ function useTrackSignup() {
103
+ const { has } = useConsentManager();
104
+
105
+ return () => {
106
+ if (has('measurement')) {
107
+ window.fathom?.trackEvent('signup');
108
+ }
109
+ };
110
+ }
111
+
112
+ function SignupButton() {
113
+ const trackSignup = useTrackSignup();
114
+
115
+ return <button onClick={trackSignup}>Sign up</button>;
116
+ }
117
+ ```
118
+
119
+ From plain JavaScript:
120
+
121
+ ```ts
122
+ import { getOrCreateConsentRuntime } from 'c15t';
123
+
124
+ const { consentStore } = getOrCreateConsentRuntime();
125
+
126
+ if (consentStore.getState().has('measurement')) {
127
+ window.fathom?.trackEvent('signup');
128
+ }
129
+ ```
130
+
131
+ ## Types
132
+
133
+ ### FathomAnalyticsOptions
134
+
135
+ |Property|Type|Description|Default|Required|
136
+ |:--|:--|:--|:--|:--:|
137
+ |site|string|Your Fathom Analytics site ID.|-|✅ Required|
138
+ |spa|"auto" \|"history" \|"hash" \|undefined|The SPA tracking mode. When undefined, SPA auto-routing is disabled and the \`data-spa\` attribute is omitted.|-|Optional|
139
+ |auto|boolean \|undefined|Automatically track page views.|-|Optional|
140
+ |canonical|boolean \|undefined|Enable canonical URL tracking.|-|Optional|
141
+ |honorDnt|boolean \|undefined|Honor Do Not Track requests.|-|Optional|
142
+ |scriptUrl|string \|undefined|Custom loader URL.|'https\://cdn.usefathom.com/script.js'|Optional|
143
+
144
+ ### Script
145
+
146
+ |Property|Type|Description|Default|Required|
147
+ |:--|:--|:--|:--|:--:|
148
+ |id|string|Unique identifier for the script|-|✅ Required|
149
+ |src|string \|undefined|URL of the script to load|-|Optional|
150
+ |textContent|string \|undefined|Inline JavaScript code to execute|-|Optional|
151
+ |category|HasCondition\<AllConsentNames>|Consent category or condition required to load this script|-|✅ Required|
152
+ |callbackOnly|boolean \|undefined|Whether this is a callback-only script that doesn't need to load an external resource. When true, no script tag will be added to the DOM, only callbacks will be executed.|false|Optional|
153
+ |persistAfterConsentRevoked|boolean \|undefined|Whether the script should persist after consent is revoked.|false|Optional|
154
+ |alwaysLoad|boolean \|undefined|Whether the script should always load regardless of consent state. This is useful for scripts like Google Tag Manager or PostHog that manage their own consent state internally. The script will load immediately and never be unloaded based on consent changes. Note: When using this option, you are responsible for ensuring the script itself respects user consent preferences through its own consent management.|false|Optional|
155
+ |fetchPriority|"high" \|"low" \|"auto" \|undefined|Priority hint for browser resource loading|-|Optional|
156
+ |attributes|Record\<string, string> \|undefined|Additional attributes to add to the script element|-|Optional|
157
+ |async|boolean \|undefined|Whether to use async loading|-|Optional|
158
+ |defer|boolean \|undefined|Whether to defer script loading|-|Optional|
159
+ |nonce|string \|undefined|Content Security Policy nonce|-|Optional|
160
+ |anonymizeId|boolean \|undefined|Whether to use an anonymized ID for the script element, this helps ensure the script is not blocked by ad blockers|true|Optional|
161
+ |target|"head" \|"body" \|undefined|Where to inject the script element in the DOM. Options: \`'head'\`: Scripts are appended to \`\<head>\` (default); \`'body'\`: Scripts are appended to \`\<body>\`|'head'|Optional|
162
+ |onBeforeLoad|Object \|undefined|Callback executed before the script is loaded|-|Optional|
163
+ |onLoad|Object \|undefined|Callback executed when the script loads successfully|-|Optional|
164
+ |onError|Object \|undefined|Callback executed if the script fails to load|-|Optional|
165
+ |onConsentChange|Object \|undefined|Callback executed whenever the consent store is changed. This callback only applies to scripts already loaded.|-|Optional|
166
+ |vendorId|string \|number \|undefined|IAB TCF vendor ID - links script to a registered vendor. When in IAB mode, the script will only load if this vendor has consent. Takes precedence over \`category\` when in IAB mode. Use custom vendor IDs (string or number) to gate non-IAB vendors too.|-|Optional|
167
+ |iabPurposes|number\[] \|undefined|IAB TCF purpose IDs this script requires consent for. When in IAB mode and no vendorId is set, the script will only load if ALL specified purposes have consent.|-|Optional|
168
+ |iabLegIntPurposes|number\[] \|undefined|IAB TCF legitimate interest purpose IDs. These purposes can operate under legitimate interest instead of consent. The script loads if all iabPurposes have consent OR all iabLegIntPurposes have legitimate interest established.|-|Optional|
169
+ |iabSpecialFeatures|number\[] \|undefined|IAB TCF special feature IDs this script requires. Options: 1: Use precise geolocation data; 2: Actively scan device characteristics for identification|-|Optional|
170
+
171
+ #### `onBeforeLoad`
172
+
173
+ Callback executed before the script is loaded
174
+
175
+ |Property|Type|Description|Default|Required|
176
+ |:--|:--|:--|:--|:--:|
177
+ |id|string|The original script ID|-|✅ Required|
178
+ |elementId|string|The actual DOM element ID used (anonymized if enabled)|-|✅ Required|
179
+ |hasConsent|boolean|Has consent|-|✅ Required|
180
+ |consents|ConsentState|The current consent state|-|✅ Required|
181
+ |element|HTMLScriptElement \|undefined|The script element (for load/error callbacks) Will be undefined for callback-only scripts|-|Optional|
182
+ |error|Error \|undefined|Error information (for error callbacks)|-|Optional|
183
+
184
+ #### `onLoad`
185
+
186
+ Callback executed when the script loads successfully
187
+
188
+ |Property|Type|Description|Default|Required|
189
+ |:--|:--|:--|:--|:--:|
190
+ |id|string|The original script ID|-|✅ Required|
191
+ |elementId|string|The actual DOM element ID used (anonymized if enabled)|-|✅ Required|
192
+ |hasConsent|boolean|Has consent|-|✅ Required|
193
+ |consents|ConsentState|The current consent state|-|✅ Required|
194
+ |element|HTMLScriptElement \|undefined|The script element (for load/error callbacks) Will be undefined for callback-only scripts|-|Optional|
195
+ |error|Error \|undefined|Error information (for error callbacks)|-|Optional|
196
+
197
+ #### `onError`
198
+
199
+ Callback executed if the script fails to load
200
+
201
+ |Property|Type|Description|Default|Required|
202
+ |:--|:--|:--|:--|:--:|
203
+ |id|string|The original script ID|-|✅ Required|
204
+ |elementId|string|The actual DOM element ID used (anonymized if enabled)|-|✅ Required|
205
+ |hasConsent|boolean|Has consent|-|✅ Required|
206
+ |consents|ConsentState|The current consent state|-|✅ Required|
207
+ |element|HTMLScriptElement \|undefined|The script element (for load/error callbacks) Will be undefined for callback-only scripts|-|Optional|
208
+ |error|Error \|undefined|Error information (for error callbacks)|-|Optional|
209
+
210
+ #### `onConsentChange`
211
+
212
+ Callback executed whenever the consent store is changed. This callback only applies to scripts already loaded.
213
+
214
+ |Property|Type|Description|Default|Required|
215
+ |:--|:--|:--|:--|:--:|
216
+ |id|string|The original script ID|-|✅ Required|
217
+ |elementId|string|The actual DOM element ID used (anonymized if enabled)|-|✅ Required|
218
+ |hasConsent|boolean|Has consent|-|✅ Required|
219
+ |consents|ConsentState|The current consent state|-|✅ Required|
220
+ |element|HTMLScriptElement \|undefined|The script element (for load/error callbacks) Will be undefined for callback-only scripts|-|Optional|
221
+ |error|Error \|undefined|Error information (for error callbacks)|-|Optional|