@c15t/scripts 2.1.0 → 2.2.0-canary-20260804162155
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +62 -0
- package/README.md +32 -20
- package/dist/e2e-test-utils.cjs +51 -10
- package/dist/e2e-test-utils.js +37 -3
- package/dist/engine/compile.cjs +9 -5
- package/dist/engine/runtime.cjs +103 -17
- package/dist/engine/runtime.js +94 -12
- package/dist/registry.cjs +97 -12
- package/dist/registry.js +80 -0
- package/dist/resolve.cjs +9 -5
- package/dist/types.cjs +17 -13
- package/dist/vendors/_shared/attributes.cjs +13 -9
- package/dist/vendors/_shared/google-consent.cjs +14 -9
- package/dist/vendors/_shared/install-builders.cjs +12 -8
- package/dist/vendors/_shared/script-url.cjs +16 -12
- package/dist/vendors/ads-and-pixels/linkedin-insights.cjs +9 -5
- package/dist/vendors/ads-and-pixels/meta-pixel.cjs +13 -9
- package/dist/vendors/ads-and-pixels/microsoft-uet.cjs +11 -7
- package/dist/vendors/ads-and-pixels/reddit-pixel.cjs +9 -5
- package/dist/vendors/ads-and-pixels/snapchat-pixel.cjs +11 -7
- package/dist/vendors/ads-and-pixels/tiktok-pixel.cjs +9 -5
- package/dist/vendors/ads-and-pixels/x-pixel.cjs +9 -5
- package/dist/vendors/analytics/adobe-analytics.cjs +90 -0
- package/dist/vendors/analytics/adobe-analytics.js +49 -0
- package/dist/vendors/analytics/ahrefs-analytics.cjs +11 -7
- package/dist/vendors/analytics/amplitude.cjs +193 -0
- package/dist/vendors/analytics/amplitude.js +134 -0
- package/dist/vendors/analytics/clearbit.cjs +69 -0
- package/dist/vendors/analytics/clearbit.js +28 -0
- package/dist/vendors/analytics/cloudflare-web-analytics.cjs +11 -7
- package/dist/vendors/analytics/databuddy.cjs +11 -7
- package/dist/vendors/analytics/fathom-analytics.cjs +11 -7
- package/dist/vendors/analytics/google-tag.cjs +11 -7
- package/dist/vendors/analytics/heap.cjs +181 -0
- package/dist/vendors/analytics/heap.js +134 -0
- package/dist/vendors/analytics/hightouch.cjs +153 -0
- package/dist/vendors/analytics/hightouch.js +109 -0
- package/dist/vendors/analytics/hotjar.cjs +11 -7
- package/dist/vendors/analytics/logrocket.cjs +99 -0
- package/dist/vendors/analytics/logrocket.js +58 -0
- package/dist/vendors/analytics/matomo-analytics.cjs +9 -5
- package/dist/vendors/analytics/microsoft-clarity.cjs +75 -47
- package/dist/vendors/analytics/microsoft-clarity.js +64 -40
- package/dist/vendors/analytics/mixpanel-analytics.cjs +31 -16
- package/dist/vendors/analytics/mixpanel-analytics.js +22 -11
- package/dist/vendors/analytics/pirsch.cjs +108 -0
- package/dist/vendors/analytics/pirsch.js +67 -0
- package/dist/vendors/analytics/plausible-analytics.cjs +9 -5
- package/dist/vendors/analytics/posthog.cjs +63 -27
- package/dist/vendors/analytics/posthog.js +52 -20
- package/dist/vendors/analytics/promptwatch.cjs +11 -7
- package/dist/vendors/analytics/rudderstack.cjs +227 -0
- package/dist/vendors/analytics/rudderstack.js +183 -0
- package/dist/vendors/analytics/rybbit-analytics.cjs +9 -5
- package/dist/vendors/analytics/segment.cjs +9 -5
- package/dist/vendors/analytics/umami-analytics.cjs +9 -5
- package/dist/vendors/analytics/vercel-analytics.cjs +11 -7
- package/dist/vendors/functional/crisp.cjs +9 -5
- package/dist/vendors/functional/intercom.cjs +11 -7
- package/dist/vendors/tag-managers/google-tag-manager.cjs +11 -7
- package/dist-types/registry.d.ts +313 -241
- package/dist-types/types.d.ts +46 -4
- package/dist-types/vendors/ads-and-pixels/linkedin-insights.d.ts +18 -18
- package/dist-types/vendors/ads-and-pixels/meta-pixel.d.ts +21 -21
- package/dist-types/vendors/ads-and-pixels/microsoft-uet.d.ts +32 -32
- package/dist-types/vendors/ads-and-pixels/reddit-pixel.d.ts +19 -19
- package/dist-types/vendors/ads-and-pixels/snapchat-pixel.d.ts +16 -16
- package/dist-types/vendors/ads-and-pixels/tiktok-pixel.d.ts +28 -28
- package/dist-types/vendors/ads-and-pixels/x-pixel.d.ts +13 -13
- package/dist-types/vendors/analytics/adobe-analytics.d.ts +75 -0
- package/dist-types/vendors/analytics/ahrefs-analytics.d.ts +7 -7
- package/dist-types/vendors/analytics/amplitude.d.ts +234 -0
- package/dist-types/vendors/analytics/clearbit.d.ts +60 -0
- package/dist-types/vendors/analytics/cloudflare-web-analytics.d.ts +7 -7
- package/dist-types/vendors/analytics/databuddy.d.ts +25 -25
- package/dist-types/vendors/analytics/fathom-analytics.d.ts +11 -11
- package/dist-types/vendors/analytics/google-tag.d.ts +17 -17
- package/dist-types/vendors/analytics/heap.d.ts +316 -0
- package/dist-types/vendors/analytics/hightouch.d.ts +285 -0
- package/dist-types/vendors/analytics/hotjar.d.ts +14 -14
- package/dist-types/vendors/analytics/logrocket.d.ts +101 -0
- package/dist-types/vendors/analytics/microsoft-clarity.d.ts +42 -30
- package/dist-types/vendors/analytics/mixpanel-analytics.d.ts +40 -28
- package/dist-types/vendors/analytics/pirsch.d.ts +96 -0
- package/dist-types/vendors/analytics/plausible-analytics.d.ts +13 -13
- package/dist-types/vendors/analytics/posthog.d.ts +63 -45
- package/dist-types/vendors/analytics/promptwatch.d.ts +7 -7
- package/dist-types/vendors/analytics/rudderstack.d.ts +330 -0
- package/dist-types/vendors/analytics/rybbit-analytics.d.ts +18 -18
- package/dist-types/vendors/analytics/segment.d.ts +13 -13
- package/dist-types/vendors/analytics/umami-analytics.d.ts +12 -12
- package/dist-types/vendors/analytics/vercel-analytics.d.ts +16 -16
- package/dist-types/vendors/functional/crisp.d.ts +11 -11
- package/dist-types/vendors/functional/intercom.d.ts +16 -16
- package/dist-types/vendors/tag-managers/google-tag-manager.d.ts +18 -18
- package/docs/README.md +62 -0
- package/docs/frameworks/javascript/script-loader.md +356 -0
- package/docs/frameworks/next/script-loader.md +501 -0
- package/docs/frameworks/react/script-loader.md +555 -0
- package/docs/integrations/adobe-analytics.md +160 -0
- package/docs/integrations/ahrefs-analytics.md +157 -0
- package/docs/integrations/amplitude.md +230 -0
- package/docs/integrations/building-integrations.md +239 -0
- package/docs/integrations/clearbit.md +130 -0
- package/docs/integrations/cloudflare-web-analytics.md +126 -0
- package/docs/integrations/crisp.md +140 -0
- package/docs/integrations/databuddy.md +205 -0
- package/docs/integrations/fathom-analytics.md +150 -0
- package/docs/integrations/google-maps.md +263 -0
- package/docs/integrations/google-tag-manager.md +154 -0
- package/docs/integrations/google-tag.md +134 -0
- package/docs/integrations/heap.md +219 -0
- package/docs/integrations/hightouch.md +199 -0
- package/docs/integrations/hotjar.md +143 -0
- package/docs/integrations/intercom.md +144 -0
- package/docs/integrations/linkedin-insights.md +161 -0
- package/docs/integrations/logrocket.md +175 -0
- package/docs/integrations/matomo-analytics.md +171 -0
- package/docs/integrations/meta-pixel.md +412 -0
- package/docs/integrations/microsoft-clarity.md +173 -0
- package/docs/integrations/microsoft-uet.md +156 -0
- package/docs/integrations/mixpanel-analytics.md +130 -0
- package/docs/integrations/overview.md +149 -0
- package/docs/integrations/pirsch.md +142 -0
- package/docs/integrations/plausible-analytics.md +154 -0
- package/docs/integrations/posthog.md +258 -0
- package/docs/integrations/promptwatch.md +121 -0
- package/docs/integrations/reddit-pixel.md +241 -0
- package/docs/integrations/rudderstack.md +271 -0
- package/docs/integrations/rybbit-analytics.md +143 -0
- package/docs/integrations/segment.md +146 -0
- package/docs/integrations/snapchat-pixel.md +163 -0
- package/docs/integrations/tiktok-pixel.md +123 -0
- package/docs/integrations/umami-analytics.md +148 -0
- package/docs/integrations/vercel-analytics.md +141 -0
- package/docs/integrations/x-pixel.md +157 -0
- package/docs/integrations/youtube.md +193 -0
- package/docs/shared/react/guides/script-loader.md +311 -0
- package/package.json +61 -7
- package/readme.json +8 -4
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Script Loader
|
|
3
|
+
description: Reference page for script loader.
|
|
4
|
+
group: reference
|
|
5
|
+
---
|
|
6
|
+
The script loader manages third-party JavaScript based on consent state. You declare scripts in your provider's `scripts` option, and c15t decides when each script should load, stay loaded, unload, or receive a consent update.
|
|
7
|
+
|
|
8
|
+
Use it for analytics, pixels, tag managers, product analytics, and other vendor snippets that should not run until the right consent condition is satisfied. Prebuilt helpers live in [`@c15t/scripts`](/docs/integrations/overview); custom scripts can be declared directly when the vendor is specific to your app.
|
|
9
|
+
|
|
10
|
+
<PackageCommandTabs mode="install" command="@c15t/scripts" />
|
|
11
|
+
|
|
12
|
+
> ℹ️ **Info:**
|
|
13
|
+
> Start with the integrations overview before writing your own script. Built-in helpers encode vendor boot order, consent updates, and common defaults so you do not have to.
|
|
14
|
+
>
|
|
15
|
+
> 📝 **Note:**
|
|
16
|
+
> If you need a vendor c15t does not ship yet, see the custom integration guide. It explains when a one-off Script is enough and when to build a reusable manifest-backed helper.
|
|
17
|
+
>
|
|
18
|
+
> ℹ️ **Info:**
|
|
19
|
+
> The script loader handles JavaScript tags and callback lifecycles. For iframe-only embeds, use the iframe blocking pattern. For UI components such as maps or video players, combine consent state with a component-level placeholder or a dedicated renderable integration.
|
|
20
|
+
|
|
21
|
+
## Mental Model
|
|
22
|
+
|
|
23
|
+
Every script you register has the same lifecycle. c15t evaluates each script against the current consent state, then drives it through a small number of states:
|
|
24
|
+
|
|
25
|
+
1. **Pending** — registered but waiting for consent. Nothing is in the DOM yet.
|
|
26
|
+
2. **Loaded** — consent matched, c15t injected the script (or ran callbacks for callback-only scripts).
|
|
27
|
+
3. **Updated** — already loaded, consent state changed, `onConsentChange` ran so the SDK can react.
|
|
28
|
+
4. **Unloaded** — consent was revoked. c15t removed the script element unless you opted into persistence.
|
|
29
|
+
|
|
30
|
+
Four lifecycle callbacks let you hook into transitions: `onBeforeLoad`, `onLoad`, `onConsentChange`, and `onError`. Two flags — [`alwaysLoad`](#always-load) and [`persistAfterConsentRevoked`](#persist-after-revocation) — change how c15t treats consent boundaries. Everything else (DOM placement, ad-block evasion, dynamic management) is a refinement on top of this core model.
|
|
31
|
+
|
|
32
|
+
## Choose the Right Approach
|
|
33
|
+
|
|
34
|
+
Most projects mix more than one style. Pick the smallest one that keeps consent behavior obvious:
|
|
35
|
+
|
|
36
|
+
|Style|Use when|
|
|
37
|
+
|--|--|
|
|
38
|
+
|**Built-in helper** from `@c15t/scripts`|c15t already ships the vendor. See the [integrations overview](/docs/integrations/overview).|
|
|
39
|
+
|**Plain `Script`**|One-off app code with simple load and callback behavior.|
|
|
40
|
+
|**Callback-only `Script`**|Another package already loaded the SDK; c15t only synchronizes consent.|
|
|
41
|
+
|**Manifest-backed helper**|Reusable vendor integration with structured setup phases, queues, stubs, or a vendor consent API.|
|
|
42
|
+
|**Iframe / renderable integration**|Vendor exposes an iframe or React component, not just a `<script>` tag.|
|
|
43
|
+
|
|
44
|
+
## Script Types
|
|
45
|
+
|
|
46
|
+
### Standard Scripts
|
|
47
|
+
|
|
48
|
+
Standard scripts load an external JavaScript file via a `<script>` tag. This is the default for most analytics and pixel SDKs:
|
|
49
|
+
|
|
50
|
+
```tsx
|
|
51
|
+
{
|
|
52
|
+
id: 'analytics',
|
|
53
|
+
src: 'https://cdn.example.com/analytics.js',
|
|
54
|
+
category: 'measurement',
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Inline Scripts
|
|
59
|
+
|
|
60
|
+
Inline scripts execute JavaScript from `textContent` instead of loading a URL. Use these sparingly; a manifest-backed helper is usually better for reusable vendor code.
|
|
61
|
+
|
|
62
|
+
```tsx
|
|
63
|
+
{
|
|
64
|
+
id: 'gtag-config',
|
|
65
|
+
textContent: `
|
|
66
|
+
window.dataLayer = window.dataLayer || [];
|
|
67
|
+
function gtag(){dataLayer.push(arguments);}
|
|
68
|
+
gtag('js', new Date());
|
|
69
|
+
gtag('config', 'G-XXXXXX');
|
|
70
|
+
`,
|
|
71
|
+
category: 'measurement',
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Callback-Only Scripts
|
|
76
|
+
|
|
77
|
+
Callback-only scripts do not inject a script tag. They run lifecycle callbacks when consent allows them to. Use this when another package has already loaded the SDK and c15t only needs to drive consent:
|
|
78
|
+
|
|
79
|
+
```tsx
|
|
80
|
+
{
|
|
81
|
+
id: 'posthog-consent',
|
|
82
|
+
callbackOnly: true,
|
|
83
|
+
category: 'measurement',
|
|
84
|
+
onLoad: ({ hasConsent }) => {
|
|
85
|
+
if (hasConsent) {
|
|
86
|
+
posthog.opt_in_capturing();
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
onConsentChange: ({ hasConsent }) => {
|
|
90
|
+
if (hasConsent) {
|
|
91
|
+
posthog.opt_in_capturing();
|
|
92
|
+
} else {
|
|
93
|
+
posthog.opt_out_capturing();
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Manifest-Backed Helpers
|
|
100
|
+
|
|
101
|
+
Built-in integrations in `@c15t/scripts` are manifest-backed. A manifest describes vendor setup as structured phases, then c15t compiles it into a `Script`. Manifests keep queue stubs, script URLs, consent signaling, and post-load work consistent across apps and they are safe to ship from a server.
|
|
102
|
+
|
|
103
|
+
Use a manifest-backed helper when:
|
|
104
|
+
|
|
105
|
+
* the integration should be reused across projects,
|
|
106
|
+
* the vendor snippet has ordered setup steps,
|
|
107
|
+
* the vendor exposes a consent API,
|
|
108
|
+
* or you plan to contribute the integration back to c15t.
|
|
109
|
+
|
|
110
|
+
Read the [custom integration guide](/docs/integrations/building-integrations) for the manifest contract, phases, and testing checklist.
|
|
111
|
+
|
|
112
|
+
### Iframe And Renderable Integrations
|
|
113
|
+
|
|
114
|
+
Some vendors are not just script tags. YouTube embeds, maps, calendars, and checkout widgets often need a visible component, a placeholder, or an iframe.
|
|
115
|
+
|
|
116
|
+
* For iframe-only embeds, gate the iframe `src` with the [iframe blocking](/docs/frameworks/react/iframe-blocking) pattern instead of loading a script just to hide an iframe.
|
|
117
|
+
* For SDK-backed UI, use the script loader for the shared SDK and render the component only when consent and SDK readiness agree.
|
|
118
|
+
* Use `YouTubeEmbed` for the iframe-only YouTube candidate and `GoogleMap` for the callback-based SDK candidate.
|
|
119
|
+
* Use `useConsentScript()` when building custom wrappers. It registers scripts through the consent store, follows `loadedScripts`, and returns a promise-shaped readiness contract for callback-based SDKs.
|
|
120
|
+
|
|
121
|
+
## Lifecycle Callbacks
|
|
122
|
+
|
|
123
|
+
Every script supports four callbacks. Each receives a `ScriptCallbackInfo` payload (id, element, hasConsent, consents):
|
|
124
|
+
|
|
125
|
+
* `onBeforeLoad` — runs before the script tag is injected. Create globals, queues, or vendor stubs here.
|
|
126
|
+
* `onLoad` — runs after the browser loads the script. Call vendor `init()` APIs here.
|
|
127
|
+
* `onConsentChange` — runs for loaded scripts when consent changes. Forward the new consent state to the vendor SDK.
|
|
128
|
+
* `onError` — runs when the script fails to load. Record diagnostics or render a fallback.
|
|
129
|
+
|
|
130
|
+
```tsx
|
|
131
|
+
{
|
|
132
|
+
id: 'analytics',
|
|
133
|
+
src: 'https://analytics.example.com/v2.js',
|
|
134
|
+
category: 'measurement',
|
|
135
|
+
onBeforeLoad: ({ id }) => {
|
|
136
|
+
window.analyticsQueue = window.analyticsQueue || [];
|
|
137
|
+
},
|
|
138
|
+
onLoad: () => {
|
|
139
|
+
window.analytics.init('my-key');
|
|
140
|
+
},
|
|
141
|
+
onError: ({ error }) => {
|
|
142
|
+
console.error('Failed to load analytics:', error);
|
|
143
|
+
},
|
|
144
|
+
onConsentChange: ({ hasConsent }) => {
|
|
145
|
+
window.analytics.setConsent(hasConsent);
|
|
146
|
+
},
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## Consent Conditions
|
|
151
|
+
|
|
152
|
+
The `category` field accepts a `HasCondition`. It can be a single consent category or a logical expression:
|
|
153
|
+
|
|
154
|
+
```tsx
|
|
155
|
+
// Simple: requires measurement consent
|
|
156
|
+
{ category: 'measurement' }
|
|
157
|
+
|
|
158
|
+
// AND: requires both measurement and marketing
|
|
159
|
+
{ category: { and: ['measurement', 'marketing'] } }
|
|
160
|
+
|
|
161
|
+
// OR: requires either measurement or marketing
|
|
162
|
+
{ category: { or: ['measurement', 'marketing'] } }
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Consent categories use the same names as the rest of c15t (`necessary`, `functionality`, `experience`, `measurement`, `marketing`).
|
|
166
|
+
|
|
167
|
+
## Persistence Options
|
|
168
|
+
|
|
169
|
+
### Always Load
|
|
170
|
+
|
|
171
|
+
`alwaysLoad` loads the script regardless of whether its category is currently granted. Use it only when the vendor must be present early **and** has a reliable consent API of its own — Google Tag Manager with Consent Mode is the canonical example.
|
|
172
|
+
|
|
173
|
+
```tsx
|
|
174
|
+
{
|
|
175
|
+
id: 'google-tag-manager',
|
|
176
|
+
src: 'https://www.googletagmanager.com/gtm.js?id=GTM-XXXX',
|
|
177
|
+
category: 'measurement',
|
|
178
|
+
alwaysLoad: true,
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
When `alwaysLoad` is on, `onConsentChange` becomes mandatory: it is how the loaded SDK learns about every transition.
|
|
183
|
+
|
|
184
|
+
> ⚠️ **Warning:**
|
|
185
|
+
> alwaysLoad shifts compliance responsibility to the vendor integration. Make sure the script receives denied-by-default consent signals before it can track.
|
|
186
|
+
|
|
187
|
+
### Persist After Revocation
|
|
188
|
+
|
|
189
|
+
`persistAfterConsentRevoked` keeps a script in the page after consent is revoked instead of unloading it. Use it only when the vendor exposes a runtime consent toggle — otherwise unloading is safer because removing the element guarantees the SDK stops.
|
|
190
|
+
|
|
191
|
+
```tsx
|
|
192
|
+
{
|
|
193
|
+
id: 'error-tracking',
|
|
194
|
+
src: 'https://errors.example.com/track.js',
|
|
195
|
+
category: 'measurement',
|
|
196
|
+
persistAfterConsentRevoked: true,
|
|
197
|
+
onConsentChange: ({ hasConsent }) => {
|
|
198
|
+
window.ErrorTracker.setConsent(hasConsent);
|
|
199
|
+
},
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
As with `alwaysLoad`, `onConsentChange` is how the persisted SDK learns about consent updates.
|
|
204
|
+
|
|
205
|
+
### `alwaysLoad` vs `persistAfterConsentRevoked`
|
|
206
|
+
|
|
207
|
+
These two flags answer different questions. Use this table to keep them straight:
|
|
208
|
+
|
|
209
|
+
|Question|`alwaysLoad`|`persistAfterConsentRevoked`|
|
|
210
|
+
|--|--|--|
|
|
211
|
+
|Loads before consent is granted?|Yes|No (waits for consent like a normal script)|
|
|
212
|
+
|Stays loaded after consent is revoked?|Yes|Yes|
|
|
213
|
+
|Requires a vendor consent API?|Yes|Yes|
|
|
214
|
+
|
|
215
|
+
## DOM Placement
|
|
216
|
+
|
|
217
|
+
Control where the script is injected and whether the element id is anonymized:
|
|
218
|
+
|
|
219
|
+
```tsx
|
|
220
|
+
{
|
|
221
|
+
id: 'widget',
|
|
222
|
+
src: 'https://widget.example.com/embed.js',
|
|
223
|
+
category: 'experience',
|
|
224
|
+
target: 'body', // 'head' (default) or 'body'
|
|
225
|
+
anonymizeId: true, // default: true, hides the c15t script id from ad blockers
|
|
226
|
+
nonce: 'abc123', // optional CSP nonce
|
|
227
|
+
}
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
Set `anonymizeId: false` only when another script or test needs a stable DOM id. Pass `nonce` when your CSP requires it; c15t applies it directly to the generated `<script>` element.
|
|
231
|
+
|
|
232
|
+
You usually do not need a per-script `nonce`. Setting `nonce` once on the provider covers every injected script (and the theme stylesheet); a per-script value overrides it for that script alone.
|
|
233
|
+
|
|
234
|
+
## Dynamic Management
|
|
235
|
+
|
|
236
|
+
Framework packages expose script-manager methods so integrations can be added, removed, or inspected at runtime. Use this for tenant-specific tools, feature-flagged scripts, or vendors that are configured after sign-in:
|
|
237
|
+
|
|
238
|
+
* `setScripts(scripts)` — registers script definitions and immediately evaluates them against consent.
|
|
239
|
+
* `removeScript(id)` — removes a definition and unloads its element if needed.
|
|
240
|
+
* `isScriptLoaded(id)` — returns whether c15t has loaded a script.
|
|
241
|
+
* `getLoadedScriptIds()` — returns every currently loaded script id.
|
|
242
|
+
|
|
243
|
+
Dynamic scripts should still use stable ids. If the same vendor is added repeatedly with different ids, c15t treats each call as a new script.
|
|
244
|
+
|
|
245
|
+
## Calling Vendor APIs From Your App
|
|
246
|
+
|
|
247
|
+
The script loader controls **when the vendor SDK loads**. It does not intercept calls your application code makes to that SDK afterwards. Whether your event calls are safe before consent is granted depends on the script's persistence flags:
|
|
248
|
+
|
|
249
|
+
|Vendor pattern|What c15t does|What your app code must do|
|
|
250
|
+
|--|--|--|
|
|
251
|
+
|Consent-gated load, unloaded on revoke (e.g. cookieless analytics)|Script not in DOM until consent granted; removed on revoke. Global is `undefined` outside that window.|**Guard every call.** Unguarded `window.vendor.track(...)` throws when the global is absent.|
|
|
252
|
+
|Consent-gated load with `persistAfterConsentRevoked` (e.g. Meta Pixel)|Script not in DOM until consent granted; stays after revoke. c15t calls vendor's consent-revoke API on revocation.|Guard calls only for the pre-initial-consent window. Once loaded, the SDK handles its own suppression.|
|
|
253
|
+
|`alwaysLoad: true` with a vendor consent API (e.g. GTM, gtag, Databuddy, PostHog)|Script in DOM on page start; c15t signals consent state through the vendor's API.|Calls are safe — the vendor SDK suppresses transmission when consent is denied.|
|
|
254
|
+
|No app-facing API (e.g. Cloudflare Web Analytics)|Script in/out of DOM based on consent. Tracking is fully automatic.|Nothing to guard.|
|
|
255
|
+
|
|
256
|
+
The safe pattern in React is to read consent state through `useConsentManager().has(category)` before calling the SDK:
|
|
257
|
+
|
|
258
|
+
```tsx
|
|
259
|
+
import { useCallback } from 'react';
|
|
260
|
+
import { useConsentManager } from '@c15t/react';
|
|
261
|
+
|
|
262
|
+
function useTrackSignup() {
|
|
263
|
+
const { has } = useConsentManager();
|
|
264
|
+
|
|
265
|
+
return useCallback(() => {
|
|
266
|
+
if (has('measurement')) {
|
|
267
|
+
window.fathom?.trackEvent('signup');
|
|
268
|
+
}
|
|
269
|
+
}, [has]);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function SignupButton() {
|
|
273
|
+
const trackSignup = useTrackSignup();
|
|
274
|
+
|
|
275
|
+
return <button onClick={trackSignup}>Sign up</button>;
|
|
276
|
+
}
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
From non-React code, read the consent store directly:
|
|
280
|
+
|
|
281
|
+
```ts
|
|
282
|
+
import { getOrCreateConsentRuntime } from 'c15t';
|
|
283
|
+
|
|
284
|
+
const { consentStore } = getOrCreateConsentRuntime();
|
|
285
|
+
|
|
286
|
+
if (consentStore.getState().has('measurement')) {
|
|
287
|
+
window.fathom?.trackEvent('signup');
|
|
288
|
+
}
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
Each [integration page](/docs/integrations/overview) includes a vendor-specific **Tracking events in your app** block that names which pattern applies.
|
|
292
|
+
|
|
293
|
+
## Debugging Checklist
|
|
294
|
+
|
|
295
|
+
When a script does not behave as expected:
|
|
296
|
+
|
|
297
|
+
1. Confirm the script's `category` matches the consent that has been granted.
|
|
298
|
+
2. Check whether the script is `alwaysLoad` or consent-gated.
|
|
299
|
+
3. Confirm `onBeforeLoad` creates any globals before the vendor code reads them.
|
|
300
|
+
4. Confirm `onConsentChange` updates persisted or always-loaded scripts when consent changes.
|
|
301
|
+
5. Check whether the browser or an ad blocker blocked the request.
|
|
302
|
+
6. Use c15t devtools to inspect script lifecycle events when available.
|
|
303
|
+
|
|
304
|
+
## API Reference
|
|
305
|
+
|
|
306
|
+
|Property|Value|
|
|
307
|
+
|:--|:--|
|
|
308
|
+
|Type Name|\`Script\`|
|
|
309
|
+
|Source Path|\`./packages/core/src/libs/script-loader/types.ts\`|
|
|
310
|
+
|
|
311
|
+
\*ExtractedTypeTable: Could not extract "Script" from "./packages/core/src/libs/script-loader/types.ts" using base path "/home/runner/work/c15t/c15t". Verify the path/name and that the file is included by your tsconfig.\*
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@c15t/scripts",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.2.0-canary-20260804162155",
|
|
4
|
+
"description": "Consent-aware script integrations for Google Tag Manager, Google Consent Mode v2, GA4, Google Ads, Meta Pixel, and more.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"c15t",
|
|
7
7
|
"script-loader",
|
|
@@ -14,14 +14,23 @@
|
|
|
14
14
|
"google-tag",
|
|
15
15
|
"ga4",
|
|
16
16
|
"google-ads",
|
|
17
|
+
"adobe-analytics",
|
|
18
|
+
"amplitude",
|
|
19
|
+
"heap",
|
|
20
|
+
"hightouch",
|
|
21
|
+
"rudderstack",
|
|
22
|
+
"logrocket",
|
|
17
23
|
"meta-pixel",
|
|
18
24
|
"posthog",
|
|
25
|
+
"pirsch",
|
|
26
|
+
"clearbit",
|
|
19
27
|
"tiktok-pixel",
|
|
20
28
|
"linkedin-insights",
|
|
21
29
|
"microsoft-uet",
|
|
22
30
|
"x-pixel",
|
|
23
31
|
"analytics-consent",
|
|
24
32
|
"consent-mode",
|
|
33
|
+
"consent-mode-v2",
|
|
25
34
|
"privacy",
|
|
26
35
|
"cmp"
|
|
27
36
|
],
|
|
@@ -38,16 +47,31 @@
|
|
|
38
47
|
"sideEffects": false,
|
|
39
48
|
"type": "module",
|
|
40
49
|
"exports": {
|
|
50
|
+
"./adobe-analytics": {
|
|
51
|
+
"types": "./dist-types/vendors/analytics/adobe-analytics.d.ts",
|
|
52
|
+
"import": "./dist/vendors/analytics/adobe-analytics.js",
|
|
53
|
+
"require": "./dist/vendors/analytics/adobe-analytics.cjs"
|
|
54
|
+
},
|
|
41
55
|
"./ahrefs-analytics": {
|
|
42
56
|
"types": "./dist-types/vendors/analytics/ahrefs-analytics.d.ts",
|
|
43
57
|
"import": "./dist/vendors/analytics/ahrefs-analytics.js",
|
|
44
58
|
"require": "./dist/vendors/analytics/ahrefs-analytics.cjs"
|
|
45
59
|
},
|
|
60
|
+
"./amplitude": {
|
|
61
|
+
"types": "./dist-types/vendors/analytics/amplitude.d.ts",
|
|
62
|
+
"import": "./dist/vendors/analytics/amplitude.js",
|
|
63
|
+
"require": "./dist/vendors/analytics/amplitude.cjs"
|
|
64
|
+
},
|
|
46
65
|
"./cloudflare-web-analytics": {
|
|
47
66
|
"types": "./dist-types/vendors/analytics/cloudflare-web-analytics.d.ts",
|
|
48
67
|
"import": "./dist/vendors/analytics/cloudflare-web-analytics.js",
|
|
49
68
|
"require": "./dist/vendors/analytics/cloudflare-web-analytics.cjs"
|
|
50
69
|
},
|
|
70
|
+
"./clearbit": {
|
|
71
|
+
"types": "./dist-types/vendors/analytics/clearbit.d.ts",
|
|
72
|
+
"import": "./dist/vendors/analytics/clearbit.js",
|
|
73
|
+
"require": "./dist/vendors/analytics/clearbit.cjs"
|
|
74
|
+
},
|
|
51
75
|
"./microsoft-clarity": {
|
|
52
76
|
"types": "./dist-types/vendors/analytics/microsoft-clarity.d.ts",
|
|
53
77
|
"import": "./dist/vendors/analytics/microsoft-clarity.js",
|
|
@@ -63,11 +87,31 @@
|
|
|
63
87
|
"import": "./dist/vendors/analytics/fathom-analytics.js",
|
|
64
88
|
"require": "./dist/vendors/analytics/fathom-analytics.cjs"
|
|
65
89
|
},
|
|
90
|
+
"./heap": {
|
|
91
|
+
"types": "./dist-types/vendors/analytics/heap.d.ts",
|
|
92
|
+
"import": "./dist/vendors/analytics/heap.js",
|
|
93
|
+
"require": "./dist/vendors/analytics/heap.cjs"
|
|
94
|
+
},
|
|
66
95
|
"./hotjar": {
|
|
67
96
|
"types": "./dist-types/vendors/analytics/hotjar.d.ts",
|
|
68
97
|
"import": "./dist/vendors/analytics/hotjar.js",
|
|
69
98
|
"require": "./dist/vendors/analytics/hotjar.cjs"
|
|
70
99
|
},
|
|
100
|
+
"./hightouch": {
|
|
101
|
+
"types": "./dist-types/vendors/analytics/hightouch.d.ts",
|
|
102
|
+
"import": "./dist/vendors/analytics/hightouch.js",
|
|
103
|
+
"require": "./dist/vendors/analytics/hightouch.cjs"
|
|
104
|
+
},
|
|
105
|
+
"./rudderstack": {
|
|
106
|
+
"types": "./dist-types/vendors/analytics/rudderstack.d.ts",
|
|
107
|
+
"import": "./dist/vendors/analytics/rudderstack.js",
|
|
108
|
+
"require": "./dist/vendors/analytics/rudderstack.cjs"
|
|
109
|
+
},
|
|
110
|
+
"./logrocket": {
|
|
111
|
+
"types": "./dist-types/vendors/analytics/logrocket.d.ts",
|
|
112
|
+
"import": "./dist/vendors/analytics/logrocket.js",
|
|
113
|
+
"require": "./dist/vendors/analytics/logrocket.cjs"
|
|
114
|
+
},
|
|
71
115
|
"./google-tag": {
|
|
72
116
|
"types": "./dist-types/vendors/analytics/google-tag.d.ts",
|
|
73
117
|
"import": "./dist/vendors/analytics/google-tag.js",
|
|
@@ -83,6 +127,11 @@
|
|
|
83
127
|
"import": "./dist/vendors/analytics/mixpanel-analytics.js",
|
|
84
128
|
"require": "./dist/vendors/analytics/mixpanel-analytics.cjs"
|
|
85
129
|
},
|
|
130
|
+
"./pirsch": {
|
|
131
|
+
"types": "./dist-types/vendors/analytics/pirsch.d.ts",
|
|
132
|
+
"import": "./dist/vendors/analytics/pirsch.js",
|
|
133
|
+
"require": "./dist/vendors/analytics/pirsch.cjs"
|
|
134
|
+
},
|
|
86
135
|
"./plausible-analytics": {
|
|
87
136
|
"types": "./dist-types/vendors/analytics/plausible-analytics.d.ts",
|
|
88
137
|
"import": "./dist/vendors/analytics/plausible-analytics.js",
|
|
@@ -181,15 +230,19 @@
|
|
|
181
230
|
},
|
|
182
231
|
"files": [
|
|
183
232
|
"dist",
|
|
184
|
-
"dist-types"
|
|
233
|
+
"dist-types",
|
|
234
|
+
"AGENTS.md",
|
|
235
|
+
"docs"
|
|
185
236
|
],
|
|
186
237
|
"scripts": {
|
|
187
|
-
"build": "rslib build && bun ../../scripts/normalize-dist-types.mjs",
|
|
188
|
-
"
|
|
238
|
+
"build": "rslib build && bun ../../scripts/normalize-dist-types.mjs && bun ../../scripts/generate-package-docs.ts @c15t/scripts",
|
|
239
|
+
"build:docs": "bun ../../scripts/generate-package-docs.ts @c15t/scripts",
|
|
240
|
+
"check-types": "tsc --noEmit && tsc -p live-vendors --noEmit",
|
|
189
241
|
"dev": "sh -c 'rslib build --no-dts --no-clean && rslib build --watch --no-dts --no-clean'",
|
|
190
242
|
"fmt": "bun biome format --write . && bun biome check --formatter-enabled=false --linter-enabled=false --write",
|
|
191
|
-
"lint": "bun biome lint ./src",
|
|
243
|
+
"lint": "bun biome lint ./src ./live-vendors",
|
|
192
244
|
"test": "vitest run",
|
|
245
|
+
"test:live-vendors": "bun --tsconfig-override live-vendors/tsconfig.json live-vendors/runner.ts",
|
|
193
246
|
"test:watch": "vitest"
|
|
194
247
|
},
|
|
195
248
|
"browserslist": [
|
|
@@ -200,7 +253,8 @@
|
|
|
200
253
|
"devDependencies": {
|
|
201
254
|
"@c15t/typescript-config": "0.0.1",
|
|
202
255
|
"@c15t/vitest-config": "1.0.0",
|
|
203
|
-
"c15t": "2.
|
|
256
|
+
"c15t": "2.2.0-canary-20260731105620",
|
|
257
|
+
"playwright": "1.58.2"
|
|
204
258
|
},
|
|
205
259
|
"publishConfig": {
|
|
206
260
|
"access": "public"
|
package/readme.json
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"title": "@c15t/scripts: Prebuilt Consent Scripts",
|
|
3
|
-
"description": "
|
|
3
|
+
"description": "Consent-aware script integrations for Google Tag Manager, Google Consent Mode v2, GA4, Google Ads, Meta Pixel, analytics tools, pixels, tag managers, and widgets.",
|
|
4
4
|
"features": [
|
|
5
|
-
"Prebuilt script
|
|
5
|
+
"Prebuilt script loaders for popular analytics, advertising, marketing, and functional tools",
|
|
6
|
+
"Google Tag Manager support with Google Consent Mode v2 defaults and consent updates",
|
|
7
|
+
"Google Analytics 4 and Google Ads support through gtag.js",
|
|
8
|
+
"Consent-gated Meta Pixel and conversion pixel loading",
|
|
6
9
|
"Easy integration with c15t's script loader",
|
|
7
10
|
"Configuration options for each supported vendor",
|
|
8
|
-
"Supported vendors include Google Tag Manager, Meta Pixel, PostHog, TikTok Pixel, LinkedIn Insights, Microsoft UET,
|
|
11
|
+
"Supported vendors include Google Tag Manager, Meta Pixel, PostHog, TikTok Pixel, LinkedIn Insights, Microsoft UET, X Pixel, Reddit Pixel, Snapchat Pixel, Intercom, Crisp, and more"
|
|
9
12
|
],
|
|
10
13
|
"docsLink": "https://c15t.com/docs/integrations",
|
|
11
14
|
"showCLIGeneration": false,
|
|
12
15
|
"customSections": {
|
|
13
|
-
"
|
|
16
|
+
"Integrations": "- **Google Tag Manager**: Loads with Google Consent Mode v2 defaults set to denied; GTM-managed tags fire only once matching consent is granted ([guide](https://c15t.com/docs/integrations/google-tag-manager))\n- **Google Analytics 4 + Google Ads (gtag.js)**: Consent Mode v2 defaults and consent updates when users make a choice ([guide](https://c15t.com/docs/integrations/google-tag))\n- **Conversion pixels**: Meta Pixel, TikTok Pixel, LinkedIn Insights, Microsoft UET (Microsoft Ads), X Pixel, Reddit Pixel, Snapchat Pixel\n- **Analytics**: PostHog, Segment, Mixpanel, Microsoft Clarity, Hotjar, Plausible, Fathom, Matomo, Umami, Vercel Analytics\n- **Chat widgets**: Intercom, Crisp",
|
|
17
|
+
"Example": "```ts\nimport { googleTagManager } from '@c15t/scripts/google-tag-manager'\nimport { metaPixel } from '@c15t/scripts/meta-pixel'\n\nconst scripts = [\n googleTagManager({ id: 'GTM-XXXXXX' }),\n metaPixel({ pixelId: '000000000000000' }),\n]\n```"
|
|
14
18
|
}
|
|
15
19
|
}
|