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.
- package/CHANGELOG.md +36 -0
- package/dist/index.cjs +2 -2
- package/dist/index.js +2 -2
- package/dist-types/index.d.ts +1 -1
- package/dist-types/version.d.ts +1 -1
- package/docs/integrations/ahrefs-analytics.md +224 -0
- package/docs/integrations/cloudflare-web-analytics.md +194 -0
- package/docs/integrations/crisp.md +214 -0
- package/docs/integrations/databuddy.md +136 -65
- package/docs/integrations/fathom-analytics.md +221 -0
- package/docs/integrations/google-tag-manager.md +84 -15
- package/docs/integrations/google-tag.md +89 -8
- package/docs/integrations/hotjar.md +211 -0
- package/docs/integrations/intercom.md +214 -0
- package/docs/integrations/linkedin-insights.md +130 -11
- package/docs/integrations/matomo-analytics.md +246 -0
- package/docs/integrations/meta-pixel.md +377 -24
- package/docs/integrations/microsoft-clarity.md +241 -0
- package/docs/integrations/microsoft-uet.md +120 -9
- package/docs/integrations/mixpanel-analytics.md +198 -0
- package/docs/integrations/overview.md +69 -74
- package/docs/integrations/plausible-analytics.md +237 -0
- package/docs/integrations/posthog.md +172 -41
- package/docs/integrations/promptwatch.md +187 -0
- package/docs/integrations/reddit-pixel.md +336 -0
- package/docs/integrations/rybbit-analytics.md +222 -0
- package/docs/integrations/segment.md +213 -0
- package/docs/integrations/snapchat-pixel.md +244 -0
- package/docs/integrations/tiktok-pixel.md +88 -10
- package/docs/integrations/umami-analytics.md +220 -0
- package/docs/integrations/vercel-analytics.md +213 -0
- package/docs/integrations/x-pixel.md +99 -10
- package/docs/script-loader.md +168 -51
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,41 @@
|
|
|
1
1
|
# c15t
|
|
2
2
|
|
|
3
|
+
## 2.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 4a89092: Expanded the script loader with a registry-backed provider system and a much
|
|
8
|
+
broader set of consent-aware integrations. New helpers cover analytics,
|
|
9
|
+
advertising pixels, functional tools, and tag managers, including Ahrefs,
|
|
10
|
+
Cloudflare Web Analytics, Fathom, Hotjar, Matomo, Microsoft Clarity, Mixpanel,
|
|
11
|
+
Plausible, PromptWatch, Rybbit, Segment, Umami, Vercel Analytics, Reddit Pixel,
|
|
12
|
+
Snapchat Pixel, and Crisp/Intercom.
|
|
13
|
+
|
|
14
|
+
Provider manifests now share common utilities for script URL resolution, boolean
|
|
15
|
+
data attributes, install-step builders, Google consent mapping, and lifecycle
|
|
16
|
+
execution. The package also includes registry metadata, focused provider tests,
|
|
17
|
+
and engine coverage so script helpers resolve predictable loader URLs,
|
|
18
|
+
attributes, consent callbacks, and queued vendor calls.
|
|
19
|
+
|
|
20
|
+
Google Tag and Google Tag Manager boot timestamps now resolve during script
|
|
21
|
+
lifecycle execution instead of helper construction, which keeps documented setup
|
|
22
|
+
patterns compatible with Next.js Cache Components prerendering.
|
|
23
|
+
|
|
24
|
+
PostHog now supports explicit EU/US region selection, keeps the bootstrap script
|
|
25
|
+
host aligned with an explicit API host, and exposes loading modes for immediate
|
|
26
|
+
cookieless consent sync, consent-gated loading, or disabling the helper without
|
|
27
|
+
issuing a PostHog network request.
|
|
28
|
+
|
|
29
|
+
Updated the docs and CLI generation prompts so these providers are discoverable
|
|
30
|
+
from the integration docs and script-loader setup flows.
|
|
31
|
+
|
|
32
|
+
### Patch Changes
|
|
33
|
+
|
|
34
|
+
- Updated dependencies [1588a24]
|
|
35
|
+
- Updated dependencies [4a89092]
|
|
36
|
+
- @c15t/translations@2.1.0
|
|
37
|
+
- @c15t/schema@2.1.0
|
|
38
|
+
|
|
3
39
|
## 2.0.4
|
|
4
40
|
|
|
5
41
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -607,7 +607,7 @@ const initial_state_initialState = {
|
|
|
607
607
|
debug: false,
|
|
608
608
|
config: {
|
|
609
609
|
pkg: 'c15t',
|
|
610
|
-
version: "2.0
|
|
610
|
+
version: "2.1.0",
|
|
611
611
|
mode: 'Unknown'
|
|
612
612
|
},
|
|
613
613
|
consents: consent_types_consentTypes.reduce((acc, consent)=>{
|
|
@@ -4073,7 +4073,7 @@ function getOrCreateConsentRuntime(options, pkgInfo) {
|
|
|
4073
4073
|
config: {
|
|
4074
4074
|
...userConfig ?? {},
|
|
4075
4075
|
pkg: pkgInfo?.pkg || 'c15t',
|
|
4076
|
-
version: pkgInfo?.version || "2.0
|
|
4076
|
+
version: pkgInfo?.version || "2.1.0",
|
|
4077
4077
|
mode: normalizedMode,
|
|
4078
4078
|
meta: {
|
|
4079
4079
|
...userConfig?.meta ?? {},
|
package/dist/index.js
CHANGED
|
@@ -531,7 +531,7 @@ const initial_state_initialState = {
|
|
|
531
531
|
debug: false,
|
|
532
532
|
config: {
|
|
533
533
|
pkg: 'c15t',
|
|
534
|
-
version: "2.0
|
|
534
|
+
version: "2.1.0",
|
|
535
535
|
mode: 'Unknown'
|
|
536
536
|
},
|
|
537
537
|
consents: consent_types_consentTypes.reduce((acc, consent)=>{
|
|
@@ -3996,7 +3996,7 @@ function getOrCreateConsentRuntime(options, pkgInfo) {
|
|
|
3996
3996
|
config: {
|
|
3997
3997
|
...userConfig ?? {},
|
|
3998
3998
|
pkg: pkgInfo?.pkg || 'c15t',
|
|
3999
|
-
version: pkgInfo?.version || "2.0
|
|
3999
|
+
version: pkgInfo?.version || "2.1.0",
|
|
4000
4000
|
mode: normalizedMode,
|
|
4001
4001
|
meta: {
|
|
4002
4002
|
...userConfig?.meta ?? {},
|
package/dist-types/index.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ export { applyPolicyPurposeAllowlist, applyPolicyScopeForRuntimeGating, filterCo
|
|
|
24
24
|
export { flattenPolicyActionGroups, hasPolicyHints, resolvePolicyActionGroups, resolvePolicyAllowedActions, resolvePolicyDirection, resolvePolicyOrderedActions, resolvePolicyPrimaryActions, resolvePolicyUiProfile, shouldFillPolicyActions, } from './libs/policy-actions';
|
|
25
25
|
export type { PrefetchOptions } from './libs/prefetch';
|
|
26
26
|
export { buildPrefetchScript } from './libs/prefetch';
|
|
27
|
-
export { emitScriptDebugEvent, getLoadedScriptIds, isScriptLoaded, loadScripts, type Script, type ScriptDebugAction, type ScriptDebugEvent, type ScriptDebugEventInput, type ScriptDebugListener, type ScriptDebugScope, type ScriptDebugSource, type ScriptLifecycleCallback, subscribeToScriptDebugEvents, unloadScripts, updateScripts, } from './libs/script-loader';
|
|
27
|
+
export { emitScriptDebugEvent, getLoadedScriptIds, isScriptLoaded, loadScripts, type Script, type ScriptCallbackInfo, type ScriptDebugAction, type ScriptDebugEvent, type ScriptDebugEventInput, type ScriptDebugListener, type ScriptDebugScope, type ScriptDebugSource, type ScriptLifecycleCallback, subscribeToScriptDebugEvents, unloadScripts, updateScripts, } from './libs/script-loader';
|
|
28
28
|
export { type ConsentRuntimeOptions, type ConsentRuntimePkgInfo, type ConsentRuntimeResult, clearConsentRuntimeCache, getOrCreateConsentRuntime, } from './runtime';
|
|
29
29
|
export { createConsentManagerStore } from './store';
|
|
30
30
|
export type { ActiveUI, ConsentStoreState, InitDataSource, OfflinePolicyConfig, PolicyScopeMode, PolicySurfaceState, PolicyUiAction, PolicyUiActionDirection, PolicyUiActionGroup, PolicyUiProfile, PolicyUiSurfaceConfig, SSRInitialData, SSRInitRequestContext, SSRInitRequestMetadata, SSRSkippedReason, StoreOptions, UnstableGenericPolicyConsentInput, UnstableLegalDocumentConsentInput, UnstablePolicyConsentInput, } from './store/type';
|
package/dist-types/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "2.0
|
|
1
|
+
export declare const version = "2.1.0";
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Ahrefs Analytics
|
|
3
|
+
description: Cookieless web analytics from Ahrefs with a prebuilt helper that wires the project key into a c15t-managed script.
|
|
4
|
+
lastModified: 2026-05-10
|
|
5
|
+
icon: ahrefs
|
|
6
|
+
---
|
|
7
|
+
Ahrefs Web Analytics is a cookieless analytics product configured with a single project key. The `ahrefsAnalytics()` helper wires that key into the `data-key` attribute that Ahrefs' loader reads at startup.
|
|
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 { ahrefsAnalytics } from '@c15t/scripts/ahrefs-analytics';
|
|
17
|
+
|
|
18
|
+
const scripts = [
|
|
19
|
+
ahrefsAnalytics({
|
|
20
|
+
key: 'your-ahrefs-project-key',
|
|
21
|
+
}),
|
|
22
|
+
];
|
|
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
|
+
```
|
|
38
|
+
|
|
39
|
+
**Next.js**
|
|
40
|
+
|
|
41
|
+
```tsx
|
|
42
|
+
'use client';
|
|
43
|
+
|
|
44
|
+
import { type ReactNode } from 'react';
|
|
45
|
+
import { ConsentManagerProvider } from '@c15t/nextjs';
|
|
46
|
+
import { ahrefsAnalytics } from '@c15t/scripts/ahrefs-analytics';
|
|
47
|
+
|
|
48
|
+
const scripts = [
|
|
49
|
+
ahrefsAnalytics({
|
|
50
|
+
key: 'your-ahrefs-project-key',
|
|
51
|
+
}),
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
export function ConsentProvider({ children }: { children: ReactNode }) {
|
|
55
|
+
return (
|
|
56
|
+
<ConsentManagerProvider
|
|
57
|
+
options={{
|
|
58
|
+
mode: 'hosted',
|
|
59
|
+
backendURL: '/api/c15t',
|
|
60
|
+
scripts,
|
|
61
|
+
}}
|
|
62
|
+
>
|
|
63
|
+
{children}
|
|
64
|
+
</ConsentManagerProvider>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
**JavaScript**
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
import { getOrCreateConsentRuntime } from 'c15t';
|
|
73
|
+
import { ahrefsAnalytics } from '@c15t/scripts/ahrefs-analytics';
|
|
74
|
+
|
|
75
|
+
getOrCreateConsentRuntime({
|
|
76
|
+
mode: 'hosted',
|
|
77
|
+
backendURL: 'https://your-instance.c15t.dev',
|
|
78
|
+
scripts: [
|
|
79
|
+
ahrefsAnalytics({
|
|
80
|
+
key: 'your-ahrefs-project-key',
|
|
81
|
+
}),
|
|
82
|
+
],
|
|
83
|
+
});
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## How c15t loads it
|
|
87
|
+
|
|
88
|
+
* **Category:** `measurement` (Analytics)
|
|
89
|
+
* **Loads when:** measurement consent is granted
|
|
90
|
+
* **On revocation:** unloaded — c15t removes the script element from the DOM. Ahrefs Web Analytics is cookieless, so no client-side state needs clearing.
|
|
91
|
+
|
|
92
|
+
To run from a custom loader URL (for example a self-hosted proxy):
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
ahrefsAnalytics({
|
|
96
|
+
key: 'your-ahrefs-project-key',
|
|
97
|
+
scriptUrl: 'https://analytics.example.com/analytics.js',
|
|
98
|
+
})
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Once loaded, Ahrefs exposes its runtime API on `window.AhrefsAnalytics`. The c15t helper only models the serializable script configuration — calls to `window.AhrefsAnalytics.sendEvent(...)` happen in your application code as needed.
|
|
102
|
+
|
|
103
|
+
## Tracking events in your app
|
|
104
|
+
|
|
105
|
+
c15t gates the Ahrefs Analytics script from loading until `measurement` consent is granted. Your application code that calls Ahrefs' runtime API (`window.AhrefsAnalytics.sendEvent`) is **not** automatically gated — `window.AhrefsAnalytics` does not exist until the script is loaded, so unguarded calls before consent throw.
|
|
106
|
+
|
|
107
|
+
Guard event calls by checking consent state. From React:
|
|
108
|
+
|
|
109
|
+
```tsx
|
|
110
|
+
import { useCallback } from 'react';
|
|
111
|
+
import { useConsentManager } from '@c15t/react';
|
|
112
|
+
|
|
113
|
+
function SignupExample() {
|
|
114
|
+
const { has } = useConsentManager();
|
|
115
|
+
|
|
116
|
+
const trackSignup = useCallback(() => {
|
|
117
|
+
if (has('measurement')) {
|
|
118
|
+
window.AhrefsAnalytics?.sendEvent('signup');
|
|
119
|
+
}
|
|
120
|
+
}, [has]);
|
|
121
|
+
|
|
122
|
+
// Call trackSignup() from an event handler after signup succeeds.
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
From plain JavaScript:
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
import { getOrCreateConsentRuntime } from 'c15t';
|
|
130
|
+
|
|
131
|
+
const { consentStore } = getOrCreateConsentRuntime();
|
|
132
|
+
|
|
133
|
+
if (consentStore.getState().has('measurement')) {
|
|
134
|
+
window.AhrefsAnalytics?.sendEvent('signup');
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Types
|
|
139
|
+
|
|
140
|
+
### AhrefsAnalyticsOptions
|
|
141
|
+
|
|
142
|
+
|Property|Type|Description|Default|Required|
|
|
143
|
+
|:--|:--|:--|:--|:--:|
|
|
144
|
+
|key|string|Your Ahrefs Web Analytics project key.|-|✅ Required|
|
|
145
|
+
|scriptUrl|string \|undefined|Custom loader URL.|'https\://analytics.ahrefs.com/analytics.js'|Optional|
|
|
146
|
+
|
|
147
|
+
### Script
|
|
148
|
+
|
|
149
|
+
|Property|Type|Description|Default|Required|
|
|
150
|
+
|:--|:--|:--|:--|:--:|
|
|
151
|
+
|id|string|Unique identifier for the script|-|✅ Required|
|
|
152
|
+
|src|string \|undefined|URL of the script to load|-|Optional|
|
|
153
|
+
|textContent|string \|undefined|Inline JavaScript code to execute|-|Optional|
|
|
154
|
+
|category|HasCondition\<AllConsentNames>|Consent category or condition required to load this script|-|✅ Required|
|
|
155
|
+
|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|
|
|
156
|
+
|persistAfterConsentRevoked|boolean \|undefined|Whether the script should persist after consent is revoked.|false|Optional|
|
|
157
|
+
|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|
|
|
158
|
+
|fetchPriority|"high" \|"low" \|"auto" \|undefined|Priority hint for browser resource loading|-|Optional|
|
|
159
|
+
|attributes|Record\<string, string> \|undefined|Additional attributes to add to the script element|-|Optional|
|
|
160
|
+
|async|boolean \|undefined|Whether to use async loading|-|Optional|
|
|
161
|
+
|defer|boolean \|undefined|Whether to defer script loading|-|Optional|
|
|
162
|
+
|nonce|string \|undefined|Content Security Policy nonce|-|Optional|
|
|
163
|
+
|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|
|
|
164
|
+
|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|
|
|
165
|
+
|onBeforeLoad|Object \|undefined|Callback executed before the script is loaded|-|Optional|
|
|
166
|
+
|onLoad|Object \|undefined|Callback executed when the script loads successfully|-|Optional|
|
|
167
|
+
|onError|Object \|undefined|Callback executed if the script fails to load|-|Optional|
|
|
168
|
+
|onConsentChange|Object \|undefined|Callback executed whenever the consent store is changed. This callback only applies to scripts already loaded.|-|Optional|
|
|
169
|
+
|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|
|
|
170
|
+
|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|
|
|
171
|
+
|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|
|
|
172
|
+
|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|
|
|
173
|
+
|
|
174
|
+
#### `onBeforeLoad`
|
|
175
|
+
|
|
176
|
+
Callback executed before the script is loaded
|
|
177
|
+
|
|
178
|
+
|Property|Type|Description|Default|Required|
|
|
179
|
+
|:--|:--|:--|:--|:--:|
|
|
180
|
+
|id|string|The original script ID|-|✅ Required|
|
|
181
|
+
|elementId|string|The actual DOM element ID used (anonymized if enabled)|-|✅ Required|
|
|
182
|
+
|hasConsent|boolean|Has consent|-|✅ Required|
|
|
183
|
+
|consents|ConsentState|The current consent state|-|✅ Required|
|
|
184
|
+
|element|HTMLScriptElement \|undefined|The script element (for load/error callbacks) Will be undefined for callback-only scripts|-|Optional|
|
|
185
|
+
|error|Error \|undefined|Error information (for error callbacks)|-|Optional|
|
|
186
|
+
|
|
187
|
+
#### `onLoad`
|
|
188
|
+
|
|
189
|
+
Callback executed when the script loads successfully
|
|
190
|
+
|
|
191
|
+
|Property|Type|Description|Default|Required|
|
|
192
|
+
|:--|:--|:--|:--|:--:|
|
|
193
|
+
|id|string|The original script ID|-|✅ Required|
|
|
194
|
+
|elementId|string|The actual DOM element ID used (anonymized if enabled)|-|✅ Required|
|
|
195
|
+
|hasConsent|boolean|Has consent|-|✅ Required|
|
|
196
|
+
|consents|ConsentState|The current consent state|-|✅ Required|
|
|
197
|
+
|element|HTMLScriptElement \|undefined|The script element (for load/error callbacks) Will be undefined for callback-only scripts|-|Optional|
|
|
198
|
+
|error|Error \|undefined|Error information (for error callbacks)|-|Optional|
|
|
199
|
+
|
|
200
|
+
#### `onError`
|
|
201
|
+
|
|
202
|
+
Callback executed if the script fails to load
|
|
203
|
+
|
|
204
|
+
|Property|Type|Description|Default|Required|
|
|
205
|
+
|:--|:--|:--|:--|:--:|
|
|
206
|
+
|id|string|The original script ID|-|✅ Required|
|
|
207
|
+
|elementId|string|The actual DOM element ID used (anonymized if enabled)|-|✅ Required|
|
|
208
|
+
|hasConsent|boolean|Has consent|-|✅ Required|
|
|
209
|
+
|consents|ConsentState|The current consent state|-|✅ Required|
|
|
210
|
+
|element|HTMLScriptElement \|undefined|The script element (for load/error callbacks) Will be undefined for callback-only scripts|-|Optional|
|
|
211
|
+
|error|Error \|undefined|Error information (for error callbacks)|-|Optional|
|
|
212
|
+
|
|
213
|
+
#### `onConsentChange`
|
|
214
|
+
|
|
215
|
+
Callback executed whenever the consent store is changed. This callback only applies to scripts already loaded.
|
|
216
|
+
|
|
217
|
+
|Property|Type|Description|Default|Required|
|
|
218
|
+
|:--|:--|:--|:--|:--:|
|
|
219
|
+
|id|string|The original script ID|-|✅ Required|
|
|
220
|
+
|elementId|string|The actual DOM element ID used (anonymized if enabled)|-|✅ Required|
|
|
221
|
+
|hasConsent|boolean|Has consent|-|✅ Required|
|
|
222
|
+
|consents|ConsentState|The current consent state|-|✅ Required|
|
|
223
|
+
|element|HTMLScriptElement \|undefined|The script element (for load/error callbacks) Will be undefined for callback-only scripts|-|Optional|
|
|
224
|
+
|error|Error \|undefined|Error information (for error callbacks)|-|Optional|
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Cloudflare Web Analytics
|
|
3
|
+
description: Cookieless analytics from Cloudflare with a prebuilt helper that serializes the beacon config into the `data-cf-beacon` attribute.
|
|
4
|
+
lastModified: 2026-05-10
|
|
5
|
+
icon: cloudflare-web-analytics
|
|
6
|
+
---
|
|
7
|
+
Cloudflare Web Analytics is a cookieless analytics product configured through a single `data-cf-beacon` attribute on its loader. The `cloudflareWebAnalytics()` helper serializes your token and single-page application (SPA) preference into that attribute 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 { cloudflareWebAnalytics } from '@c15t/scripts/cloudflare-web-analytics';
|
|
17
|
+
|
|
18
|
+
const scripts = [
|
|
19
|
+
cloudflareWebAnalytics({
|
|
20
|
+
token: 'your-cloudflare-token',
|
|
21
|
+
}),
|
|
22
|
+
];
|
|
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
|
+
```
|
|
38
|
+
|
|
39
|
+
**Next.js**
|
|
40
|
+
|
|
41
|
+
```tsx
|
|
42
|
+
'use client';
|
|
43
|
+
|
|
44
|
+
import { type ReactNode } from 'react';
|
|
45
|
+
import { ConsentManagerProvider } from '@c15t/nextjs';
|
|
46
|
+
import { cloudflareWebAnalytics } from '@c15t/scripts/cloudflare-web-analytics';
|
|
47
|
+
|
|
48
|
+
const scripts = [
|
|
49
|
+
cloudflareWebAnalytics({
|
|
50
|
+
token: 'your-cloudflare-token',
|
|
51
|
+
}),
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
export function ConsentProvider({ children }: { children: ReactNode }) {
|
|
55
|
+
return (
|
|
56
|
+
<ConsentManagerProvider
|
|
57
|
+
options={{
|
|
58
|
+
mode: 'hosted',
|
|
59
|
+
backendURL: '/api/c15t',
|
|
60
|
+
scripts,
|
|
61
|
+
}}
|
|
62
|
+
>
|
|
63
|
+
{children}
|
|
64
|
+
</ConsentManagerProvider>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
**JavaScript**
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
import { getOrCreateConsentRuntime } from 'c15t';
|
|
73
|
+
import { cloudflareWebAnalytics } from '@c15t/scripts/cloudflare-web-analytics';
|
|
74
|
+
|
|
75
|
+
getOrCreateConsentRuntime({
|
|
76
|
+
mode: 'hosted',
|
|
77
|
+
backendURL: 'https://your-instance.c15t.dev',
|
|
78
|
+
scripts: [
|
|
79
|
+
cloudflareWebAnalytics({
|
|
80
|
+
token: 'your-cloudflare-token',
|
|
81
|
+
}),
|
|
82
|
+
],
|
|
83
|
+
});
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## How c15t loads it
|
|
87
|
+
|
|
88
|
+
* **Category:** `measurement` (Analytics)
|
|
89
|
+
* **Loads when:** measurement consent is granted
|
|
90
|
+
* **On revocation:** unloaded — c15t removes the script element from the DOM. Cloudflare Web Analytics is cookieless, so no client-side state needs clearing.
|
|
91
|
+
|
|
92
|
+
SPA route tracking is enabled by default. Disable it for traditional multi-page apps:
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
cloudflareWebAnalytics({
|
|
96
|
+
token: 'your-cloudflare-token',
|
|
97
|
+
spa: false,
|
|
98
|
+
})
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
The helper JSON-encodes `{ token, spa }` into the `data-cf-beacon` attribute that Cloudflare's loader reads at startup, matching Cloudflare's recommended embed.
|
|
102
|
+
|
|
103
|
+
## Tracking events in your app
|
|
104
|
+
|
|
105
|
+
Cloudflare Web Analytics has no app-facing event API — the beacon tracks pageviews automatically once the script is loaded. There are no event calls in your application code to guard, so c15t's consent gating fully controls when and whether tracking happens.
|
|
106
|
+
|
|
107
|
+
## Types
|
|
108
|
+
|
|
109
|
+
### CloudflareWebAnalyticsOptions
|
|
110
|
+
|
|
111
|
+
|Property|Type|Description|Default|Required|
|
|
112
|
+
|:--|:--|:--|:--|:--:|
|
|
113
|
+
|token|string|Your Cloudflare Web Analytics token.|-|✅ Required|
|
|
114
|
+
|spa|boolean \|undefined|Enable Cloudflare's SPA route tracking.|true|Optional|
|
|
115
|
+
|scriptUrl|string \|undefined|Custom loader URL.|'https\://static.cloudflareinsights.com/beacon.min.js'|Optional|
|
|
116
|
+
|
|
117
|
+
### Script
|
|
118
|
+
|
|
119
|
+
|Property|Type|Description|Default|Required|
|
|
120
|
+
|:--|:--|:--|:--|:--:|
|
|
121
|
+
|id|string|Unique identifier for the script|-|✅ Required|
|
|
122
|
+
|src|string \|undefined|URL of the script to load|-|Optional|
|
|
123
|
+
|textContent|string \|undefined|Inline JavaScript code to execute|-|Optional|
|
|
124
|
+
|category|HasCondition\<AllConsentNames>|Consent category or condition required to load this script|-|✅ Required|
|
|
125
|
+
|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|
|
|
126
|
+
|persistAfterConsentRevoked|boolean \|undefined|Whether the script should persist after consent is revoked.|false|Optional|
|
|
127
|
+
|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|
|
|
128
|
+
|fetchPriority|"high" \|"low" \|"auto" \|undefined|Priority hint for browser resource loading|-|Optional|
|
|
129
|
+
|attributes|Record\<string, string> \|undefined|Additional attributes to add to the script element|-|Optional|
|
|
130
|
+
|async|boolean \|undefined|Whether to use async loading|-|Optional|
|
|
131
|
+
|defer|boolean \|undefined|Whether to defer script loading|-|Optional|
|
|
132
|
+
|nonce|string \|undefined|Content Security Policy nonce|-|Optional|
|
|
133
|
+
|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|
|
|
134
|
+
|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|
|
|
135
|
+
|onBeforeLoad|Object \|undefined|Callback executed before the script is loaded|-|Optional|
|
|
136
|
+
|onLoad|Object \|undefined|Callback executed when the script loads successfully|-|Optional|
|
|
137
|
+
|onError|Object \|undefined|Callback executed if the script fails to load|-|Optional|
|
|
138
|
+
|onConsentChange|Object \|undefined|Callback executed whenever the consent store is changed. This callback only applies to scripts already loaded.|-|Optional|
|
|
139
|
+
|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|
|
|
140
|
+
|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|
|
|
141
|
+
|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|
|
|
142
|
+
|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|
|
|
143
|
+
|
|
144
|
+
#### `onBeforeLoad`
|
|
145
|
+
|
|
146
|
+
Callback executed before the script is loaded
|
|
147
|
+
|
|
148
|
+
|Property|Type|Description|Default|Required|
|
|
149
|
+
|:--|:--|:--|:--|:--:|
|
|
150
|
+
|id|string|The original script ID|-|✅ Required|
|
|
151
|
+
|elementId|string|The actual DOM element ID used (anonymized if enabled)|-|✅ Required|
|
|
152
|
+
|hasConsent|boolean|Has consent|-|✅ Required|
|
|
153
|
+
|consents|ConsentState|The current consent state|-|✅ Required|
|
|
154
|
+
|element|HTMLScriptElement \|undefined|The script element (for load/error callbacks) Will be undefined for callback-only scripts|-|Optional|
|
|
155
|
+
|error|Error \|undefined|Error information (for error callbacks)|-|Optional|
|
|
156
|
+
|
|
157
|
+
#### `onLoad`
|
|
158
|
+
|
|
159
|
+
Callback executed when the script loads successfully
|
|
160
|
+
|
|
161
|
+
|Property|Type|Description|Default|Required|
|
|
162
|
+
|:--|:--|:--|:--|:--:|
|
|
163
|
+
|id|string|The original script ID|-|✅ Required|
|
|
164
|
+
|elementId|string|The actual DOM element ID used (anonymized if enabled)|-|✅ Required|
|
|
165
|
+
|hasConsent|boolean|Has consent|-|✅ Required|
|
|
166
|
+
|consents|ConsentState|The current consent state|-|✅ Required|
|
|
167
|
+
|element|HTMLScriptElement \|undefined|The script element (for load/error callbacks) Will be undefined for callback-only scripts|-|Optional|
|
|
168
|
+
|error|Error \|undefined|Error information (for error callbacks)|-|Optional|
|
|
169
|
+
|
|
170
|
+
#### `onError`
|
|
171
|
+
|
|
172
|
+
Callback executed if the script fails to load
|
|
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
|
+
#### `onConsentChange`
|
|
184
|
+
|
|
185
|
+
Callback executed whenever the consent store is changed. This callback only applies to scripts already loaded.
|
|
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|
|