@c15t/scripts 2.2.0 → 3.0.0-alpha.1

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 (202) hide show
  1. package/AGENTS.md +77 -48
  2. package/README.md +4 -3
  3. package/dist/e2e-test-utils.js +60 -24
  4. package/dist/engine/compile.js +45 -45
  5. package/dist/engine/runtime.js +130 -119
  6. package/dist/registry.js +196 -176
  7. package/dist/resolve.js +12 -12
  8. package/dist/vendors/_shared/attributes.js +5 -5
  9. package/dist/vendors/_shared/google-consent.js +10 -10
  10. package/dist/vendors/_shared/install-builders.js +9 -9
  11. package/dist/vendors/_shared/script-url.js +12 -12
  12. package/dist/vendors/ads-and-pixels/linkedin-insights.js +16 -16
  13. package/dist/vendors/ads-and-pixels/meta-pixel.js +82 -82
  14. package/dist/vendors/ads-and-pixels/microsoft-uet.js +57 -57
  15. package/dist/vendors/ads-and-pixels/openai-pixel.js +88 -0
  16. package/dist/vendors/ads-and-pixels/reddit-pixel.js +39 -39
  17. package/dist/vendors/ads-and-pixels/snapchat-pixel.js +25 -25
  18. package/dist/vendors/ads-and-pixels/tiktok-pixel.js +31 -31
  19. package/dist/vendors/ads-and-pixels/x-pixel.js +17 -17
  20. package/dist/vendors/analytics/adobe-analytics.js +17 -17
  21. package/dist/vendors/analytics/ahrefs-analytics.js +8 -8
  22. package/dist/vendors/analytics/amplitude.js +39 -39
  23. package/dist/vendors/analytics/clearbit.js +11 -11
  24. package/dist/vendors/analytics/cloudflare-web-analytics.js +13 -13
  25. package/dist/vendors/analytics/databuddy.js +45 -45
  26. package/dist/vendors/analytics/fathom-analytics.js +15 -15
  27. package/dist/vendors/analytics/google-tag.js +23 -23
  28. package/dist/vendors/analytics/heap.js +37 -37
  29. package/dist/vendors/analytics/hightouch.js +30 -30
  30. package/dist/vendors/analytics/hotjar.js +14 -14
  31. package/dist/vendors/analytics/logrocket.js +24 -24
  32. package/dist/vendors/analytics/matomo-analytics.js +51 -51
  33. package/dist/vendors/analytics/microsoft-clarity.js +34 -31
  34. package/dist/vendors/analytics/mixpanel-analytics.js +31 -31
  35. package/dist/vendors/analytics/pirsch.js +27 -27
  36. package/dist/vendors/analytics/plausible-analytics.js +24 -24
  37. package/dist/vendors/analytics/posthog.js +84 -79
  38. package/dist/vendors/analytics/promptwatch.js +8 -8
  39. package/dist/vendors/analytics/rudderstack.js +50 -50
  40. package/dist/vendors/analytics/rybbit-analytics.js +30 -30
  41. package/dist/vendors/analytics/segment.js +16 -16
  42. package/dist/vendors/analytics/umami-analytics.js +16 -16
  43. package/dist/vendors/analytics/vercel-analytics.js +22 -22
  44. package/dist/vendors/functional/crisp.js +49 -51
  45. package/dist/vendors/functional/intercom.js +18 -18
  46. package/dist/vendors/tag-managers/cloudflare-zaraz.js +98 -0
  47. package/dist/vendors/tag-managers/google-tag-manager.js +20 -20
  48. package/dist-types/__tests__/helpers.d.ts +11 -11
  49. package/dist-types/engine/compile.d.ts +3 -3
  50. package/dist-types/engine/runtime.d.ts +3 -3
  51. package/dist-types/registry.d.ts +191 -173
  52. package/dist-types/resolve.d.ts +3 -3
  53. package/dist-types/types.d.ts +2 -2
  54. package/dist-types/vendors/_shared/attributes.d.ts +2 -2
  55. package/dist-types/vendors/_shared/google-consent.d.ts +2 -2
  56. package/dist-types/vendors/_shared/install-builders.d.ts +2 -2
  57. package/dist-types/vendors/_shared/script-url.d.ts +6 -6
  58. package/dist-types/vendors/ads-and-pixels/linkedin-insights.d.ts +14 -14
  59. package/dist-types/vendors/ads-and-pixels/meta-pixel.d.ts +27 -27
  60. package/dist-types/vendors/ads-and-pixels/microsoft-uet.d.ts +40 -40
  61. package/dist-types/vendors/ads-and-pixels/openai-pixel.d.ts +211 -0
  62. package/dist-types/vendors/ads-and-pixels/reddit-pixel.d.ts +28 -29
  63. package/dist-types/vendors/ads-and-pixels/snapchat-pixel.d.ts +23 -23
  64. package/dist-types/vendors/ads-and-pixels/tiktok-pixel.d.ts +22 -22
  65. package/dist-types/vendors/ads-and-pixels/x-pixel.d.ts +15 -15
  66. package/dist-types/vendors/analytics/adobe-analytics.d.ts +3 -3
  67. package/dist-types/vendors/analytics/ahrefs-analytics.d.ts +5 -5
  68. package/dist-types/vendors/analytics/amplitude.d.ts +24 -24
  69. package/dist-types/vendors/analytics/clearbit.d.ts +5 -5
  70. package/dist-types/vendors/analytics/cloudflare-web-analytics.d.ts +6 -6
  71. package/dist-types/vendors/analytics/databuddy.d.ts +34 -31
  72. package/dist-types/vendors/analytics/fathom-analytics.d.ts +8 -8
  73. package/dist-types/vendors/analytics/google-tag.d.ts +17 -17
  74. package/dist-types/vendors/analytics/heap.d.ts +17 -17
  75. package/dist-types/vendors/analytics/hightouch.d.ts +15 -15
  76. package/dist-types/vendors/analytics/hotjar.d.ts +9 -9
  77. package/dist-types/vendors/analytics/logrocket.d.ts +11 -11
  78. package/dist-types/vendors/analytics/matomo-analytics.d.ts +3 -3
  79. package/dist-types/vendors/analytics/microsoft-clarity.d.ts +12 -13
  80. package/dist-types/vendors/analytics/mixpanel-analytics.d.ts +20 -20
  81. package/dist-types/vendors/analytics/pirsch.d.ts +10 -10
  82. package/dist-types/vendors/analytics/plausible-analytics.d.ts +13 -13
  83. package/dist-types/vendors/analytics/posthog.d.ts +35 -32
  84. package/dist-types/vendors/analytics/promptwatch.d.ts +5 -5
  85. package/dist-types/vendors/analytics/rudderstack.d.ts +16 -16
  86. package/dist-types/vendors/analytics/rybbit-analytics.d.ts +15 -15
  87. package/dist-types/vendors/analytics/segment.d.ts +11 -11
  88. package/dist-types/vendors/analytics/umami-analytics.d.ts +9 -9
  89. package/dist-types/vendors/analytics/vercel-analytics.d.ts +13 -13
  90. package/dist-types/vendors/functional/crisp.d.ts +9 -9
  91. package/dist-types/vendors/functional/intercom.d.ts +12 -12
  92. package/dist-types/vendors/tag-managers/cloudflare-zaraz.d.ts +39 -0
  93. package/dist-types/vendors/tag-managers/google-tag-manager.d.ts +16 -16
  94. package/docs/README.md +77 -48
  95. package/docs/assets/v3/brand-bar.png +0 -0
  96. package/docs/assets/v3/brand-card.png +0 -0
  97. package/docs/assets/v3/choice-wall.png +0 -0
  98. package/docs/assets/v3/mobile-card.png +0 -0
  99. package/docs/assets/v3/preferences.png +0 -0
  100. package/docs/customization/overview.md +45 -0
  101. package/docs/customization/recipes.md +79 -0
  102. package/docs/customization/slots.md +55 -0
  103. package/docs/customization/tokens.md +76 -0
  104. package/docs/customization/translations.md +49 -0
  105. package/docs/frameworks/javascript/script-loader.md +81 -343
  106. package/docs/frameworks/next/script-loader.md +164 -455
  107. package/docs/frameworks/react/script-loader.md +41 -533
  108. package/docs/guides/consent-state.md +60 -0
  109. package/docs/guides/data-fetching.md +163 -0
  110. package/docs/guides/deployment-modes.md +75 -0
  111. package/docs/guides/troubleshooting.md +68 -0
  112. package/docs/guides/verify-consent.md +62 -0
  113. package/docs/integrations/adobe-analytics.md +239 -105
  114. package/docs/integrations/ahrefs-analytics.md +238 -104
  115. package/docs/integrations/amplitude.md +219 -157
  116. package/docs/integrations/building-integrations.md +36 -223
  117. package/docs/integrations/clear-on-revocation.md +167 -0
  118. package/docs/integrations/clearbit.md +247 -86
  119. package/docs/integrations/cloudflare-web-analytics.md +250 -84
  120. package/docs/integrations/cloudflare-zaraz.md +399 -0
  121. package/docs/integrations/crisp.md +251 -97
  122. package/docs/integrations/databuddy.md +259 -153
  123. package/docs/integrations/fathom-analytics.md +239 -96
  124. package/docs/integrations/google-maps.md +328 -207
  125. package/docs/integrations/google-tag-manager.md +248 -96
  126. package/docs/integrations/google-tag.md +261 -90
  127. package/docs/integrations/granular-consent.md +208 -0
  128. package/docs/integrations/heap.md +222 -149
  129. package/docs/integrations/hightouch.md +225 -131
  130. package/docs/integrations/hotjar.md +239 -90
  131. package/docs/integrations/intercom.md +239 -98
  132. package/docs/integrations/linkedin-insights.md +243 -113
  133. package/docs/integrations/logrocket.md +241 -123
  134. package/docs/integrations/matomo-analytics.md +256 -111
  135. package/docs/integrations/meta-pixel.md +197 -324
  136. package/docs/integrations/microsoft-clarity.md +233 -114
  137. package/docs/integrations/microsoft-uet.md +245 -110
  138. package/docs/integrations/mixpanel-analytics.md +252 -87
  139. package/docs/integrations/openai-pixel.md +441 -0
  140. package/docs/integrations/overview.md +96 -133
  141. package/docs/integrations/pirsch.md +249 -96
  142. package/docs/integrations/plausible-analytics.md +241 -100
  143. package/docs/integrations/posthog.md +353 -214
  144. package/docs/integrations/promptwatch.md +251 -81
  145. package/docs/integrations/reddit-pixel.md +226 -173
  146. package/docs/integrations/rudderstack.md +244 -187
  147. package/docs/integrations/rybbit-analytics.md +244 -91
  148. package/docs/integrations/segment.md +238 -92
  149. package/docs/integrations/snapchat-pixel.md +240 -110
  150. package/docs/integrations/tiktok-pixel.md +249 -81
  151. package/docs/integrations/umami-analytics.md +242 -95
  152. package/docs/integrations/vercel-analytics.md +242 -90
  153. package/docs/integrations/x-pixel.md +238 -104
  154. package/docs/integrations/youtube.md +359 -142
  155. package/docs/upgrade-v3.md +381 -0
  156. package/package.json +90 -78
  157. package/dist/e2e-test-utils.cjs +0 -166
  158. package/dist/engine/compile.cjs +0 -130
  159. package/dist/engine/runtime.cjs +0 -475
  160. package/dist/registry.cjs +0 -423
  161. package/dist/resolve.cjs +0 -71
  162. package/dist/types.cjs +0 -69
  163. package/dist/vendors/_shared/attributes.cjs +0 -55
  164. package/dist/vendors/_shared/google-consent.cjs +0 -69
  165. package/dist/vendors/_shared/install-builders.cjs +0 -59
  166. package/dist/vendors/_shared/script-url.cjs +0 -78
  167. package/dist/vendors/ads-and-pixels/linkedin-insights.cjs +0 -89
  168. package/dist/vendors/ads-and-pixels/meta-pixel.cjs +0 -206
  169. package/dist/vendors/ads-and-pixels/microsoft-uet.cjs +0 -151
  170. package/dist/vendors/ads-and-pixels/reddit-pixel.cjs +0 -151
  171. package/dist/vendors/ads-and-pixels/snapchat-pixel.cjs +0 -131
  172. package/dist/vendors/ads-and-pixels/tiktok-pixel.cjs +0 -130
  173. package/dist/vendors/ads-and-pixels/x-pixel.cjs +0 -92
  174. package/dist/vendors/analytics/adobe-analytics.cjs +0 -90
  175. package/dist/vendors/analytics/ahrefs-analytics.cjs +0 -68
  176. package/dist/vendors/analytics/amplitude.cjs +0 -193
  177. package/dist/vendors/analytics/clearbit.cjs +0 -69
  178. package/dist/vendors/analytics/cloudflare-web-analytics.cjs +0 -73
  179. package/dist/vendors/analytics/databuddy.cjs +0 -144
  180. package/dist/vendors/analytics/fathom-analytics.cjs +0 -76
  181. package/dist/vendors/analytics/google-tag.cjs +0 -107
  182. package/dist/vendors/analytics/heap.cjs +0 -181
  183. package/dist/vendors/analytics/hightouch.cjs +0 -153
  184. package/dist/vendors/analytics/hotjar.cjs +0 -85
  185. package/dist/vendors/analytics/logrocket.cjs +0 -99
  186. package/dist/vendors/analytics/matomo-analytics.cjs +0 -232
  187. package/dist/vendors/analytics/microsoft-clarity.cjs +0 -138
  188. package/dist/vendors/analytics/mixpanel-analytics.cjs +0 -134
  189. package/dist/vendors/analytics/pirsch.cjs +0 -108
  190. package/dist/vendors/analytics/plausible-analytics.cjs +0 -122
  191. package/dist/vendors/analytics/posthog.cjs +0 -236
  192. package/dist/vendors/analytics/promptwatch.cjs +0 -70
  193. package/dist/vendors/analytics/rudderstack.cjs +0 -227
  194. package/dist/vendors/analytics/rybbit-analytics.cjs +0 -104
  195. package/dist/vendors/analytics/segment.cjs +0 -97
  196. package/dist/vendors/analytics/umami-analytics.cjs +0 -80
  197. package/dist/vendors/analytics/vercel-analytics.cjs +0 -94
  198. package/dist/vendors/functional/crisp.cjs +0 -143
  199. package/dist/vendors/functional/intercom.cjs +0 -89
  200. package/dist/vendors/tag-managers/google-tag-manager.cjs +0 -100
  201. package/docs/shared/react/guides/script-loader.md +0 -311
  202. package/readme.json +0 -19
@@ -1,475 +0,0 @@
1
- "use strict";
2
- var __webpack_require__ = {};
3
- (()=>{
4
- __webpack_require__.d = (exports1, getters, values)=>{
5
- var define = (defs, kind)=>{
6
- for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
- enumerable: true,
8
- [kind]: defs[key]
9
- });
10
- };
11
- define(getters, "get");
12
- define(values, "value");
13
- };
14
- })();
15
- (()=>{
16
- __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
- })();
18
- (()=>{
19
- __webpack_require__.r = (exports1)=>{
20
- if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
- value: 'Module'
22
- });
23
- Object.defineProperty(exports1, '__esModule', {
24
- value: true
25
- });
26
- };
27
- })();
28
- var __webpack_exports__ = {};
29
- __webpack_require__.r(__webpack_exports__);
30
- __webpack_require__.d(__webpack_exports__, {
31
- resolvedManifestToScript: ()=>resolvedManifestToScript
32
- });
33
- const external_c15t_namespaceObject = require("c15t");
34
- const external_types_cjs_namespaceObject = require("../types.cjs");
35
- function isRuntimeValue(value) {
36
- if (null === value || 'object' != typeof value || Array.isArray(value)) return false;
37
- const candidate = value;
38
- return candidate.kind === external_types_cjs_namespaceObject.RUNTIME_VALUE_KIND && ('date' === candidate.value || 'timestamp' === candidate.value);
39
- }
40
- function resolveRuntimeValue(value) {
41
- if ('date' === value.value) return new Date();
42
- return Date.now();
43
- }
44
- function cloneStepValue(value) {
45
- if (isRuntimeValue(value)) return resolveRuntimeValue(value);
46
- if (value instanceof Date) return new Date(value);
47
- if (Array.isArray(value)) return value.map((item)=>cloneStepValue(item));
48
- if (null !== value && 'object' == typeof value) return Object.fromEntries(Object.entries(value).map(([key, nestedValue])=>[
49
- key,
50
- cloneStepValue(nestedValue)
51
- ]));
52
- return value;
53
- }
54
- function isRecord(value) {
55
- return null !== value && 'object' == typeof value && !Array.isArray(value);
56
- }
57
- function getPathTarget(root, path) {
58
- if (0 === path.length) return;
59
- let target = root;
60
- for (const segment of path.slice(0, -1)){
61
- const next = target[segment];
62
- if (null === next || 'object' != typeof next) return;
63
- target = next;
64
- }
65
- return {
66
- target,
67
- key: path[path.length - 1]
68
- };
69
- }
70
- function resolveQueueTarget(root, queue, owner) {
71
- if ('global' in queue && 'string' == typeof queue.global) {
72
- const queueTarget = root[queue.global];
73
- return Array.isArray(queueTarget) ? queueTarget : void 0;
74
- }
75
- if (!owner) return;
76
- const queueProperty = queue.property;
77
- const queueTarget = owner[queueProperty];
78
- return Array.isArray(queueTarget) ? queueTarget : void 0;
79
- }
80
- function executeStep(step) {
81
- const win = window;
82
- switch(step.type){
83
- case 'setGlobal':
84
- {
85
- const shouldSet = false !== step.ifUndefined;
86
- if (shouldSet && void 0 !== win[step.name]) break;
87
- win[step.name] = cloneStepValue(step.value);
88
- break;
89
- }
90
- case 'defineQueueFunction':
91
- {
92
- const shouldSet = false !== step.ifUndefined;
93
- if (shouldSet && void 0 !== win[step.name]) break;
94
- win[step.name] = function() {
95
- const queueTarget = win[step.queue];
96
- if (!Array.isArray(queueTarget)) return;
97
- if ('array' === step.pushStyle) return void queueTarget.push(Array.from(arguments));
98
- queueTarget.push(arguments);
99
- };
100
- break;
101
- }
102
- case 'defineStubFunction':
103
- {
104
- const shouldSet = false !== step.ifUndefined;
105
- if (shouldSet && void 0 !== win[step.name]) break;
106
- const stub = function() {
107
- const self = win[step.name];
108
- const dispatcher = self && step.dispatchProperty ? self[step.dispatchProperty] : void 0;
109
- const runtimeArgs = Array.from(arguments);
110
- if ('function' == typeof dispatcher) return void dispatcher.apply(self, runtimeArgs);
111
- const queueTarget = resolveQueueTarget(win, step.queue, self);
112
- if (!queueTarget) return;
113
- if ('array' === step.queueFormat) return void queueTarget.push(runtimeArgs);
114
- queueTarget.push(arguments);
115
- };
116
- win[step.name] = stub;
117
- const stubRecord = stub;
118
- if ('property' in step.queue && 'string' == typeof step.queue.property) {
119
- const queueProperty = step.queue.property;
120
- if (void 0 === stubRecord[queueProperty]) stubRecord[queueProperty] = [];
121
- }
122
- for (const alias of step.aliases ?? [])win[alias] = stub;
123
- for (const selfReference of step.selfReferences ?? [])stubRecord[selfReference] = stub;
124
- for (const [key, value] of Object.entries(step.properties ?? {}))stubRecord[key] = cloneStepValue(value);
125
- break;
126
- }
127
- case 'callGlobal':
128
- {
129
- const target = win[step.global];
130
- if (!target) break;
131
- const args = (step.args ?? []).map((arg)=>cloneStepValue(arg));
132
- if (step.method) {
133
- const objectTarget = target;
134
- const method = objectTarget[step.method];
135
- if ('function' == typeof method) method.apply(objectTarget, args);
136
- } else if ('function' == typeof target) target(...args);
137
- break;
138
- }
139
- case 'pushToQueue':
140
- {
141
- const queueTarget = win[step.queue];
142
- if (Array.isArray(queueTarget)) queueTarget.push(cloneStepValue(step.value));
143
- break;
144
- }
145
- case 'setGlobalPath':
146
- {
147
- const rootGlobal = step.path[0];
148
- if (step.ifGlobalIsQueue && (!rootGlobal || !Array.isArray(win[rootGlobal]))) break;
149
- const pathTarget = getPathTarget(win, step.path);
150
- if (!pathTarget) break;
151
- pathTarget.target[pathTarget.key] = cloneStepValue(step.value);
152
- break;
153
- }
154
- case 'defineQueueMethods':
155
- {
156
- const target = win[step.target];
157
- if (null === target || 'object' != typeof target && 'function' != typeof target) break;
158
- if (!step.queue && !Array.isArray(target)) break;
159
- const targetRecord = target;
160
- for (const methodName of step.methods)targetRecord[methodName] = (...args)=>{
161
- const queueTarget = resolveQueueTarget(win, step.queue ?? {
162
- global: step.target
163
- }, targetRecord);
164
- if (!queueTarget) return;
165
- if ('methodCall' === step.queueFormat || 'wrappedMethodCall' === step.queueFormat || 'voidMethodCall' === step.queueFormat) {
166
- const promise = new Promise((resolve)=>{
167
- queueTarget.push({
168
- name: methodName,
169
- args,
170
- resolve
171
- });
172
- });
173
- if ('wrappedMethodCall' === step.queueFormat) return {
174
- promise
175
- };
176
- if ('voidMethodCall' === step.queueFormat) return;
177
- return promise;
178
- }
179
- if ('callback' === step.queueFormat) return void queueTarget.push({
180
- name: methodName,
181
- fn: ()=>{
182
- const latestTarget = win[step.target];
183
- if (null === latestTarget || 'object' != typeof latestTarget && 'function' != typeof latestTarget) return;
184
- const method = latestTarget[methodName];
185
- if ('function' == typeof method) method.apply(latestTarget, args);
186
- }
187
- });
188
- queueTarget.push([
189
- methodName,
190
- ...args
191
- ]);
192
- };
193
- break;
194
- }
195
- case 'defineQueueClass':
196
- {
197
- const target = win[step.target];
198
- if (null === target || 'object' != typeof target && 'function' != typeof target) break;
199
- const queueProperty = step.queueProperty ?? '_q';
200
- const QueueClass = function() {
201
- this[queueProperty] = [];
202
- };
203
- const prototype = QueueClass.prototype;
204
- for (const methodName of step.methods)prototype[methodName] = function(...args) {
205
- const queueTarget = this[queueProperty];
206
- if (Array.isArray(queueTarget)) queueTarget.push({
207
- name: methodName,
208
- args
209
- });
210
- return this;
211
- };
212
- target[step.name] = QueueClass;
213
- break;
214
- }
215
- case 'defineGlobalMethods':
216
- {
217
- const target = win[step.target];
218
- if (null === target || 'object' != typeof target && 'function' != typeof target) break;
219
- if (step.ifGlobalIsQueue && !Array.isArray(target)) break;
220
- const targetRecord = target;
221
- for (const method of step.methods)targetRecord[method.name] = 'return' === method.behavior ? ()=>cloneStepValue(method.value) : ()=>{};
222
- break;
223
- }
224
- case 'constructGlobal':
225
- {
226
- const Constructor = win[step.constructor];
227
- if ('function' != typeof Constructor) break;
228
- const args = (step.args ?? []).map((arg)=>cloneStepValue(arg));
229
- if (step.copyAssignedValueToArgProperty) {
230
- const firstArg = args[0];
231
- const targetOptions = isRecord(firstArg) ? firstArg : {};
232
- targetOptions[step.copyAssignedValueToArgProperty] = win[step.assignTo];
233
- if (!isRecord(firstArg)) args.unshift(targetOptions);
234
- }
235
- win[step.assignTo] = new Constructor(...args);
236
- break;
237
- }
238
- case 'loadScript':
239
- break;
240
- }
241
- }
242
- function executePhaseSteps(steps, context) {
243
- if (0 === steps.length) return;
244
- (0, external_c15t_namespaceObject.emitScriptDebugEvent)({
245
- source: 'manifest-runtime',
246
- scope: 'phase',
247
- action: 'phase_start',
248
- message: `Manifest phase ${context.phase} started`,
249
- scriptId: context.scriptId,
250
- elementId: context.elementId,
251
- hasConsent: context.hasConsent,
252
- callback: context.callback,
253
- phase: context.phase,
254
- data: {
255
- stepCount: steps.length
256
- }
257
- });
258
- for (const [stepIndex, step] of steps.entries())try {
259
- executeStep(step);
260
- (0, external_c15t_namespaceObject.emitScriptDebugEvent)({
261
- source: 'manifest-runtime',
262
- scope: 'step',
263
- action: 'step_executed',
264
- message: `Executed ${step.type}`,
265
- scriptId: context.scriptId,
266
- elementId: context.elementId,
267
- hasConsent: context.hasConsent,
268
- callback: context.callback,
269
- phase: context.phase,
270
- stepType: step.type,
271
- stepIndex
272
- });
273
- } catch (error) {
274
- (0, external_c15t_namespaceObject.emitScriptDebugEvent)({
275
- source: 'manifest-runtime',
276
- scope: 'step',
277
- action: 'step_error',
278
- message: `Failed to execute ${step.type}`,
279
- scriptId: context.scriptId,
280
- elementId: context.elementId,
281
- hasConsent: context.hasConsent,
282
- callback: context.callback,
283
- phase: context.phase,
284
- stepType: step.type,
285
- stepIndex,
286
- data: {
287
- error: error instanceof Error ? error.message : 'string' == typeof error ? error : 'Unknown error'
288
- }
289
- });
290
- throw error;
291
- }
292
- (0, external_c15t_namespaceObject.emitScriptDebugEvent)({
293
- source: 'manifest-runtime',
294
- scope: 'phase',
295
- action: 'phase_complete',
296
- message: `Manifest phase ${context.phase} completed`,
297
- scriptId: context.scriptId,
298
- elementId: context.elementId,
299
- hasConsent: context.hasConsent,
300
- callback: context.callback,
301
- phase: context.phase,
302
- data: {
303
- stepCount: steps.length
304
- }
305
- });
306
- }
307
- function mapConsentState(mapping, consents) {
308
- const result = {};
309
- for (const [c15tCategory, vendorTypes] of Object.entries(mapping)){
310
- const isGranted = consents[c15tCategory];
311
- for (const vendorType of vendorTypes)result[vendorType] = isGranted ? 'granted' : 'denied';
312
- }
313
- return result;
314
- }
315
- function partitionConsentIds(mapping, consents) {
316
- const allowedConsentIds = [];
317
- const deniedConsentIds = [];
318
- for (const [c15tCategory, consentIds] of Object.entries(mapping)){
319
- const isGranted = consents[c15tCategory];
320
- for (const consentId of consentIds)(isGranted ? allowedConsentIds : deniedConsentIds).push(consentId);
321
- }
322
- return {
323
- allowedConsentIds,
324
- deniedConsentIds
325
- };
326
- }
327
- function getConsentSignalSteps(resolvedManifest, mode, consents) {
328
- if (!resolvedManifest.consentMapping || !resolvedManifest.consentSignal) return [];
329
- switch(resolvedManifest.consentSignal){
330
- case 'gtag':
331
- {
332
- const mapped = mapConsentState(resolvedManifest.consentMapping, consents);
333
- return [
334
- {
335
- type: 'callGlobal',
336
- global: resolvedManifest.consentSignalTarget ?? 'gtag',
337
- args: [
338
- 'consent',
339
- mode,
340
- mapped
341
- ]
342
- }
343
- ];
344
- }
345
- case 'rudderstack':
346
- {
347
- const partition = partitionConsentIds(resolvedManifest.consentMapping, consents);
348
- return [
349
- {
350
- type: 'callGlobal',
351
- global: resolvedManifest.consentSignalTarget ?? 'rudderanalytics',
352
- method: 'consent',
353
- args: [
354
- {
355
- consentManagement: {
356
- enabled: true,
357
- provider: 'custom',
358
- allowedConsentIds: partition.allowedConsentIds,
359
- deniedConsentIds: partition.deniedConsentIds
360
- }
361
- }
362
- ]
363
- }
364
- ];
365
- }
366
- }
367
- }
368
- function resolvedManifestToScript(resolvedManifest) {
369
- const hasConsentMapping = !!(resolvedManifest.consentMapping && resolvedManifest.consentSignal);
370
- const hasLoadConsentBranches = !!(resolvedManifest.onLoadGrantedSteps.length > 0 || resolvedManifest.onLoadDeniedSteps.length > 0);
371
- const hasConsentLifecycle = !!(resolvedManifest.onConsentChangeSteps.length > 0 || resolvedManifest.onConsentGrantedSteps.length > 0 || resolvedManifest.onConsentDeniedSteps.length > 0 || hasConsentMapping);
372
- const script = {
373
- id: resolvedManifest.vendor,
374
- category: resolvedManifest.category,
375
- alwaysLoad: resolvedManifest.alwaysLoad,
376
- persistAfterConsentRevoked: resolvedManifest.persistAfterConsentRevoked,
377
- callbackOnly: resolvedManifest.loadScript ? void 0 : true,
378
- src: resolvedManifest.loadScript?.src,
379
- async: resolvedManifest.loadScript?.async,
380
- defer: resolvedManifest.loadScript?.defer,
381
- attributes: resolvedManifest.loadScript?.attributes
382
- };
383
- if (resolvedManifest.bootstrapSteps.length > 0 || resolvedManifest.setupSteps.length > 0 || resolvedManifest.onBeforeLoadGrantedSteps.length > 0 || resolvedManifest.onBeforeLoadDeniedSteps.length > 0 || hasConsentMapping) script.onBeforeLoad = (info)=>{
384
- const baseContext = {
385
- scriptId: resolvedManifest.vendor,
386
- elementId: info.elementId,
387
- hasConsent: info.hasConsent,
388
- callback: 'onBeforeLoad'
389
- };
390
- executePhaseSteps(resolvedManifest.bootstrapSteps, {
391
- ...baseContext,
392
- phase: 'bootstrap'
393
- });
394
- executePhaseSteps(getConsentSignalSteps(resolvedManifest, 'default', info.consents), {
395
- ...baseContext,
396
- phase: 'consent-default'
397
- });
398
- executePhaseSteps(resolvedManifest.setupSteps, {
399
- ...baseContext,
400
- phase: 'setup'
401
- });
402
- executePhaseSteps(info.hasConsent ? resolvedManifest.onBeforeLoadGrantedSteps : resolvedManifest.onBeforeLoadDeniedSteps, {
403
- ...baseContext,
404
- phase: info.hasConsent ? 'onBeforeLoadGranted' : 'onBeforeLoadDenied'
405
- });
406
- };
407
- if (resolvedManifest.afterLoadSteps.length > 0) script.onLoad = (info)=>{
408
- const baseContext = {
409
- scriptId: resolvedManifest.vendor,
410
- elementId: info.elementId,
411
- hasConsent: info.hasConsent,
412
- callback: 'onLoad'
413
- };
414
- executePhaseSteps(resolvedManifest.afterLoadSteps, {
415
- ...baseContext,
416
- phase: 'afterLoad'
417
- });
418
- if (info.hasConsent && resolvedManifest.onLoadGrantedSteps.length > 0) executePhaseSteps(resolvedManifest.onLoadGrantedSteps, {
419
- ...baseContext,
420
- phase: 'onLoadGranted'
421
- });
422
- else if (!info.hasConsent && resolvedManifest.onLoadDeniedSteps.length > 0) executePhaseSteps(resolvedManifest.onLoadDeniedSteps, {
423
- ...baseContext,
424
- phase: 'onLoadDenied'
425
- });
426
- };
427
- else if (hasLoadConsentBranches) script.onLoad = (info)=>{
428
- const baseContext = {
429
- scriptId: resolvedManifest.vendor,
430
- elementId: info.elementId,
431
- hasConsent: info.hasConsent,
432
- callback: 'onLoad'
433
- };
434
- if (info.hasConsent && resolvedManifest.onLoadGrantedSteps.length > 0) executePhaseSteps(resolvedManifest.onLoadGrantedSteps, {
435
- ...baseContext,
436
- phase: 'onLoadGranted'
437
- });
438
- else if (!info.hasConsent && resolvedManifest.onLoadDeniedSteps.length > 0) executePhaseSteps(resolvedManifest.onLoadDeniedSteps, {
439
- ...baseContext,
440
- phase: 'onLoadDenied'
441
- });
442
- };
443
- if (hasConsentLifecycle) script.onConsentChange = (info)=>{
444
- const baseContext = {
445
- scriptId: resolvedManifest.vendor,
446
- elementId: info.elementId,
447
- hasConsent: info.hasConsent,
448
- callback: 'onConsentChange'
449
- };
450
- executePhaseSteps(getConsentSignalSteps(resolvedManifest, 'update', info.consents), {
451
- ...baseContext,
452
- phase: 'consent-update'
453
- });
454
- if (resolvedManifest.onConsentChangeSteps.length > 0) executePhaseSteps(resolvedManifest.onConsentChangeSteps, {
455
- ...baseContext,
456
- phase: 'onConsentChange'
457
- });
458
- if (info.hasConsent && resolvedManifest.onConsentGrantedSteps.length > 0) executePhaseSteps(resolvedManifest.onConsentGrantedSteps, {
459
- ...baseContext,
460
- phase: 'onConsentGranted'
461
- });
462
- else if (!info.hasConsent && resolvedManifest.onConsentDeniedSteps.length > 0) executePhaseSteps(resolvedManifest.onConsentDeniedSteps, {
463
- ...baseContext,
464
- phase: 'onConsentDenied'
465
- });
466
- };
467
- return script;
468
- }
469
- exports.resolvedManifestToScript = __webpack_exports__.resolvedManifestToScript;
470
- for(var __rspack_i in __webpack_exports__)if (-1 === [
471
- "resolvedManifestToScript"
472
- ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
473
- Object.defineProperty(exports, '__esModule', {
474
- value: true
475
- });