c15t 2.0.0 → 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 (44) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/README.md +15 -15
  3. package/dist/index.cjs +29 -26
  4. package/dist/index.js +29 -26
  5. package/dist-types/client/hosted/init.d.ts +1 -1
  6. package/dist-types/client/hosted/types.d.ts +1 -1
  7. package/dist-types/client/offline/types.d.ts +1 -1
  8. package/dist-types/index.d.ts +1 -1
  9. package/dist-types/libs/iab-tcf/types.d.ts +4 -4
  10. package/dist-types/libs/policy.d.ts +8 -5
  11. package/dist-types/store/type.d.ts +2 -2
  12. package/dist-types/version.d.ts +1 -1
  13. package/docs/ai-agents.md +111 -0
  14. package/docs/iab/overview.md +4 -4
  15. package/docs/integrations/ahrefs-analytics.md +224 -0
  16. package/docs/integrations/cloudflare-web-analytics.md +194 -0
  17. package/docs/integrations/crisp.md +214 -0
  18. package/docs/integrations/databuddy.md +136 -65
  19. package/docs/integrations/fathom-analytics.md +221 -0
  20. package/docs/integrations/google-tag-manager.md +84 -15
  21. package/docs/integrations/google-tag.md +89 -8
  22. package/docs/integrations/hotjar.md +211 -0
  23. package/docs/integrations/intercom.md +214 -0
  24. package/docs/integrations/linkedin-insights.md +130 -11
  25. package/docs/integrations/matomo-analytics.md +246 -0
  26. package/docs/integrations/meta-pixel.md +377 -24
  27. package/docs/integrations/microsoft-clarity.md +241 -0
  28. package/docs/integrations/microsoft-uet.md +120 -9
  29. package/docs/integrations/mixpanel-analytics.md +198 -0
  30. package/docs/integrations/overview.md +69 -74
  31. package/docs/integrations/plausible-analytics.md +237 -0
  32. package/docs/integrations/posthog.md +172 -41
  33. package/docs/integrations/promptwatch.md +187 -0
  34. package/docs/integrations/reddit-pixel.md +336 -0
  35. package/docs/integrations/rybbit-analytics.md +222 -0
  36. package/docs/integrations/segment.md +213 -0
  37. package/docs/integrations/snapchat-pixel.md +244 -0
  38. package/docs/integrations/tiktok-pixel.md +88 -10
  39. package/docs/integrations/umami-analytics.md +220 -0
  40. package/docs/integrations/vercel-analytics.md +213 -0
  41. package/docs/integrations/x-pixel.md +99 -10
  42. package/docs/script-loader.md +168 -51
  43. package/package.json +25 -15
  44. package/readme.json +1 -1
@@ -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|
@@ -2,19 +2,91 @@
2
2
  title: Google Tag Manager
3
3
  description: Deploy and manage marketing tags centrally with automatic consent state synchronization.
4
4
  lastModified: 2026-02-10
5
-
6
5
  icon: google-tag-manager
7
6
  ---
8
7
  Google Tag Manager (GTM) is Google's tag management system that lets you deploy and manage marketing tags, analytics scripts, and conversion pixels without modifying your codebase. Instead of hardcoding multiple scripts, you configure them through GTM's web interface.
9
8
 
10
- c15t automatically injects the GTM script into your page and syncs consent state with GTM using Consent Mode v2. By default, c15t loads GTM regardless of consent because GTM manages its own internal consent state and only fires tags when appropriate consent is granted.
9
+ c15t automatically injects the GTM script into your page and syncs consent state with GTM using Consent Mode v2. GTM manages its own internal consent state and only fires tags when appropriate consent is granted, which means it can safely load before consent is collected.
11
10
 
12
11
  This prevents GTM-managed scripts from loading without proper consent while giving you centralized control over your marketing stack.
13
12
 
14
13
  > ℹ️ **Info:**
15
14
  > Use GTM if your team manages many tags centrally in the GTM UI. Use gtag.js if you only need GA4/Google Ads directly in code. Don't run both for the same destination unless intentional, or you may duplicate events.
16
15
 
17
- ## Implementation
16
+ ## Integrate with c15t
17
+
18
+ Use your GTM container ID, which begins with `GTM-`.
19
+
20
+ **React**
21
+
22
+ ```tsx
23
+ import { type ReactNode } from 'react';
24
+ import { ConsentManagerProvider } from '@c15t/react';
25
+ import { googleTagManager } from '@c15t/scripts/google-tag-manager';
26
+
27
+ const scripts = [googleTagManager({ id: 'GTM-XXXXXXX' })];
28
+
29
+ export function ConsentProvider({ children }: { children: ReactNode }) {
30
+ return (
31
+ <ConsentManagerProvider
32
+ options={{
33
+ mode: 'hosted',
34
+ backendURL: 'https://your-instance.c15t.dev',
35
+ scripts,
36
+ }}
37
+ >
38
+ {children}
39
+ </ConsentManagerProvider>
40
+ );
41
+ }
42
+ ```
43
+
44
+ **Next.js**
45
+
46
+ ```tsx
47
+ 'use client';
48
+
49
+ import { type ReactNode } from 'react';
50
+ import { ConsentManagerProvider } from '@c15t/nextjs';
51
+ import { googleTagManager } from '@c15t/scripts/google-tag-manager';
52
+
53
+ const scripts = [googleTagManager({ id: 'GTM-XXXXXXX' })];
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 { googleTagManager } from '@c15t/scripts/google-tag-manager';
75
+
76
+ getOrCreateConsentRuntime({
77
+ mode: 'hosted',
78
+ backendURL: 'https://your-instance.c15t.dev',
79
+ scripts: [googleTagManager({ id: 'GTM-XXXXXXX' })],
80
+ });
81
+ ```
82
+
83
+ ## How c15t loads it
84
+
85
+ * **Category:** `necessary` (Tag Managers)
86
+ * **Loads when:** [`alwaysLoad`](/docs/frameworks/react/script-loader#always-load) — runs on page start with Consent Mode v2 defaults set to denied
87
+ * **On consent change:** c15t pushes a Consent Mode v2 `update` to the data layer; GTM-managed tags re-evaluate against the new state
88
+
89
+ ## Configure the integration
18
90
 
19
91
  1. **Creating a Tag Manager Container**
20
92
 
@@ -37,25 +109,22 @@ This prevents GTM-managed scripts from loading without proper consent while givi
37
109
 
38
110
  Create trigger
39
111
 
40
- 3. **Adding / Updating tags** Now for your existing tags, you can add the "consent-update" trigger to the tag, this will fire the update event when the consent state is updated & it has the appropriate consent state.
112
+ 3. **Update tags** Now for your existing tags, you can add the "consent-update" trigger to the tag, this will fire the update event when the consent state is updated & it has the appropriate consent state.
41
113
 
42
114
  Update tags
43
115
 
44
- 4. **Setting up c15t with Google Tag Manager** After creating your container, you can set up c15t with Google Tag Manager. All you need to do is copy and paste your container ID & begins with "GTM-".
116
+ ## Tracking events in your app
45
117
 
46
- > ℹ️ Info:
47
- >
48
- > See the integration overview for how to pass scripts to your framework (JavaScript, React, or Next.js).
118
+ GTM is `alwaysLoad: true`, so the GTM container and `window.dataLayer` are present from page start regardless of consent. Calls like `dataLayer.push({ event: 'signup' })` are **safe at any time** — Consent Mode v2 defaults are set to denied before the user makes a choice, and GTM-managed tags only fire when the matching consent has been granted.
49
119
 
50
- ```ts
51
- import { googleTagManager } from '@c15t/scripts/google-tag-manager';
120
+ ```ts
121
+ window.dataLayer = window.dataLayer || [];
122
+ window.dataLayer.push({ event: 'signup' });
123
+ ```
52
124
 
53
- googleTagManager({
54
- id: 'GTM-XXXXXXX',
55
- })
56
- ```
125
+ You do not need to wrap `dataLayer.push(...)` in a `useConsentManager().has(...)` check — the consent gate happens inside GTM, not inside c15t.
57
126
 
58
- ## Post-setup verification checklist
127
+ ## Verify setup
59
128
 
60
129
  1. Open GTM Preview mode and confirm your container (`GTM-...`) loads on page load.
61
130
  2. Before giving consent, confirm non-essential tags do not fire in GTM Preview.
@@ -2,7 +2,6 @@
2
2
  title: GA4 + Google Ads (gtag.js)
3
3
  description: Send data to Google Analytics 4 and Google Ads with automatic Consent Mode v2 support.
4
4
  lastModified: 2026-02-10
5
-
6
5
  icon: google-analytics
7
6
  ---
8
7
  Google Tag (`gtag.js`) is Google's unified tracking script for sending data to Google Analytics 4 (GA4), Google Ads, and Floodlight. It measures user behavior, tracks conversions, and powers Google's advertising ecosystem.
@@ -17,20 +16,102 @@ c15t initializes Google Tag with Consent Mode v2 defaults set to denied and auto
17
16
  * Use `category: 'measurement'` for analytics-only tracking (GA4 events)
18
17
  * Use `category: 'marketing'` for advertising and conversion tracking (Google Ads)
19
18
 
20
- ## Adding GA4 + Google Ads to c15t
19
+ ## Integrate with c15t
21
20
 
22
- > ℹ️ **Info:**
23
- > See the integration overview for how to pass scripts to your framework (JavaScript, React, or Next.js).
21
+ **React**
22
+
23
+ ```tsx
24
+ import { type ReactNode } from 'react';
25
+ import { ConsentManagerProvider } from '@c15t/react';
26
+ import { gtag } from '@c15t/scripts/google-tag';
27
+
28
+ const scripts = [
29
+ gtag({
30
+ id: 'G-XXXXXXXXXX',
31
+ category: 'measurement', // or 'marketing'
32
+ }),
33
+ ];
34
+
35
+ export function ConsentProvider({ children }: { children: ReactNode }) {
36
+ return (
37
+ <ConsentManagerProvider
38
+ options={{
39
+ mode: 'hosted',
40
+ backendURL: 'https://your-instance.c15t.dev',
41
+ scripts,
42
+ }}
43
+ >
44
+ {children}
45
+ </ConsentManagerProvider>
46
+ );
47
+ }
48
+ ```
49
+
50
+ **Next.js**
51
+
52
+ ```tsx
53
+ 'use client';
54
+
55
+ import { type ReactNode } from 'react';
56
+ import { ConsentManagerProvider } from '@c15t/nextjs';
57
+ import { gtag } from '@c15t/scripts/google-tag';
58
+
59
+ const scripts = [
60
+ gtag({
61
+ id: 'G-XXXXXXXXXX',
62
+ category: 'measurement', // or 'marketing'
63
+ }),
64
+ ];
65
+
66
+ export function ConsentProvider({ children }: { children: ReactNode }) {
67
+ return (
68
+ <ConsentManagerProvider
69
+ options={{
70
+ mode: 'hosted',
71
+ backendURL: '/api/c15t',
72
+ scripts,
73
+ }}
74
+ >
75
+ {children}
76
+ </ConsentManagerProvider>
77
+ );
78
+ }
79
+ ```
80
+
81
+ **JavaScript**
24
82
 
25
83
  ```ts
84
+ import { getOrCreateConsentRuntime } from 'c15t';
26
85
  import { gtag } from '@c15t/scripts/google-tag';
27
86
 
28
- gtag({
29
- id: 'G-XXXXXXXXXX',
30
- category: 'measurement', // or 'marketing'
31
- })
87
+ getOrCreateConsentRuntime({
88
+ mode: 'hosted',
89
+ backendURL: 'https://your-instance.c15t.dev',
90
+ scripts: [
91
+ gtag({
92
+ id: 'G-XXXXXXXXXX',
93
+ category: 'measurement', // or 'marketing'
94
+ }),
95
+ ],
96
+ });
97
+ ```
98
+
99
+ ## How c15t loads it
100
+
101
+ * **Category:** configurable — `measurement` (default, Analytics) or `marketing`
102
+ * **Loads when:** [`alwaysLoad`](/docs/frameworks/react/script-loader#always-load) — runs on page start regardless of consent state, with Consent Mode v2 defaults set to denied
103
+ * **On consent change:** [persists](/docs/frameworks/react/script-loader#persist-after-revocation) — c15t pushes a Consent Mode v2 `update` to gtag instead of removing the script
104
+
105
+ ## Tracking events in your app
106
+
107
+ `gtag.js` is `alwaysLoad: true`, so `window.gtag` is present from page start regardless of consent. Calls like `gtag('event', 'sign_up')` are **safe at any time** — c15t sets Consent Mode v2 defaults to denied before the user makes a choice, and Google's SDK suppresses transmission of events while the relevant consent is denied. When consent later changes, c15t emits a Consent Mode v2 `update` so events fire correctly going forward.
108
+
109
+ ```ts
110
+ window.gtag?.('event', 'sign_up', { method: 'email' });
32
111
  ```
33
112
 
113
+ You do not need to wrap `gtag(...)` calls in a `useConsentManager().has(...)` check — Consent Mode handles the suppression for you.
114
+
34
115
  ## Types
35
116
 
36
117
  ### GtagOptions