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