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,220 @@
1
+ ---
2
+ title: Umami Analytics
3
+ description: Open-source, cookieless analytics with a prebuilt helper that maps Umami's data attributes into a c15t-managed script.
4
+ lastModified: 2026-05-10
5
+ icon: umami-analytics
6
+ ---
7
+ Umami is an open-source, cookieless analytics product configured entirely through `data-*` attributes on its loader. The `umamiAnalytics()` helper serializes your website ID, host override, 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 { umamiAnalytics } from '@c15t/scripts/umami-analytics';
17
+
18
+ const scripts = [umamiAnalytics({ websiteId: 'site-abc-123' })];
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 { umamiAnalytics } from '@c15t/scripts/umami-analytics';
43
+
44
+ const scripts = [umamiAnalytics({ websiteId: 'site-abc-123' })];
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 { umamiAnalytics } from '@c15t/scripts/umami-analytics';
66
+
67
+ getOrCreateConsentRuntime({
68
+ mode: 'hosted',
69
+ backendURL: 'https://your-instance.c15t.dev',
70
+ scripts: [umamiAnalytics({ websiteId: 'site-abc-123' })],
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. Umami is cookieless, so no client-side state needs clearing.
79
+
80
+ If you self-host Umami or need to restrict tracking to specific domains:
81
+
82
+ ```ts
83
+ umamiAnalytics({
84
+ websiteId: 'site-abc-123',
85
+ hostUrl: 'https://analytics.example.com',
86
+ domains: ['example.com', 'www.example.com'],
87
+ autoTrack: false,
88
+ tag: 'release-2025',
89
+ })
90
+ ```
91
+
92
+ Each option is mapped to Umami's published `data-*` attribute (`data-website-id`, `data-host-url`, `data-auto-track`, `data-domains`, `data-tag`, `data-before-send`) and the script uses `defer` so it matches Umami's recommended embed pattern.
93
+
94
+ > ℹ️ **Info:**
95
+ > beforeSend accepts a string referencing a global hook (e.g. 'window\.umamiBeforeSend'), not a function value. The c15t manifest runtime serializes script configuration, so inline callbacks cannot be passed through it.
96
+
97
+ ## Tracking events in your app
98
+
99
+ c15t gates the Umami script from loading until `measurement` consent is granted. Your application code that calls Umami's runtime API (`window.umami.track`, `window.umami.identify`) is **not** automatically gated — `window.umami` does not exist until the script is loaded, so unguarded calls before consent throw.
100
+
101
+ Guard event calls by checking consent state. From React:
102
+
103
+ ```tsx
104
+ import { useConsentManager } from '@c15t/react';
105
+
106
+ function useTrackSignup() {
107
+ const { has } = useConsentManager();
108
+
109
+ return () => {
110
+ if (has('measurement')) {
111
+ window.umami?.track('signup');
112
+ }
113
+ };
114
+ }
115
+ ```
116
+
117
+ From plain JavaScript:
118
+
119
+ ```ts
120
+ import { getOrCreateConsentRuntime } from 'c15t';
121
+
122
+ const { consentStore } = getOrCreateConsentRuntime();
123
+
124
+ if (consentStore.getState().has('measurement')) {
125
+ window.umami?.track('signup');
126
+ }
127
+ ```
128
+
129
+ ## Types
130
+
131
+ ### UmamiAnalyticsOptions
132
+
133
+ |Property|Type|Description|Default|Required|
134
+ |:--|:--|:--|:--|:--:|
135
+ |websiteId|string|Your Umami website ID.|-|✅ Required|
136
+ |hostUrl|string \|undefined|Override the host that receives analytics events.|-|Optional|
137
+ |autoTrack|boolean \|undefined|Disable automatic tracking when set to \`false\`.|-|Optional|
138
+ |domains|string \|string\[] \|undefined|Restrict tracking to specific domains.|-|Optional|
139
+ |tag|string \|undefined|Attach a tag to tracked events.|-|Optional|
140
+ |beforeSend|string \|undefined|Optional global hook name used for Umami's \`data-before-send\` attribute. Callback functions are intentionally not supported here because the c15t manifest runtime cannot serialize custom JavaScript functions.|-|Optional|
141
+ |scriptUrl|string \|undefined|Custom loader URL.|'https\://cloud.umami.is/script.js'|Optional|
142
+
143
+ ### Script
144
+
145
+ |Property|Type|Description|Default|Required|
146
+ |:--|:--|:--|:--|:--:|
147
+ |id|string|Unique identifier for the script|-|✅ Required|
148
+ |src|string \|undefined|URL of the script to load|-|Optional|
149
+ |textContent|string \|undefined|Inline JavaScript code to execute|-|Optional|
150
+ |category|HasCondition\<AllConsentNames>|Consent category or condition required to load this script|-|✅ Required|
151
+ |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|
152
+ |persistAfterConsentRevoked|boolean \|undefined|Whether the script should persist after consent is revoked.|false|Optional|
153
+ |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|
154
+ |fetchPriority|"high" \|"low" \|"auto" \|undefined|Priority hint for browser resource loading|-|Optional|
155
+ |attributes|Record\<string, string> \|undefined|Additional attributes to add to the script element|-|Optional|
156
+ |async|boolean \|undefined|Whether to use async loading|-|Optional|
157
+ |defer|boolean \|undefined|Whether to defer script loading|-|Optional|
158
+ |nonce|string \|undefined|Content Security Policy nonce|-|Optional|
159
+ |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|
160
+ |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|
161
+ |onBeforeLoad|Object \|undefined|Callback executed before the script is loaded|-|Optional|
162
+ |onLoad|Object \|undefined|Callback executed when the script loads successfully|-|Optional|
163
+ |onError|Object \|undefined|Callback executed if the script fails to load|-|Optional|
164
+ |onConsentChange|Object \|undefined|Callback executed whenever the consent store is changed. This callback only applies to scripts already loaded.|-|Optional|
165
+ |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|
166
+ |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|
167
+ |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|
168
+ |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|
169
+
170
+ #### `onBeforeLoad`
171
+
172
+ Callback executed before the script is loaded
173
+
174
+ |Property|Type|Description|Default|Required|
175
+ |:--|:--|:--|:--|:--:|
176
+ |id|string|The original script ID|-|✅ Required|
177
+ |elementId|string|The actual DOM element ID used (anonymized if enabled)|-|✅ Required|
178
+ |hasConsent|boolean|Has consent|-|✅ Required|
179
+ |consents|ConsentState|The current consent state|-|✅ Required|
180
+ |element|HTMLScriptElement \|undefined|The script element (for load/error callbacks) Will be undefined for callback-only scripts|-|Optional|
181
+ |error|Error \|undefined|Error information (for error callbacks)|-|Optional|
182
+
183
+ #### `onLoad`
184
+
185
+ Callback executed when the script loads successfully
186
+
187
+ |Property|Type|Description|Default|Required|
188
+ |:--|:--|:--|:--|:--:|
189
+ |id|string|The original script ID|-|✅ Required|
190
+ |elementId|string|The actual DOM element ID used (anonymized if enabled)|-|✅ Required|
191
+ |hasConsent|boolean|Has consent|-|✅ Required|
192
+ |consents|ConsentState|The current consent state|-|✅ Required|
193
+ |element|HTMLScriptElement \|undefined|The script element (for load/error callbacks) Will be undefined for callback-only scripts|-|Optional|
194
+ |error|Error \|undefined|Error information (for error callbacks)|-|Optional|
195
+
196
+ #### `onError`
197
+
198
+ Callback executed if the script fails to load
199
+
200
+ |Property|Type|Description|Default|Required|
201
+ |:--|:--|:--|:--|:--:|
202
+ |id|string|The original script ID|-|✅ Required|
203
+ |elementId|string|The actual DOM element ID used (anonymized if enabled)|-|✅ Required|
204
+ |hasConsent|boolean|Has consent|-|✅ Required|
205
+ |consents|ConsentState|The current consent state|-|✅ Required|
206
+ |element|HTMLScriptElement \|undefined|The script element (for load/error callbacks) Will be undefined for callback-only scripts|-|Optional|
207
+ |error|Error \|undefined|Error information (for error callbacks)|-|Optional|
208
+
209
+ #### `onConsentChange`
210
+
211
+ Callback executed whenever the consent store is changed. This callback only applies to scripts already loaded.
212
+
213
+ |Property|Type|Description|Default|Required|
214
+ |:--|:--|:--|:--|:--:|
215
+ |id|string|The original script ID|-|✅ Required|
216
+ |elementId|string|The actual DOM element ID used (anonymized if enabled)|-|✅ Required|
217
+ |hasConsent|boolean|Has consent|-|✅ Required|
218
+ |consents|ConsentState|The current consent state|-|✅ Required|
219
+ |element|HTMLScriptElement \|undefined|The script element (for load/error callbacks) Will be undefined for callback-only scripts|-|Optional|
220
+ |error|Error \|undefined|Error information (for error callbacks)|-|Optional|
@@ -0,0 +1,213 @@
1
+ ---
2
+ title: Vercel Analytics
3
+ description: Bootstrap Vercel Analytics with a declarative queue and script attributes.
4
+ lastModified: 2026-05-10
5
+ icon: vercel-analytics
6
+ ---
7
+ Vercel Analytics loads through `@c15t/scripts` using a declarative queue bootstrap (`vaq` + `va`) and script attributes for DSN/endpoint options.
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 { vercelAnalytics } from '@c15t/scripts/vercel-analytics';
17
+
18
+ const scripts = [vercelAnalytics()];
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 { vercelAnalytics } from '@c15t/scripts/vercel-analytics';
43
+
44
+ const scripts = [vercelAnalytics()];
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 { vercelAnalytics } from '@c15t/scripts/vercel-analytics';
66
+
67
+ getOrCreateConsentRuntime({
68
+ mode: 'hosted',
69
+ backendURL: 'https://your-instance.c15t.dev',
70
+ scripts: [vercelAnalytics()],
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 from the DOM and clears access to runtime globals until consent is granted again.
79
+
80
+ Load the debug bundle or a custom endpoint when needed:
81
+
82
+ ```ts
83
+ vercelAnalytics({
84
+ mode: 'development',
85
+ disableAutoTrack: true,
86
+ endpoint: 'https://analytics.example.com/v1/events',
87
+ })
88
+ ```
89
+
90
+ ## Tracking events in your app
91
+
92
+ c15t initializes a bootstrap phase first (`vaq` plus a local `window.va` stub), then loads the remote Vercel Analytics script after `measurement` consent is granted. Calls are safe once the bootstrap stub exists (they are queued/ignored in `vaq`), but they execute only after consent is granted and the real `window.va` is injected and flushes the queue.
93
+
94
+ Guard event calls by checking consent state. From React:
95
+
96
+ ```tsx
97
+ import { useCallback } from 'react';
98
+ import { useConsentManager } from '@c15t/react';
99
+
100
+ function SignupExample() {
101
+ const { has } = useConsentManager();
102
+
103
+ const trackSignup = useCallback(() => {
104
+ if (has('measurement')) {
105
+ window.va?.('signup', { plan: 'pro' });
106
+ }
107
+ }, [has]);
108
+ }
109
+ ```
110
+
111
+ From plain JavaScript:
112
+
113
+ ```ts
114
+ import { getOrCreateConsentRuntime } from 'c15t';
115
+
116
+ const { consentStore } = getOrCreateConsentRuntime();
117
+
118
+ if (consentStore.getState().has('measurement')) {
119
+ window.va?.('signup', { plan: 'pro' });
120
+ }
121
+ ```
122
+
123
+ ## Types
124
+
125
+ ### VercelAnalyticsOptions
126
+
127
+ |Property|Type|Description|Default|Required|
128
+ |:--|:--|:--|:--|:--:|
129
+ |dsn|string \|undefined|Project DSN for self-hosted or non-Vercel deployments.|-|Optional|
130
+ |disableAutoTrack|boolean \|undefined|Disable automatic pageview tracking.|-|Optional|
131
+ |mode|VercelAnalyticsMode \|undefined|Preferred script mode.|-|Optional|
132
+ |debug|boolean \|undefined|Load Vercel's debug bundle when set to \`true\`.|-|Optional|
133
+ |endpoint|string \|undefined|Custom ingestion endpoint.|-|Optional|
134
+ |scriptUrl|string \|undefined|Custom loader URL.|-|Optional|
135
+
136
+ ### Script
137
+
138
+ |Property|Type|Description|Default|Required|
139
+ |:--|:--|:--|:--|:--:|
140
+ |id|string|Unique identifier for the script|-|✅ Required|
141
+ |src|string \|undefined|URL of the script to load|-|Optional|
142
+ |textContent|string \|undefined|Inline JavaScript code to execute|-|Optional|
143
+ |category|HasCondition\<AllConsentNames>|Consent category or condition required to load this script|-|✅ Required|
144
+ |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|
145
+ |persistAfterConsentRevoked|boolean \|undefined|Whether the script should persist after consent is revoked.|false|Optional|
146
+ |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|
147
+ |fetchPriority|"high" \|"low" \|"auto" \|undefined|Priority hint for browser resource loading|-|Optional|
148
+ |attributes|Record\<string, string> \|undefined|Additional attributes to add to the script element|-|Optional|
149
+ |async|boolean \|undefined|Whether to use async loading|-|Optional|
150
+ |defer|boolean \|undefined|Whether to defer script loading|-|Optional|
151
+ |nonce|string \|undefined|Content Security Policy nonce|-|Optional|
152
+ |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|
153
+ |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|
154
+ |onBeforeLoad|Object \|undefined|Callback executed before the script is loaded|-|Optional|
155
+ |onLoad|Object \|undefined|Callback executed when the script loads successfully|-|Optional|
156
+ |onError|Object \|undefined|Callback executed if the script fails to load|-|Optional|
157
+ |onConsentChange|Object \|undefined|Callback executed whenever the consent store is changed. This callback only applies to scripts already loaded.|-|Optional|
158
+ |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|
159
+ |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|
160
+ |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|
161
+ |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|
162
+
163
+ #### `onBeforeLoad`
164
+
165
+ Callback executed before the script is loaded
166
+
167
+ |Property|Type|Description|Default|Required|
168
+ |:--|:--|:--|:--|:--:|
169
+ |id|string|The original script ID|-|✅ Required|
170
+ |elementId|string|The actual DOM element ID used (anonymized if enabled)|-|✅ Required|
171
+ |hasConsent|boolean|Has consent|-|✅ Required|
172
+ |consents|ConsentState|The current consent state|-|✅ Required|
173
+ |element|HTMLScriptElement \|undefined|The script element (for load/error callbacks) Will be undefined for callback-only scripts|-|Optional|
174
+ |error|Error \|undefined|Error information (for error callbacks)|-|Optional|
175
+
176
+ #### `onLoad`
177
+
178
+ Callback executed when the script loads successfully
179
+
180
+ |Property|Type|Description|Default|Required|
181
+ |:--|:--|:--|:--|:--:|
182
+ |id|string|The original script ID|-|✅ Required|
183
+ |elementId|string|The actual DOM element ID used (anonymized if enabled)|-|✅ Required|
184
+ |hasConsent|boolean|Has consent|-|✅ Required|
185
+ |consents|ConsentState|The current consent state|-|✅ Required|
186
+ |element|HTMLScriptElement \|undefined|The script element (for load/error callbacks) Will be undefined for callback-only scripts|-|Optional|
187
+ |error|Error \|undefined|Error information (for error callbacks)|-|Optional|
188
+
189
+ #### `onError`
190
+
191
+ Callback executed if the script fails to load
192
+
193
+ |Property|Type|Description|Default|Required|
194
+ |:--|:--|:--|:--|:--:|
195
+ |id|string|The original script ID|-|✅ Required|
196
+ |elementId|string|The actual DOM element ID used (anonymized if enabled)|-|✅ Required|
197
+ |hasConsent|boolean|Has consent|-|✅ Required|
198
+ |consents|ConsentState|The current consent state|-|✅ Required|
199
+ |element|HTMLScriptElement \|undefined|The script element (for load/error callbacks) Will be undefined for callback-only scripts|-|Optional|
200
+ |error|Error \|undefined|Error information (for error callbacks)|-|Optional|
201
+
202
+ #### `onConsentChange`
203
+
204
+ Callback executed whenever the consent store is changed. This callback only applies to scripts already loaded.
205
+
206
+ |Property|Type|Description|Default|Required|
207
+ |:--|:--|:--|:--|:--:|
208
+ |id|string|The original script ID|-|✅ Required|
209
+ |elementId|string|The actual DOM element ID used (anonymized if enabled)|-|✅ Required|
210
+ |hasConsent|boolean|Has consent|-|✅ Required|
211
+ |consents|ConsentState|The current consent state|-|✅ Required|
212
+ |element|HTMLScriptElement \|undefined|The script element (for load/error callbacks) Will be undefined for callback-only scripts|-|Optional|
213
+ |error|Error \|undefined|Error information (for error callbacks)|-|Optional|
@@ -2,25 +2,86 @@
2
2
  title: X Pixel (Twitter Pixel)
3
3
  description: Track conversions and build audiences for advertising campaigns on X (formerly Twitter).
4
4
  lastModified: 2025-09-24
5
-
6
5
  icon: x
7
6
  ---
8
- X Pixel (formerly Twitter Pixel) is X's conversion tracking and audience building tool. It helps you measure ad performance, retarget website visitors, and optimize campaigns on the X platform. By default, c15t loads this script based on `marketing` consent.
7
+ X Pixel (formerly Twitter Pixel) is X's conversion tracking and audience building tool. It helps you measure ad performance, retarget website visitors, and optimize campaigns on the X platform.
8
+
9
+ ## Official X documentation
10
+
11
+ * [Conversion tracking for websites (X Ads Help)](https://business.x.com/en/help/campaign-measurement-and-analytics/conversion-tracking-for-websites)
12
+
13
+ ## Integrate with c15t
14
+
15
+ **React**
16
+
17
+ ```tsx
18
+ import { type ReactNode } from 'react';
19
+ import { ConsentManagerProvider } from '@c15t/react';
20
+ import { xPixel } from '@c15t/scripts/x-pixel';
21
+
22
+ const scripts = [xPixel({ pixelId: '123456789012345' })];
23
+
24
+ export function ConsentProvider({ children }: { children: ReactNode }) {
25
+ return (
26
+ <ConsentManagerProvider
27
+ options={{
28
+ mode: 'hosted',
29
+ backendURL: 'https://your-instance.c15t.dev',
30
+ scripts,
31
+ }}
32
+ >
33
+ {children}
34
+ </ConsentManagerProvider>
35
+ );
36
+ }
37
+ ```
9
38
 
10
- ## Implementation
39
+ **Next.js**
11
40
 
12
- > ℹ️ **Info:**
13
- > See the integration overview for how to pass scripts to your framework (JavaScript, React, or Next.js).
41
+ ```tsx
42
+ 'use client';
43
+
44
+ import { type ReactNode } from 'react';
45
+ import { ConsentManagerProvider } from '@c15t/nextjs';
46
+ import { xPixel } from '@c15t/scripts/x-pixel';
47
+
48
+ const scripts = [xPixel({ pixelId: '123456789012345' })];
49
+
50
+ export function ConsentProvider({ children }: { children: ReactNode }) {
51
+ return (
52
+ <ConsentManagerProvider
53
+ options={{
54
+ mode: 'hosted',
55
+ backendURL: '/api/c15t',
56
+ scripts,
57
+ }}
58
+ >
59
+ {children}
60
+ </ConsentManagerProvider>
61
+ );
62
+ }
63
+ ```
64
+
65
+ **JavaScript**
14
66
 
15
67
  ```ts
68
+ import { getOrCreateConsentRuntime } from 'c15t';
16
69
  import { xPixel } from '@c15t/scripts/x-pixel';
17
70
 
18
- xPixel({
19
- id: '123456789012345',
20
- })
71
+ getOrCreateConsentRuntime({
72
+ mode: 'hosted',
73
+ backendURL: 'https://your-instance.c15t.dev',
74
+ scripts: [xPixel({ pixelId: '123456789012345' })],
75
+ });
21
76
  ```
22
77
 
23
- ## xPixelEvent
78
+ ## How c15t loads it
79
+
80
+ * **Category:** `marketing` (Ads & Pixels)
81
+ * **Loads when:** marketing consent is granted
82
+ * **On revocation:** unloaded — c15t removes the script element from the DOM
83
+
84
+ ## Configure the integration
24
85
 
25
86
  You can use the `xPixelEvent` function to track events. This is a wrapper around the `twq` function that the X Pixel script uses.
26
87
 
@@ -30,6 +91,32 @@ import { xPixelEvent } from '@c15t/scripts/x-pixel';
30
91
  xPixelEvent('tw-xxxx-xxxx', { value: 10.00, currency: 'USD' });
31
92
  ```
32
93
 
94
+ ## Tracking events in your app
95
+
96
+ c15t gates the X Pixel script from loading until `marketing` consent is granted. Your application code that calls `twq` or the `xPixelEvent` helper is **not** automatically gated — `window.twq` does not exist before consent is granted, and is removed again if consent is revoked. Unguarded calls throw.
97
+
98
+ Guard event calls by checking consent state:
99
+
100
+ ```tsx
101
+ import { useCallback } from 'react';
102
+ import { useConsentManager } from '@c15t/react';
103
+ import { xPixelEvent } from '@c15t/scripts/x-pixel';
104
+
105
+ function useTrackPurchase() {
106
+ const { has } = useConsentManager();
107
+ return useCallback(() => {
108
+ if (has('marketing')) {
109
+ xPixelEvent('tw-xxxx-xxxx', { value: 10.0, currency: 'USD' });
110
+ }
111
+ }, [has]);
112
+ }
113
+
114
+ function PurchaseButton() {
115
+ const trackPurchase = useTrackPurchase();
116
+ return <button onClick={trackPurchase}>Complete purchase</button>;
117
+ }
118
+ ```
119
+
33
120
  ## Types
34
121
 
35
122
  ### XPixelOptions
@@ -128,7 +215,9 @@ Callback executed whenever the consent store is changed. This callback only appl
128
215
  |search\_string|string \|undefined|Search string of the conversion event|-|Optional|
129
216
  |description|string \|undefined|Description of the conversion event|-|Optional|
130
217
  |twclid|string \|undefined|twclid of the conversion event The X Pixel already automatically passes twclid from URL or first-party cookie. This parameter can be optionally used to force attribution to a certain ad click.|-|Optional|
131
- |status|boolean \|undefined|Status of the conversion event|-|Optional|
218
+ |status|"started" \|"completed" \|undefined|Status of the conversion event Should be set to values like "started" or "completed".|-|Optional|
219
+ |email\_address|string \|undefined|Email address used for user matching. The X Pixel hashes this value before transmission.|-|Optional|
220
+ |phone\_number|string \|undefined|Phone number used for user matching. Include country code in E.164 format (for example, +11234567890). The X Pixel hashes this value before transmission.|-|Optional|
132
221
  |contents|XPixelContent \|undefined|Content/products associated with the conversion event|-|Optional|
133
222
 
134
223
  ### XPixelContent