@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
@@ -0,0 +1,160 @@
1
+ ---
2
+ title: Adobe Analytics
3
+ description: Adobe Analytics loaded through an Adobe Experience Platform Data
4
+ Collection Tags embed URL.
5
+ group: integrations
6
+ icon: adobe-analytics
7
+ ---
8
+ [Adobe Analytics](https://business.adobe.com/products/analytics/adobe-analytics.html) is commonly deployed through an Adobe Experience Platform Data Collection web property. Data Collection generates a property-specific Tags embed script, often hosted on `assets.adobedtm.com`, and that script can load Adobe Analytics, Web SDK, or other configured extensions and rules.
9
+
10
+ ## Integrate with c15t
11
+
12
+ **React**
13
+
14
+ ```tsx
15
+ import { type ReactNode } from 'react';
16
+ import { ConsentManagerProvider } from '@c15t/react';
17
+ import { adobeAnalytics } from '@c15t/scripts/adobe-analytics';
18
+
19
+ const scripts = [
20
+ adobeAnalytics({
21
+ scriptUrl:
22
+ 'https://assets.adobedtm.com/YOUR_ORG/YOUR_PROPERTY/launch-production.min.js',
23
+ }),
24
+ ];
25
+
26
+ export function ConsentProvider({ children }: { children: ReactNode }) {
27
+ return (
28
+ <ConsentManagerProvider
29
+ options={{
30
+ mode: 'hosted',
31
+ backendURL: 'https://your-instance.c15t.dev',
32
+ scripts,
33
+ }}
34
+ >
35
+ {children}
36
+ </ConsentManagerProvider>
37
+ );
38
+ }
39
+ ```
40
+
41
+ **Next.js**
42
+
43
+ ```tsx
44
+ 'use client';
45
+
46
+ import { type ReactNode } from 'react';
47
+ import { ConsentManagerProvider } from '@c15t/nextjs';
48
+ import { adobeAnalytics } from '@c15t/scripts/adobe-analytics';
49
+
50
+ const scripts = [
51
+ adobeAnalytics({
52
+ scriptUrl:
53
+ 'https://assets.adobedtm.com/YOUR_ORG/YOUR_PROPERTY/launch-production.min.js',
54
+ }),
55
+ ];
56
+
57
+ export function ConsentProvider({ children }: { children: ReactNode }) {
58
+ return (
59
+ <ConsentManagerProvider
60
+ options={{
61
+ mode: 'hosted',
62
+ backendURL: '/api/c15t',
63
+ scripts,
64
+ }}
65
+ >
66
+ {children}
67
+ </ConsentManagerProvider>
68
+ );
69
+ }
70
+ ```
71
+
72
+ **JavaScript**
73
+
74
+ ```ts
75
+ import { getOrCreateConsentRuntime } from 'c15t';
76
+ import { adobeAnalytics } from '@c15t/scripts/adobe-analytics';
77
+
78
+ getOrCreateConsentRuntime({
79
+ mode: 'hosted',
80
+ backendURL: 'https://your-instance.c15t.dev',
81
+ scripts: [
82
+ adobeAnalytics({
83
+ scriptUrl:
84
+ 'https://assets.adobedtm.com/YOUR_ORG/YOUR_PROPERTY/launch-production.min.js',
85
+ }),
86
+ ],
87
+ });
88
+ ```
89
+
90
+ ## Find Your Embed URL
91
+
92
+ Open Adobe Data Collection, choose your Tags property, then open **Environments**. Select the install action for the environment you want to deploy and copy the web property embed script URL from the generated code.
93
+
94
+ Each Adobe environment has its own embed code. Use the production URL in production, and keep development or staging URLs limited to test environments. The URL is typically shaped like:
95
+
96
+ ```txt
97
+ https://assets.adobedtm.com/{org}/{property}/launch-{env}.min.js
98
+ ```
99
+
100
+ Self-hosted Data Collection builds are supported too. c15t only requires a full `https:` URL.
101
+
102
+ ## How c15t loads it
103
+
104
+ * **Category:** `measurement` (Analytics)
105
+ * **Loads when:** measurement consent is granted
106
+ * **On revocation:** unloaded - c15t removes the Adobe Tags script element from the DOM.
107
+
108
+ The helper blocks the Adobe Tags library until measurement consent is granted. When measurement consent is revoked, c15t unloads the script element. Adobe rules, extensions, cookies, and downstream tags that already ran may have their own state, so configure Data Collection rules and extensions to respect your consent model as well.
109
+
110
+ This is the same caveat as tag managers: a Tags property can load more than Adobe Analytics. Keep non-measurement tags behind Adobe-side rule conditions, consent checks, or separate properties so they do not run from a measurement-only grant.
111
+
112
+ By default, c15t also seeds the Adobe Client Data Layer queue before loading:
113
+
114
+ ```ts
115
+ adobeAnalytics({
116
+ scriptUrl:
117
+ 'https://assets.adobedtm.com/YOUR_ORG/YOUR_PROPERTY/launch-production.min.js',
118
+ seedAdobeDataLayer: true,
119
+ })
120
+ ```
121
+
122
+ This creates `window.adobeDataLayer = []` only when it is still undefined. Adobe's Client Data Layer extension uses `adobeDataLayer` as the default object name, and the pre-seed is harmless for properties that do not use that extension.
123
+
124
+ Adobe's `_satellite` object becomes available after the Tags library loads:
125
+
126
+ ```ts
127
+ if (window._satellite) {
128
+ // Adobe Tags runtime is available.
129
+ }
130
+ ```
131
+
132
+ Use synchronous deployment only when a legacy Tags setup requires it:
133
+
134
+ ```ts
135
+ adobeAnalytics({
136
+ scriptUrl:
137
+ 'https://assets.adobedtm.com/YOUR_ORG/YOUR_PROPERTY/launch-production.min.js',
138
+ async: false,
139
+ })
140
+ ```
141
+
142
+ ## Types
143
+
144
+ ### AdobeAnalyticsOptions
145
+
146
+ |Property|Value|
147
+ |:--|:--|
148
+ |Type Name|\`AdobeAnalyticsOptions\`|
149
+ |Source Path|\`./packages/scripts/src/vendors/analytics/adobe-analytics.ts\`|
150
+
151
+ \*ExtractedTypeTable: Could not extract "AdobeAnalyticsOptions" from "./packages/scripts/src/vendors/analytics/adobe-analytics.ts" using base path "/home/runner/work/c15t/c15t". Verify the path/name and that the file is included by your tsconfig.\*
152
+
153
+ ### Script
154
+
155
+ |Property|Value|
156
+ |:--|:--|
157
+ |Type Name|\`Script\`|
158
+ |Source Path|\`./packages/core/src/libs/script-loader/types.ts\`|
159
+
160
+ \*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.\*
@@ -0,0 +1,157 @@
1
+ ---
2
+ title: Ahrefs Analytics
3
+ description: Cookieless web analytics from Ahrefs with a prebuilt helper that
4
+ wires the project key into a c15t-managed script.
5
+ group: integrations
6
+ icon: ahrefs
7
+ ---
8
+ 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.
9
+
10
+ ## Integrate with c15t
11
+
12
+ **React**
13
+
14
+ ```tsx
15
+ import { type ReactNode } from 'react';
16
+ import { ConsentManagerProvider } from '@c15t/react';
17
+ import { ahrefsAnalytics } from '@c15t/scripts/ahrefs-analytics';
18
+
19
+ const scripts = [
20
+ ahrefsAnalytics({
21
+ key: 'your-ahrefs-project-key',
22
+ }),
23
+ ];
24
+
25
+ export function ConsentProvider({ children }: { children: ReactNode }) {
26
+ return (
27
+ <ConsentManagerProvider
28
+ options={{
29
+ mode: 'hosted',
30
+ backendURL: 'https://your-instance.c15t.dev',
31
+ scripts,
32
+ }}
33
+ >
34
+ {children}
35
+ </ConsentManagerProvider>
36
+ );
37
+ }
38
+ ```
39
+
40
+ **Next.js**
41
+
42
+ ```tsx
43
+ 'use client';
44
+
45
+ import { type ReactNode } from 'react';
46
+ import { ConsentManagerProvider } from '@c15t/nextjs';
47
+ import { ahrefsAnalytics } from '@c15t/scripts/ahrefs-analytics';
48
+
49
+ const scripts = [
50
+ ahrefsAnalytics({
51
+ key: 'your-ahrefs-project-key',
52
+ }),
53
+ ];
54
+
55
+ export function ConsentProvider({ children }: { children: ReactNode }) {
56
+ return (
57
+ <ConsentManagerProvider
58
+ options={{
59
+ mode: 'hosted',
60
+ backendURL: '/api/c15t',
61
+ scripts,
62
+ }}
63
+ >
64
+ {children}
65
+ </ConsentManagerProvider>
66
+ );
67
+ }
68
+ ```
69
+
70
+ **JavaScript**
71
+
72
+ ```ts
73
+ import { getOrCreateConsentRuntime } from 'c15t';
74
+ import { ahrefsAnalytics } from '@c15t/scripts/ahrefs-analytics';
75
+
76
+ getOrCreateConsentRuntime({
77
+ mode: 'hosted',
78
+ backendURL: 'https://your-instance.c15t.dev',
79
+ scripts: [
80
+ ahrefsAnalytics({
81
+ key: 'your-ahrefs-project-key',
82
+ }),
83
+ ],
84
+ });
85
+ ```
86
+
87
+ ## How c15t loads it
88
+
89
+ * **Category:** `measurement` (Analytics)
90
+ * **Loads when:** measurement consent is granted
91
+ * **On revocation:** unloaded — c15t removes the script element from the DOM. Ahrefs Web Analytics is cookieless, so no client-side state needs clearing.
92
+
93
+ To run from a custom loader URL (for example a self-hosted proxy):
94
+
95
+ ```ts
96
+ ahrefsAnalytics({
97
+ key: 'your-ahrefs-project-key',
98
+ scriptUrl: 'https://analytics.example.com/analytics.js',
99
+ })
100
+ ```
101
+
102
+ 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.
103
+
104
+ ## Tracking events in your app
105
+
106
+ 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.
107
+
108
+ Guard event calls by checking consent state. From React:
109
+
110
+ ```tsx
111
+ import { useCallback } from 'react';
112
+ import { useConsentManager } from '@c15t/react';
113
+
114
+ function SignupExample() {
115
+ const { has } = useConsentManager();
116
+
117
+ const trackSignup = useCallback(() => {
118
+ if (has('measurement')) {
119
+ window.AhrefsAnalytics?.sendEvent('signup');
120
+ }
121
+ }, [has]);
122
+
123
+ // Call trackSignup() from an event handler after signup succeeds.
124
+ }
125
+ ```
126
+
127
+ From plain JavaScript:
128
+
129
+ ```ts
130
+ import { getOrCreateConsentRuntime } from 'c15t';
131
+
132
+ const { consentStore } = getOrCreateConsentRuntime();
133
+
134
+ if (consentStore.getState().has('measurement')) {
135
+ window.AhrefsAnalytics?.sendEvent('signup');
136
+ }
137
+ ```
138
+
139
+ ## Types
140
+
141
+ ### AhrefsAnalyticsOptions
142
+
143
+ |Property|Value|
144
+ |:--|:--|
145
+ |Type Name|\`AhrefsAnalyticsOptions\`|
146
+ |Source Path|\`./packages/scripts/src/vendors/analytics/ahrefs-analytics.ts\`|
147
+
148
+ \*ExtractedTypeTable: Could not extract "AhrefsAnalyticsOptions" from "./packages/scripts/src/vendors/analytics/ahrefs-analytics.ts" using base path "/home/runner/work/c15t/c15t". Verify the path/name and that the file is included by your tsconfig.\*
149
+
150
+ ### Script
151
+
152
+ |Property|Value|
153
+ |:--|:--|
154
+ |Type Name|\`Script\`|
155
+ |Source Path|\`./packages/core/src/libs/script-loader/types.ts\`|
156
+
157
+ \*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.\*
@@ -0,0 +1,230 @@
1
+ ---
2
+ title: Amplitude
3
+ description: Load Amplitude Browser SDK 2 with c15t and gate product analytics
4
+ behind measurement consent.
5
+ group: integrations
6
+ icon: amplitude
7
+ ---
8
+ [Amplitude](https://amplitude.com/) provides product analytics for tracking user behavior, funnels, retention, and feature adoption. The `amplitude()` helper creates the Browser SDK 2 snippet queue, queues `amplitude.init(apiKey, initOptions)`, and loads Amplitude only when `measurement` consent is available.
9
+
10
+ ## Integrate with c15t
11
+
12
+ **React**
13
+
14
+ ```tsx
15
+ import { type ReactNode } from 'react';
16
+ import { ConsentManagerProvider } from '@c15t/react';
17
+ import { amplitude } from '@c15t/scripts/amplitude';
18
+
19
+ const scripts = [
20
+ amplitude({
21
+ apiKey: 'AMPLITUDE_API_KEY',
22
+ initOptions: {
23
+ autocapture: false,
24
+ },
25
+ }),
26
+ ];
27
+
28
+ export function ConsentProvider({ children }: { children: ReactNode }) {
29
+ return (
30
+ <ConsentManagerProvider
31
+ options={{
32
+ mode: 'hosted',
33
+ backendURL: 'https://your-instance.c15t.dev',
34
+ scripts,
35
+ }}
36
+ >
37
+ {children}
38
+ </ConsentManagerProvider>
39
+ );
40
+ }
41
+ ```
42
+
43
+ **Next.js**
44
+
45
+ ```tsx
46
+ 'use client';
47
+
48
+ import { type ReactNode } from 'react';
49
+ import { ConsentManagerProvider } from '@c15t/nextjs';
50
+ import { amplitude } from '@c15t/scripts/amplitude';
51
+
52
+ const scripts = [
53
+ amplitude({
54
+ apiKey: 'AMPLITUDE_API_KEY',
55
+ initOptions: {
56
+ autocapture: false,
57
+ },
58
+ }),
59
+ ];
60
+
61
+ export function ConsentProvider({ children }: { children: ReactNode }) {
62
+ return (
63
+ <ConsentManagerProvider
64
+ options={{
65
+ mode: 'hosted',
66
+ backendURL: '/api/c15t',
67
+ scripts,
68
+ }}
69
+ >
70
+ {children}
71
+ </ConsentManagerProvider>
72
+ );
73
+ }
74
+ ```
75
+
76
+ **JavaScript**
77
+
78
+ ```ts
79
+ import { getOrCreateConsentRuntime } from 'c15t';
80
+ import { amplitude } from '@c15t/scripts/amplitude';
81
+
82
+ getOrCreateConsentRuntime({
83
+ mode: 'hosted',
84
+ backendURL: 'https://your-instance.c15t.dev',
85
+ scripts: [
86
+ amplitude({
87
+ apiKey: 'AMPLITUDE_API_KEY',
88
+ initOptions: {
89
+ autocapture: false,
90
+ },
91
+ }),
92
+ ],
93
+ });
94
+ ```
95
+
96
+ ## How c15t loads it
97
+
98
+ * **Category:** `measurement` (Analytics)
99
+ * **Loads when:** measurement consent is granted
100
+ * **On revocation:** c15t calls `amplitude.setOptOut(true)` through the lifecycle callback and unloads the script by default.
101
+
102
+ The helper maps Amplitude Browser SDK 2's script-loader contract into the manifest engine:
103
+
104
+ ```ts
105
+ amplitude({
106
+ apiKey: 'AMPLITUDE_API_KEY',
107
+ initOptions: {
108
+ autocapture: false,
109
+ },
110
+ });
111
+ ```
112
+
113
+ It creates `window.amplitude` with:
114
+
115
+ * `invoked: true`
116
+ * `_q: []` for queued `{ name, args, resolve }` method calls
117
+ * `_iq: {}` for the named-instance registry expected by the SDK
118
+ * `Identify` for queued pre-load identify operations
119
+ * core queue methods for `init`, `track`, `identify`, `setUserId`, `setOptOut`, and `flush`
120
+
121
+ Then it queues:
122
+
123
+ ```ts
124
+ window.amplitude.init('AMPLITUDE_API_KEY', {
125
+ autocapture: false,
126
+ });
127
+ ```
128
+
129
+ and loads:
130
+
131
+ ```txt
132
+ https://cdn.amplitude.com/libs/analytics-browser-2.44.4-min.js.gz
133
+ ```
134
+
135
+ `apiKey` is required and must be a non-empty string after trimming.
136
+
137
+ ## Configure initialization
138
+
139
+ Pass `initOptions` to provide Amplitude Browser SDK 2 initialization options. Values must be JSON-serializable: plain objects, arrays, strings, numbers, booleans, and `null`.
140
+
141
+ ```ts
142
+ import { amplitude } from '@c15t/scripts/amplitude';
143
+
144
+ amplitude({
145
+ apiKey: 'AMPLITUDE_API_KEY',
146
+ initOptions: {
147
+ autocapture: false,
148
+ fetchRemoteConfig: false,
149
+ },
150
+ });
151
+ ```
152
+
153
+ Do not pass functions, Dates, Maps, Sets, class instances, symbols, or other non-JSON values in `initOptions`.
154
+
155
+ ## Configure the loader URL
156
+
157
+ Amplitude's Browser SDK 2 CDN bundle path is versioned. c15t pins a tested default version and lets you override the URL if you self-host or proxy the bundle.
158
+
159
+ ```ts
160
+ amplitude({
161
+ apiKey: 'AMPLITUDE_API_KEY',
162
+ scriptUrl: 'https://analytics.example.com/analytics-browser.js',
163
+ });
164
+ ```
165
+
166
+ ## Consent behavior
167
+
168
+ Amplitude should not load before analytics consent. c15t gates the SDK on `measurement` consent and queues `init()` only when the script is allowed to load.
169
+
170
+ After the SDK has loaded, the generated lifecycle callback maps consent changes to Amplitude's runtime opt-out API:
171
+
172
+ ```ts
173
+ window.amplitude.setOptOut(false); // measurement granted
174
+ window.amplitude.setOptOut(true); // measurement denied
175
+ ```
176
+
177
+ The script still uses c15t's default unload behavior when measurement consent is revoked.
178
+
179
+ ## Tracking events in your app
180
+
181
+ c15t gates the Amplitude browser SDK from loading until `measurement` consent is granted. Your application code that calls Amplitude's runtime API (`window.amplitude.track`, `identify`, etc.) is **not** automatically gated - `window.amplitude` does not exist until the script is loaded, so unguarded calls before consent throw.
182
+
183
+ Guard event calls by checking consent state. From React:
184
+
185
+ ```tsx
186
+ import { useCallback } from 'react';
187
+ import { useConsentManager } from '@c15t/react';
188
+
189
+ function SignupExample() {
190
+ const { has } = useConsentManager();
191
+
192
+ const trackSignup = useCallback(() => {
193
+ if (has('measurement')) {
194
+ window.amplitude?.track('Signup Completed', { plan: 'pro' });
195
+ }
196
+ }, [has]);
197
+ }
198
+ ```
199
+
200
+ From plain JavaScript:
201
+
202
+ ```ts
203
+ import { getOrCreateConsentRuntime } from 'c15t';
204
+
205
+ const { consentStore } = getOrCreateConsentRuntime();
206
+
207
+ if (consentStore.getState().has('measurement')) {
208
+ window.amplitude?.track('Signup Completed', { plan: 'pro' });
209
+ }
210
+ ```
211
+
212
+ ## Types
213
+
214
+ ### AmplitudeOptions
215
+
216
+ |Property|Value|
217
+ |:--|:--|
218
+ |Type Name|\`AmplitudeOptions\`|
219
+ |Source Path|\`./packages/scripts/src/vendors/analytics/amplitude.ts\`|
220
+
221
+ \*ExtractedTypeTable: Could not extract "AmplitudeOptions" from "./packages/scripts/src/vendors/analytics/amplitude.ts" using base path "/home/runner/work/c15t/c15t". Verify the path/name and that the file is included by your tsconfig.\*
222
+
223
+ ### Script
224
+
225
+ |Property|Value|
226
+ |:--|:--|
227
+ |Type Name|\`Script\`|
228
+ |Source Path|\`./packages/core/src/libs/script-loader/types.ts\`|
229
+
230
+ \*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.\*