@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.
Files changed (140) hide show
  1. package/AGENTS.md +62 -0
  2. package/README.md +32 -20
  3. package/dist/e2e-test-utils.cjs +51 -10
  4. package/dist/e2e-test-utils.js +37 -3
  5. package/dist/engine/compile.cjs +9 -5
  6. package/dist/engine/runtime.cjs +103 -17
  7. package/dist/engine/runtime.js +94 -12
  8. package/dist/registry.cjs +97 -12
  9. package/dist/registry.js +80 -0
  10. package/dist/resolve.cjs +9 -5
  11. package/dist/types.cjs +17 -13
  12. package/dist/vendors/_shared/attributes.cjs +13 -9
  13. package/dist/vendors/_shared/google-consent.cjs +14 -9
  14. package/dist/vendors/_shared/install-builders.cjs +12 -8
  15. package/dist/vendors/_shared/script-url.cjs +16 -12
  16. package/dist/vendors/ads-and-pixels/linkedin-insights.cjs +9 -5
  17. package/dist/vendors/ads-and-pixels/meta-pixel.cjs +13 -9
  18. package/dist/vendors/ads-and-pixels/microsoft-uet.cjs +11 -7
  19. package/dist/vendors/ads-and-pixels/reddit-pixel.cjs +9 -5
  20. package/dist/vendors/ads-and-pixels/snapchat-pixel.cjs +11 -7
  21. package/dist/vendors/ads-and-pixels/tiktok-pixel.cjs +9 -5
  22. package/dist/vendors/ads-and-pixels/x-pixel.cjs +9 -5
  23. package/dist/vendors/analytics/adobe-analytics.cjs +90 -0
  24. package/dist/vendors/analytics/adobe-analytics.js +49 -0
  25. package/dist/vendors/analytics/ahrefs-analytics.cjs +11 -7
  26. package/dist/vendors/analytics/amplitude.cjs +193 -0
  27. package/dist/vendors/analytics/amplitude.js +134 -0
  28. package/dist/vendors/analytics/clearbit.cjs +69 -0
  29. package/dist/vendors/analytics/clearbit.js +28 -0
  30. package/dist/vendors/analytics/cloudflare-web-analytics.cjs +11 -7
  31. package/dist/vendors/analytics/databuddy.cjs +11 -7
  32. package/dist/vendors/analytics/fathom-analytics.cjs +11 -7
  33. package/dist/vendors/analytics/google-tag.cjs +11 -7
  34. package/dist/vendors/analytics/heap.cjs +181 -0
  35. package/dist/vendors/analytics/heap.js +134 -0
  36. package/dist/vendors/analytics/hightouch.cjs +153 -0
  37. package/dist/vendors/analytics/hightouch.js +109 -0
  38. package/dist/vendors/analytics/hotjar.cjs +11 -7
  39. package/dist/vendors/analytics/logrocket.cjs +99 -0
  40. package/dist/vendors/analytics/logrocket.js +58 -0
  41. package/dist/vendors/analytics/matomo-analytics.cjs +9 -5
  42. package/dist/vendors/analytics/microsoft-clarity.cjs +75 -47
  43. package/dist/vendors/analytics/microsoft-clarity.js +64 -40
  44. package/dist/vendors/analytics/mixpanel-analytics.cjs +31 -16
  45. package/dist/vendors/analytics/mixpanel-analytics.js +22 -11
  46. package/dist/vendors/analytics/pirsch.cjs +108 -0
  47. package/dist/vendors/analytics/pirsch.js +67 -0
  48. package/dist/vendors/analytics/plausible-analytics.cjs +9 -5
  49. package/dist/vendors/analytics/posthog.cjs +63 -27
  50. package/dist/vendors/analytics/posthog.js +52 -20
  51. package/dist/vendors/analytics/promptwatch.cjs +11 -7
  52. package/dist/vendors/analytics/rudderstack.cjs +227 -0
  53. package/dist/vendors/analytics/rudderstack.js +183 -0
  54. package/dist/vendors/analytics/rybbit-analytics.cjs +9 -5
  55. package/dist/vendors/analytics/segment.cjs +9 -5
  56. package/dist/vendors/analytics/umami-analytics.cjs +9 -5
  57. package/dist/vendors/analytics/vercel-analytics.cjs +11 -7
  58. package/dist/vendors/functional/crisp.cjs +9 -5
  59. package/dist/vendors/functional/intercom.cjs +11 -7
  60. package/dist/vendors/tag-managers/google-tag-manager.cjs +11 -7
  61. package/dist-types/registry.d.ts +313 -241
  62. package/dist-types/types.d.ts +46 -4
  63. package/dist-types/vendors/ads-and-pixels/linkedin-insights.d.ts +18 -18
  64. package/dist-types/vendors/ads-and-pixels/meta-pixel.d.ts +21 -21
  65. package/dist-types/vendors/ads-and-pixels/microsoft-uet.d.ts +32 -32
  66. package/dist-types/vendors/ads-and-pixels/reddit-pixel.d.ts +19 -19
  67. package/dist-types/vendors/ads-and-pixels/snapchat-pixel.d.ts +16 -16
  68. package/dist-types/vendors/ads-and-pixels/tiktok-pixel.d.ts +28 -28
  69. package/dist-types/vendors/ads-and-pixels/x-pixel.d.ts +13 -13
  70. package/dist-types/vendors/analytics/adobe-analytics.d.ts +75 -0
  71. package/dist-types/vendors/analytics/ahrefs-analytics.d.ts +7 -7
  72. package/dist-types/vendors/analytics/amplitude.d.ts +234 -0
  73. package/dist-types/vendors/analytics/clearbit.d.ts +60 -0
  74. package/dist-types/vendors/analytics/cloudflare-web-analytics.d.ts +7 -7
  75. package/dist-types/vendors/analytics/databuddy.d.ts +25 -25
  76. package/dist-types/vendors/analytics/fathom-analytics.d.ts +11 -11
  77. package/dist-types/vendors/analytics/google-tag.d.ts +17 -17
  78. package/dist-types/vendors/analytics/heap.d.ts +316 -0
  79. package/dist-types/vendors/analytics/hightouch.d.ts +285 -0
  80. package/dist-types/vendors/analytics/hotjar.d.ts +14 -14
  81. package/dist-types/vendors/analytics/logrocket.d.ts +101 -0
  82. package/dist-types/vendors/analytics/microsoft-clarity.d.ts +42 -30
  83. package/dist-types/vendors/analytics/mixpanel-analytics.d.ts +40 -28
  84. package/dist-types/vendors/analytics/pirsch.d.ts +96 -0
  85. package/dist-types/vendors/analytics/plausible-analytics.d.ts +13 -13
  86. package/dist-types/vendors/analytics/posthog.d.ts +63 -45
  87. package/dist-types/vendors/analytics/promptwatch.d.ts +7 -7
  88. package/dist-types/vendors/analytics/rudderstack.d.ts +330 -0
  89. package/dist-types/vendors/analytics/rybbit-analytics.d.ts +18 -18
  90. package/dist-types/vendors/analytics/segment.d.ts +13 -13
  91. package/dist-types/vendors/analytics/umami-analytics.d.ts +12 -12
  92. package/dist-types/vendors/analytics/vercel-analytics.d.ts +16 -16
  93. package/dist-types/vendors/functional/crisp.d.ts +11 -11
  94. package/dist-types/vendors/functional/intercom.d.ts +16 -16
  95. package/dist-types/vendors/tag-managers/google-tag-manager.d.ts +18 -18
  96. package/docs/README.md +62 -0
  97. package/docs/frameworks/javascript/script-loader.md +356 -0
  98. package/docs/frameworks/next/script-loader.md +501 -0
  99. package/docs/frameworks/react/script-loader.md +555 -0
  100. package/docs/integrations/adobe-analytics.md +160 -0
  101. package/docs/integrations/ahrefs-analytics.md +157 -0
  102. package/docs/integrations/amplitude.md +230 -0
  103. package/docs/integrations/building-integrations.md +239 -0
  104. package/docs/integrations/clearbit.md +130 -0
  105. package/docs/integrations/cloudflare-web-analytics.md +126 -0
  106. package/docs/integrations/crisp.md +140 -0
  107. package/docs/integrations/databuddy.md +205 -0
  108. package/docs/integrations/fathom-analytics.md +150 -0
  109. package/docs/integrations/google-maps.md +263 -0
  110. package/docs/integrations/google-tag-manager.md +154 -0
  111. package/docs/integrations/google-tag.md +134 -0
  112. package/docs/integrations/heap.md +219 -0
  113. package/docs/integrations/hightouch.md +199 -0
  114. package/docs/integrations/hotjar.md +143 -0
  115. package/docs/integrations/intercom.md +144 -0
  116. package/docs/integrations/linkedin-insights.md +161 -0
  117. package/docs/integrations/logrocket.md +175 -0
  118. package/docs/integrations/matomo-analytics.md +171 -0
  119. package/docs/integrations/meta-pixel.md +412 -0
  120. package/docs/integrations/microsoft-clarity.md +173 -0
  121. package/docs/integrations/microsoft-uet.md +156 -0
  122. package/docs/integrations/mixpanel-analytics.md +130 -0
  123. package/docs/integrations/overview.md +149 -0
  124. package/docs/integrations/pirsch.md +142 -0
  125. package/docs/integrations/plausible-analytics.md +154 -0
  126. package/docs/integrations/posthog.md +258 -0
  127. package/docs/integrations/promptwatch.md +121 -0
  128. package/docs/integrations/reddit-pixel.md +241 -0
  129. package/docs/integrations/rudderstack.md +271 -0
  130. package/docs/integrations/rybbit-analytics.md +143 -0
  131. package/docs/integrations/segment.md +146 -0
  132. package/docs/integrations/snapchat-pixel.md +163 -0
  133. package/docs/integrations/tiktok-pixel.md +123 -0
  134. package/docs/integrations/umami-analytics.md +148 -0
  135. package/docs/integrations/vercel-analytics.md +141 -0
  136. package/docs/integrations/x-pixel.md +157 -0
  137. package/docs/integrations/youtube.md +193 -0
  138. package/docs/shared/react/guides/script-loader.md +311 -0
  139. package/package.json +61 -7
  140. package/readme.json +8 -4
@@ -14,44 +14,44 @@ declare global {
14
14
  * - Signals consent state via `gtag('consent', 'default'|'update', ...)`
15
15
  */
16
16
  export declare const googleTagManagerManifest: {
17
- readonly vendor: "google-tag-manager";
18
- readonly category: "necessary";
17
+ readonly kind: "c15t.vendor-manifest";
18
+ readonly schemaVersion: 1;
19
+ readonly vendor: 'google-tag-manager';
20
+ readonly category: 'necessary';
19
21
  readonly alwaysLoad: true;
20
22
  readonly bootstrap: [{
21
- readonly type: "setGlobal";
22
- readonly name: "dataLayer";
23
+ readonly type: 'setGlobal';
24
+ readonly name: 'dataLayer';
23
25
  readonly value: readonly [];
24
26
  readonly ifUndefined: true;
25
27
  }, {
26
- readonly type: "defineQueueFunction";
27
- readonly name: "gtag";
28
- readonly queue: "dataLayer";
28
+ readonly type: 'defineQueueFunction';
29
+ readonly name: 'gtag';
30
+ readonly queue: 'dataLayer';
29
31
  readonly ifUndefined: true;
30
32
  }];
31
33
  readonly install: [{
32
- readonly type: "pushToQueue";
33
- readonly queue: "dataLayer";
34
+ readonly type: 'pushToQueue';
35
+ readonly queue: 'dataLayer';
34
36
  readonly value: {
35
37
  readonly 'gtm.start': {
36
38
  readonly kind: "c15t.runtime-value";
37
- readonly value: "timestamp";
39
+ readonly value: 'timestamp';
38
40
  };
39
- readonly event: "gtm.js";
41
+ readonly event: 'gtm.js';
40
42
  };
41
43
  }, {
42
- readonly type: "loadScript";
43
- readonly src: "https://www.googletagmanager.com/gtm.js?id={{id}}";
44
+ readonly type: 'loadScript';
45
+ readonly src: 'https://www.googletagmanager.com/gtm.js?id={{id}}';
44
46
  readonly async: true;
45
47
  }];
46
48
  readonly onConsentChange: [{
47
- readonly type: "callGlobal";
48
- readonly global: "gtag";
49
+ readonly type: 'callGlobal';
50
+ readonly global: 'gtag';
49
51
  readonly args: ["event", "{{updateEventName}}"];
50
52
  }];
51
53
  readonly consentMapping: Record<string, string[]>;
52
- readonly consentSignal: "gtag";
53
- readonly kind: "c15t.vendor-manifest";
54
- readonly schemaVersion: 1;
54
+ readonly consentSignal: 'gtag';
55
55
  };
56
56
  export interface GoogleTagManagerOptions {
57
57
  /**
package/docs/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # @c15t/scripts
2
+
3
+ > Consent-aware script integration docs for analytics, advertising pixels, tag managers, widgets, and custom loaders.
4
+
5
+ These docs ship inside the package so coding agents can read them offline. Open the topic file you need from the list below — paths are relative to this file.
6
+
7
+ ## Frameworks
8
+
9
+ Install and configure c15t in JavaScript, React, and Next.js applications.
10
+
11
+ - [Script Loader](./frameworks/javascript/script-loader.md): Gate third-party scripts behind consent — load Google Analytics, Meta Pixel, and other tracking scripts only when users grant permission.
12
+ - [Script Loader](./frameworks/next/script-loader.md): Gate third-party scripts behind consent in Next.js — load Google Analytics, Meta Pixel, and other tracking scripts only when users grant permission.
13
+ - [Script Loader](./frameworks/react/script-loader.md): Gate third-party scripts behind consent in React — load Google Analytics, Meta Pixel, and other tracking scripts only when users grant permission.
14
+
15
+ ## Integrations
16
+
17
+ Connect analytics, advertising, maps, media, and other third-party tools behind consent.
18
+
19
+ - [Adobe Analytics](./integrations/adobe-analytics.md): Adobe Analytics loaded through an Adobe Experience Platform Data Collection Tags embed URL.
20
+ - [Ahrefs Analytics](./integrations/ahrefs-analytics.md): Cookieless web analytics from Ahrefs with a prebuilt helper that wires the project key into a c15t-managed script.
21
+ - [Amplitude](./integrations/amplitude.md): Load Amplitude Browser SDK 2 with c15t and gate product analytics behind measurement consent.
22
+ - [Build a Custom Script Integration](./integrations/building-integrations.md): Learn when to use a raw Script, when to build a reusable manifest-backed integration, and how to debug and test custom consent-aware scripts in c15t.
23
+ - [Clearbit](./integrations/clearbit.md): Visitor and company enrichment loaded with Clearbit's account-keyed tags.js snippet.
24
+ - [Cloudflare Web Analytics](./integrations/cloudflare-web-analytics.md): Cookieless analytics from Cloudflare with a prebuilt helper that serializes the beacon config into the `data-cf-beacon` attribute.
25
+ - [Crisp](./integrations/crisp.md): Load Crisp live chat with website ID, runtime, cookie, and session options.
26
+ - [Databuddy](./integrations/databuddy.md): 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.
27
+ - [Fathom Analytics](./integrations/fathom-analytics.md): Privacy-friendly cookieless analytics with a prebuilt helper that maps Fathom's data attributes into a c15t-managed script.
28
+ - [Google Maps](./integrations/google-maps.md): Render Google Maps only after consent with one shared Maps JavaScript API loader and independently managed map instances.
29
+ - [GA4 + Google Ads (gtag.js)](./integrations/google-tag.md): Send data to Google Analytics 4 and Google Ads with automatic Consent Mode v2 support.
30
+ - [Google Tag Manager](./integrations/google-tag-manager.md): Deploy and manage marketing tags centrally with automatic consent state synchronization.
31
+ - [Heap](./integrations/heap.md): Load Heap with c15t and gate autocapture product analytics behind measurement consent.
32
+ - [Hightouch](./integrations/hightouch.md): Load Hightouch Events with c15t and gate the browser SDK behind measurement consent.
33
+ - [Hotjar](./integrations/hotjar.md): Product analytics and behavior insights with a prebuilt helper that seeds Hotjar globals before loading the vendor bundle.
34
+ - [Intercom](./integrations/intercom.md): Bootstrap Intercom settings and load the messenger widget bundle.
35
+ - [LinkedIn Insights](./integrations/linkedin-insights.md): Track conversions and build matched audiences for LinkedIn advertising campaigns.
36
+ - [LogRocket](./integrations/logrocket.md): Session replay and monitoring loaded after measurement consent with LogRocket's browser SDK.
37
+ - [Matomo Analytics](./integrations/matomo-analytics.md): Load Matomo with c15t and keep Matomo's queue aligned with measurement consent.
38
+ - [Meta Pixel](./integrations/meta-pixel.md): Track conversions and build audiences for Facebook and Instagram advertising campaigns.
39
+ - [Microsoft Clarity](./integrations/microsoft-clarity.md): Session replay and behavior analytics with a prebuilt helper that keeps Clarity consent synchronized with c15t measurement state.
40
+ - [Microsoft UET](./integrations/microsoft-uet.md): Track conversions and measure performance for Microsoft Advertising and Bing Ads.
41
+ - [Mixpanel Analytics](./integrations/mixpanel-analytics.md): Load Mixpanel with c15t and let Mixpanel's own opt-in and opt-out APIs follow measurement consent.
42
+ - [Integrations](./integrations/overview.md): Load analytics, pixels, tag managers, and widgets through c15t so consent state controls when they run, update, and appear in your consent UI.
43
+ - [Pirsch](./integrations/pirsch.md): Privacy-friendly, cookieless analytics loaded with Pirsch's fixed script id and identification-code attributes.
44
+ - [Plausible Analytics](./integrations/plausible-analytics.md): Privacy-friendly cookieless analytics with a prebuilt helper that preserves Plausible's queue bootstrap and loader attributes.
45
+ - [PostHog](./integrations/posthog.md): PostHog is an open-source product analytics platform for tracking user behavior, session replays, feature flags, and A/B testing. It supports cookieless tracking, allowing analytics to continue even without cookie consent.
46
+ - [Promptwatch](./integrations/promptwatch.md): Promptwatch analyzes traffic on your site for Artificial Intelligence (AI) traffic and usage insights. Data is stored in the EU without user-identifiable information.
47
+ - [Reddit Pixel](./integrations/reddit-pixel.md): Track conversions and build retargeting audiences for Reddit advertising campaigns.
48
+ - [RudderStack](./integrations/rudderstack.md): Load RudderStack's JavaScript SDK with c15t and gate the browser SDK behind measurement consent.
49
+ - [Rybbit Analytics](./integrations/rybbit-analytics.md): Privacy-friendly analytics with script-tag configuration via Rybbit's data attributes.
50
+ - [Segment](./integrations/segment.md): Load Segment Analytics.js with c15t and gate it behind measurement consent.
51
+ - [Snapchat Pixel](./integrations/snapchat-pixel.md): Measure Snapchat ad performance and build remarketing audiences with a prebuilt pixel helper.
52
+ - [TikTok Pixel](./integrations/tiktok-pixel.md): Measure ad performance and build audiences for TikTok advertising campaigns.
53
+ - [Umami Analytics](./integrations/umami-analytics.md): Open-source, cookieless analytics with a prebuilt helper that maps Umami's data attributes into a c15t-managed script.
54
+ - [Vercel Analytics](./integrations/vercel-analytics.md): Bootstrap Vercel Analytics with a declarative queue and script attributes.
55
+ - [X Pixel (Twitter Pixel)](./integrations/x-pixel.md): Track conversions and build audiences for advertising campaigns on X (formerly Twitter).
56
+ - [YouTube](./integrations/youtube.md): Keep YouTube iframes unmounted until consent with a privacy-enhanced, lazy-loaded React or Next.js embed.
57
+
58
+ ## Reference
59
+
60
+ Concepts, legal templates, open-source policies, and contributor documentation.
61
+
62
+ - [Script Loader](./shared/react/guides/script-loader.md): Reference page for script loader.
@@ -0,0 +1,356 @@
1
+ ---
2
+ title: Script Loader
3
+ description: Gate third-party scripts behind consent — load Google Analytics,
4
+ Meta Pixel, and other tracking scripts only when users grant permission.
5
+ group: frameworks
6
+ ---
7
+ 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.
8
+
9
+ 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.
10
+
11
+ <PackageCommandTabs mode="install" command="@c15t/scripts" />
12
+
13
+ > ℹ️ **Info:**
14
+ > 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.
15
+ >
16
+ > 📝 **Note:**
17
+ > 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.
18
+ >
19
+ > ℹ️ **Info:**
20
+ > 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.
21
+
22
+ ## Basic Usage
23
+
24
+ Pass an array of `Script` objects to the runtime options:
25
+
26
+ ```ts
27
+ import { getOrCreateConsentRuntime } from 'c15t';
28
+ import { metaPixel } from '@c15t/scripts/meta-pixel';
29
+
30
+ const { consentStore } = getOrCreateConsentRuntime({
31
+ mode: 'hosted',
32
+ backendURL: 'https://your-instance.c15t.dev',
33
+ scripts: [
34
+ metaPixel({ pixelId: '123456' }),
35
+ {
36
+ id: 'custom-analytics',
37
+ src: 'https://cdn.example.com/analytics.js',
38
+ category: 'measurement',
39
+ },
40
+ ],
41
+ });
42
+ ```
43
+
44
+ ## Mental Model
45
+
46
+ 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:
47
+
48
+ 1. **Pending** — registered but waiting for consent. Nothing is in the DOM yet.
49
+ 2. **Loaded** — consent matched, c15t injected the script (or ran callbacks for callback-only scripts).
50
+ 3. **Updated** — already loaded, consent state changed, `onConsentChange` ran so the SDK can react.
51
+ 4. **Unloaded** — consent was revoked. c15t removed the script element unless you opted into persistence.
52
+
53
+ 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.
54
+
55
+ ## Choose the Right Approach
56
+
57
+ Most projects mix more than one style. Pick the smallest one that keeps consent behavior obvious:
58
+
59
+ |Style|Use when|
60
+ |--|--|
61
+ |**Built-in helper** from `@c15t/scripts`|c15t already ships the vendor. See the [integrations overview](/docs/integrations/overview).|
62
+ |**Plain `Script`**|One-off app code with simple load and callback behavior.|
63
+ |**Callback-only `Script`**|Another package already loaded the SDK; c15t only synchronizes consent.|
64
+ |**Manifest-backed helper**|Reusable vendor integration with structured setup phases, queues, stubs, or a vendor consent API.|
65
+ |**Iframe / renderable integration**|Vendor exposes an iframe or React component, not just a `<script>` tag.|
66
+
67
+ ## Script Types
68
+
69
+ ### Standard Scripts
70
+
71
+ Standard scripts load an external JavaScript file via a `<script>` tag. This is the default for most analytics and pixel SDKs:
72
+
73
+ ```tsx
74
+ {
75
+ id: 'analytics',
76
+ src: 'https://cdn.example.com/analytics.js',
77
+ category: 'measurement',
78
+ }
79
+ ```
80
+
81
+ ### Inline Scripts
82
+
83
+ 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.
84
+
85
+ ```tsx
86
+ {
87
+ id: 'gtag-config',
88
+ textContent: `
89
+ window.dataLayer = window.dataLayer || [];
90
+ function gtag(){dataLayer.push(arguments);}
91
+ gtag('js', new Date());
92
+ gtag('config', 'G-XXXXXX');
93
+ `,
94
+ category: 'measurement',
95
+ }
96
+ ```
97
+
98
+ ### Callback-Only Scripts
99
+
100
+ 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:
101
+
102
+ ```tsx
103
+ {
104
+ id: 'posthog-consent',
105
+ callbackOnly: true,
106
+ category: 'measurement',
107
+ onLoad: ({ hasConsent }) => {
108
+ if (hasConsent) {
109
+ posthog.opt_in_capturing();
110
+ }
111
+ },
112
+ onConsentChange: ({ hasConsent }) => {
113
+ if (hasConsent) {
114
+ posthog.opt_in_capturing();
115
+ } else {
116
+ posthog.opt_out_capturing();
117
+ }
118
+ },
119
+ }
120
+ ```
121
+
122
+ ### Manifest-Backed Helpers
123
+
124
+ 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.
125
+
126
+ Use a manifest-backed helper when:
127
+
128
+ * the integration should be reused across projects,
129
+ * the vendor snippet has ordered setup steps,
130
+ * the vendor exposes a consent API,
131
+ * or you plan to contribute the integration back to c15t.
132
+
133
+ Read the [custom integration guide](/docs/integrations/building-integrations) for the manifest contract, phases, and testing checklist.
134
+
135
+ ### Iframe And Renderable Integrations
136
+
137
+ Some vendors are not just script tags. YouTube embeds, maps, calendars, and checkout widgets often need a visible component, a placeholder, or an iframe.
138
+
139
+ * 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.
140
+ * For SDK-backed UI, use the script loader for the shared SDK and render the component only when consent and SDK readiness agree.
141
+ * Use `YouTubeEmbed` for the iframe-only YouTube candidate and `GoogleMap` for the callback-based SDK candidate.
142
+ * 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.
143
+
144
+ ## Lifecycle Callbacks
145
+
146
+ Every script supports four callbacks. Each receives a `ScriptCallbackInfo` payload (id, element, hasConsent, consents):
147
+
148
+ * `onBeforeLoad` — runs before the script tag is injected. Create globals, queues, or vendor stubs here.
149
+ * `onLoad` — runs after the browser loads the script. Call vendor `init()` APIs here.
150
+ * `onConsentChange` — runs for loaded scripts when consent changes. Forward the new consent state to the vendor SDK.
151
+ * `onError` — runs when the script fails to load. Record diagnostics or render a fallback.
152
+
153
+ ```tsx
154
+ {
155
+ id: 'analytics',
156
+ src: 'https://analytics.example.com/v2.js',
157
+ category: 'measurement',
158
+ onBeforeLoad: ({ id }) => {
159
+ window.analyticsQueue = window.analyticsQueue || [];
160
+ },
161
+ onLoad: () => {
162
+ window.analytics.init('my-key');
163
+ },
164
+ onError: ({ error }) => {
165
+ console.error('Failed to load analytics:', error);
166
+ },
167
+ onConsentChange: ({ hasConsent }) => {
168
+ window.analytics.setConsent(hasConsent);
169
+ },
170
+ }
171
+ ```
172
+
173
+ ## Consent Conditions
174
+
175
+ The `category` field accepts a `HasCondition`. It can be a single consent category or a logical expression:
176
+
177
+ ```tsx
178
+ // Simple: requires measurement consent
179
+ { category: 'measurement' }
180
+
181
+ // AND: requires both measurement and marketing
182
+ { category: { and: ['measurement', 'marketing'] } }
183
+
184
+ // OR: requires either measurement or marketing
185
+ { category: { or: ['measurement', 'marketing'] } }
186
+ ```
187
+
188
+ Consent categories use the same names as the rest of c15t (`necessary`, `functionality`, `experience`, `measurement`, `marketing`).
189
+
190
+ ## Persistence Options
191
+
192
+ ### Always Load
193
+
194
+ `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.
195
+
196
+ ```tsx
197
+ {
198
+ id: 'google-tag-manager',
199
+ src: 'https://www.googletagmanager.com/gtm.js?id=GTM-XXXX',
200
+ category: 'measurement',
201
+ alwaysLoad: true,
202
+ }
203
+ ```
204
+
205
+ When `alwaysLoad` is on, `onConsentChange` becomes mandatory: it is how the loaded SDK learns about every transition.
206
+
207
+ > ⚠️ **Warning:**
208
+ > alwaysLoad shifts compliance responsibility to the vendor integration. Make sure the script receives denied-by-default consent signals before it can track.
209
+
210
+ ### Persist After Revocation
211
+
212
+ `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.
213
+
214
+ ```tsx
215
+ {
216
+ id: 'error-tracking',
217
+ src: 'https://errors.example.com/track.js',
218
+ category: 'measurement',
219
+ persistAfterConsentRevoked: true,
220
+ onConsentChange: ({ hasConsent }) => {
221
+ window.ErrorTracker.setConsent(hasConsent);
222
+ },
223
+ }
224
+ ```
225
+
226
+ As with `alwaysLoad`, `onConsentChange` is how the persisted SDK learns about consent updates.
227
+
228
+ ### `alwaysLoad` vs `persistAfterConsentRevoked`
229
+
230
+ These two flags answer different questions. Use this table to keep them straight:
231
+
232
+ |Question|`alwaysLoad`|`persistAfterConsentRevoked`|
233
+ |--|--|--|
234
+ |Loads before consent is granted?|Yes|No (waits for consent like a normal script)|
235
+ |Stays loaded after consent is revoked?|Yes|Yes|
236
+ |Requires a vendor consent API?|Yes|Yes|
237
+
238
+ ## DOM Placement
239
+
240
+ Control where the script is injected and whether the element id is anonymized:
241
+
242
+ ```tsx
243
+ {
244
+ id: 'widget',
245
+ src: 'https://widget.example.com/embed.js',
246
+ category: 'experience',
247
+ target: 'body', // 'head' (default) or 'body'
248
+ anonymizeId: true, // default: true, hides the c15t script id from ad blockers
249
+ nonce: 'abc123', // optional CSP nonce
250
+ }
251
+ ```
252
+
253
+ 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.
254
+
255
+ 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.
256
+
257
+ ## Dynamic Management
258
+
259
+ 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:
260
+
261
+ * `setScripts(scripts)` — registers script definitions and immediately evaluates them against consent.
262
+ * `removeScript(id)` — removes a definition and unloads its element if needed.
263
+ * `isScriptLoaded(id)` — returns whether c15t has loaded a script.
264
+ * `getLoadedScriptIds()` — returns every currently loaded script id.
265
+
266
+ 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.
267
+
268
+ ## Calling Vendor APIs From Your App
269
+
270
+ 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:
271
+
272
+ |Vendor pattern|What c15t does|What your app code must do|
273
+ |--|--|--|
274
+ |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.|
275
+ |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.|
276
+ |`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.|
277
+ |No app-facing API (e.g. Cloudflare Web Analytics)|Script in/out of DOM based on consent. Tracking is fully automatic.|Nothing to guard.|
278
+
279
+ The safe pattern in React is to read consent state through `useConsentManager().has(category)` before calling the SDK:
280
+
281
+ ```tsx
282
+ import { useCallback } from 'react';
283
+ import { useConsentManager } from '@c15t/react';
284
+
285
+ function useTrackSignup() {
286
+ const { has } = useConsentManager();
287
+
288
+ return useCallback(() => {
289
+ if (has('measurement')) {
290
+ window.fathom?.trackEvent('signup');
291
+ }
292
+ }, [has]);
293
+ }
294
+
295
+ function SignupButton() {
296
+ const trackSignup = useTrackSignup();
297
+
298
+ return <button onClick={trackSignup}>Sign up</button>;
299
+ }
300
+ ```
301
+
302
+ From non-React code, read the consent store directly:
303
+
304
+ ```ts
305
+ import { getOrCreateConsentRuntime } from 'c15t';
306
+
307
+ const { consentStore } = getOrCreateConsentRuntime();
308
+
309
+ if (consentStore.getState().has('measurement')) {
310
+ window.fathom?.trackEvent('signup');
311
+ }
312
+ ```
313
+
314
+ Each [integration page](/docs/integrations/overview) includes a vendor-specific **Tracking events in your app** block that names which pattern applies.
315
+
316
+ ## Debugging Checklist
317
+
318
+ When a script does not behave as expected:
319
+
320
+ 1. Confirm the script's `category` matches the consent that has been granted.
321
+ 2. Check whether the script is `alwaysLoad` or consent-gated.
322
+ 3. Confirm `onBeforeLoad` creates any globals before the vendor code reads them.
323
+ 4. Confirm `onConsentChange` updates persisted or always-loaded scripts when consent changes.
324
+ 5. Check whether the browser or an ad blocker blocked the request.
325
+ 6. Use c15t devtools to inspect script lifecycle events when available.
326
+
327
+ ## Dynamic Script Management
328
+
329
+ Add, remove, or check scripts at runtime via the store:
330
+
331
+ ```ts
332
+ const state = consentStore.getState();
333
+
334
+ // Add scripts dynamically
335
+ state.setScripts([
336
+ { id: 'dynamic', src: 'https://cdn.example.com/widget.js', category: 'measurement' },
337
+ ]);
338
+
339
+ // Remove a script
340
+ state.removeScript('dynamic');
341
+
342
+ // Check if a script is loaded
343
+ const loaded = state.isScriptLoaded('custom-analytics');
344
+
345
+ // Get all loaded script IDs
346
+ const allLoaded = state.getLoadedScriptIds();
347
+ ```
348
+
349
+ ## API Reference
350
+
351
+ |Property|Value|
352
+ |:--|:--|
353
+ |Type Name|\`Script\`|
354
+ |Source Path|\`./packages/core/src/libs/script-loader/types.ts\`|
355
+
356
+ \*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.\*