@c15t/scripts 2.0.0-rc.1 → 2.0.0
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/README.md +3 -3
- package/dist/databuddy.cjs +103 -48
- package/dist/databuddy.js +99 -47
- package/dist/engine/compile.cjs +126 -0
- package/dist/engine/compile.js +89 -0
- package/dist/engine/runtime.cjs +379 -0
- package/dist/engine/runtime.js +345 -0
- package/dist/google-tag-manager.cjs +78 -86
- package/dist/google-tag-manager.js +74 -79
- package/dist/google-tag.cjs +86 -37
- package/dist/google-tag.js +82 -36
- package/dist/linkedin-insights.cjs +51 -33
- package/dist/linkedin-insights.js +46 -31
- package/dist/meta-pixel.cjs +90 -28
- package/dist/meta-pixel.js +86 -27
- package/dist/microsoft-uet.cjs +90 -50
- package/dist/microsoft-uet.js +86 -49
- package/dist/posthog.cjs +100 -51
- package/dist/posthog.js +96 -50
- package/dist/resolve.cjs +67 -0
- package/dist/resolve.js +33 -0
- package/dist/tiktok-pixel.cjs +91 -29
- package/dist/tiktok-pixel.js +86 -27
- package/dist/types.cjs +47 -0
- package/dist/types.js +7 -0
- package/dist/x-pixel.cjs +48 -14
- package/dist/x-pixel.js +43 -12
- package/dist-types/databuddy.d.ts +144 -0
- package/dist-types/engine/compile.d.ts +3 -0
- package/dist-types/engine/runtime.d.ts +3 -0
- package/dist-types/engine.test.d.ts +1 -0
- package/dist-types/google-tag-manager.d.ts +97 -0
- package/dist-types/google-tag.d.ts +96 -0
- package/dist-types/helpers.test.d.ts +1 -0
- package/dist-types/linkedin-insights.d.ts +79 -0
- package/{dist → dist-types}/meta-pixel.d.ts +61 -14
- package/dist-types/microsoft-uet.d.ts +94 -0
- package/dist-types/posthog.d.ts +112 -0
- package/dist-types/resolve.d.ts +9 -0
- package/dist-types/tiktok-pixel.d.ts +91 -0
- package/dist-types/types.d.ts +259 -0
- package/{dist → dist-types}/x-pixel.d.ts +38 -12
- package/package.json +9 -8
- package/dist/databuddy.d.ts +0 -104
- package/dist/databuddy.d.ts.map +0 -1
- package/dist/google-tag-manager.d.ts +0 -63
- package/dist/google-tag-manager.d.ts.map +0 -1
- package/dist/google-tag.d.ts +0 -38
- package/dist/google-tag.d.ts.map +0 -1
- package/dist/linkedin-insights.d.ts +0 -48
- package/dist/linkedin-insights.d.ts.map +0 -1
- package/dist/meta-pixel.d.ts.map +0 -1
- package/dist/microsoft-uet.d.ts +0 -40
- package/dist/microsoft-uet.d.ts.map +0 -1
- package/dist/posthog.d.ts +0 -54
- package/dist/posthog.d.ts.map +0 -1
- package/dist/tiktok-pixel.d.ts +0 -44
- package/dist/tiktok-pixel.d.ts.map +0 -1
- package/dist/x-pixel.d.ts.map +0 -1
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
import { emitScriptDebugEvent } from "c15t";
|
|
2
|
+
function cloneStepValue(value) {
|
|
3
|
+
if (value instanceof Date) return new Date(value);
|
|
4
|
+
if (Array.isArray(value)) return value.map((item)=>cloneStepValue(item));
|
|
5
|
+
if (null !== value && 'object' == typeof value) return Object.fromEntries(Object.entries(value).map(([key, nestedValue])=>[
|
|
6
|
+
key,
|
|
7
|
+
cloneStepValue(nestedValue)
|
|
8
|
+
]));
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
function isRecord(value) {
|
|
12
|
+
return null !== value && 'object' == typeof value && !Array.isArray(value);
|
|
13
|
+
}
|
|
14
|
+
function getPathTarget(root, path) {
|
|
15
|
+
if (0 === path.length) return;
|
|
16
|
+
let target = root;
|
|
17
|
+
for (const segment of path.slice(0, -1)){
|
|
18
|
+
const next = target[segment];
|
|
19
|
+
if (null === next || 'object' != typeof next) return;
|
|
20
|
+
target = next;
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
target,
|
|
24
|
+
key: path[path.length - 1]
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function resolveQueueTarget(root, queue, owner) {
|
|
28
|
+
if ('global' in queue && 'string' == typeof queue.global) {
|
|
29
|
+
const queueTarget = root[queue.global];
|
|
30
|
+
return Array.isArray(queueTarget) ? queueTarget : void 0;
|
|
31
|
+
}
|
|
32
|
+
if (!owner) return;
|
|
33
|
+
const queueProperty = queue.property;
|
|
34
|
+
const queueTarget = owner[queueProperty];
|
|
35
|
+
return Array.isArray(queueTarget) ? queueTarget : void 0;
|
|
36
|
+
}
|
|
37
|
+
function executeStep(step) {
|
|
38
|
+
const win = window;
|
|
39
|
+
switch(step.type){
|
|
40
|
+
case 'setGlobal':
|
|
41
|
+
{
|
|
42
|
+
const shouldSet = false !== step.ifUndefined;
|
|
43
|
+
if (shouldSet && void 0 !== win[step.name]) break;
|
|
44
|
+
win[step.name] = cloneStepValue(step.value);
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
case 'defineQueueFunction':
|
|
48
|
+
{
|
|
49
|
+
const shouldSet = false !== step.ifUndefined;
|
|
50
|
+
if (shouldSet && void 0 !== win[step.name]) break;
|
|
51
|
+
win[step.name] = function(...args) {
|
|
52
|
+
const queueTarget = win[step.queue];
|
|
53
|
+
if (!Array.isArray(queueTarget)) return;
|
|
54
|
+
queueTarget.push('array' === step.pushStyle ? [
|
|
55
|
+
...args
|
|
56
|
+
] : args);
|
|
57
|
+
};
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
case 'defineStubFunction':
|
|
61
|
+
{
|
|
62
|
+
const shouldSet = false !== step.ifUndefined;
|
|
63
|
+
if (shouldSet && void 0 !== win[step.name]) break;
|
|
64
|
+
const stub = function(...args) {
|
|
65
|
+
const self = win[step.name];
|
|
66
|
+
const dispatcher = self && step.dispatchProperty ? self[step.dispatchProperty] : void 0;
|
|
67
|
+
if ('function' == typeof dispatcher) return void dispatcher.apply(self, args);
|
|
68
|
+
const queueTarget = resolveQueueTarget(win, step.queue, self);
|
|
69
|
+
if (!queueTarget) return;
|
|
70
|
+
queueTarget.push('array' === step.queueFormat ? [
|
|
71
|
+
...args
|
|
72
|
+
] : args);
|
|
73
|
+
};
|
|
74
|
+
win[step.name] = stub;
|
|
75
|
+
const stubRecord = stub;
|
|
76
|
+
if ('property' in step.queue && 'string' == typeof step.queue.property) {
|
|
77
|
+
const queueProperty = step.queue.property;
|
|
78
|
+
if (void 0 === stubRecord[queueProperty]) stubRecord[queueProperty] = [];
|
|
79
|
+
}
|
|
80
|
+
for (const alias of step.aliases ?? [])win[alias] = stub;
|
|
81
|
+
for (const selfReference of step.selfReferences ?? [])stubRecord[selfReference] = stub;
|
|
82
|
+
for (const [key, value] of Object.entries(step.properties ?? {}))stubRecord[key] = cloneStepValue(value);
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
case 'callGlobal':
|
|
86
|
+
{
|
|
87
|
+
const target = win[step.global];
|
|
88
|
+
if (!target) break;
|
|
89
|
+
const args = (step.args ?? []).map((arg)=>cloneStepValue(arg));
|
|
90
|
+
if (step.method) {
|
|
91
|
+
const objectTarget = target;
|
|
92
|
+
const method = objectTarget[step.method];
|
|
93
|
+
if ('function' == typeof method) method.apply(objectTarget, args);
|
|
94
|
+
} else if ('function' == typeof target) target(...args);
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
case 'pushToQueue':
|
|
98
|
+
{
|
|
99
|
+
const queueTarget = win[step.queue];
|
|
100
|
+
if (Array.isArray(queueTarget)) queueTarget.push(cloneStepValue(step.value));
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
case 'setGlobalPath':
|
|
104
|
+
{
|
|
105
|
+
const pathTarget = getPathTarget(win, step.path);
|
|
106
|
+
if (!pathTarget) break;
|
|
107
|
+
pathTarget.target[pathTarget.key] = cloneStepValue(step.value);
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
case 'defineQueueMethods':
|
|
111
|
+
{
|
|
112
|
+
const target = win[step.target];
|
|
113
|
+
if (null === target || 'object' != typeof target && 'function' != typeof target) break;
|
|
114
|
+
const targetRecord = target;
|
|
115
|
+
for (const methodName of step.methods)targetRecord[methodName] = (...args)=>{
|
|
116
|
+
const queueTarget = resolveQueueTarget(win, step.queue ?? {
|
|
117
|
+
global: step.target
|
|
118
|
+
}, targetRecord);
|
|
119
|
+
if (!queueTarget) return;
|
|
120
|
+
queueTarget.push([
|
|
121
|
+
methodName,
|
|
122
|
+
...args
|
|
123
|
+
]);
|
|
124
|
+
};
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
case 'defineGlobalMethods':
|
|
128
|
+
{
|
|
129
|
+
const target = win[step.target];
|
|
130
|
+
if (null === target || 'object' != typeof target && 'function' != typeof target) break;
|
|
131
|
+
const targetRecord = target;
|
|
132
|
+
for (const method of step.methods)targetRecord[method.name] = 'return' === method.behavior ? ()=>cloneStepValue(method.value) : ()=>{};
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
case 'constructGlobal':
|
|
136
|
+
{
|
|
137
|
+
const Constructor = win[step.constructor];
|
|
138
|
+
if ('function' != typeof Constructor) break;
|
|
139
|
+
const args = (step.args ?? []).map((arg)=>cloneStepValue(arg));
|
|
140
|
+
if (step.copyAssignedValueToArgProperty) {
|
|
141
|
+
const firstArg = args[0];
|
|
142
|
+
const targetOptions = isRecord(firstArg) ? firstArg : {};
|
|
143
|
+
targetOptions[step.copyAssignedValueToArgProperty] = win[step.assignTo];
|
|
144
|
+
if (!isRecord(firstArg)) args.unshift(targetOptions);
|
|
145
|
+
}
|
|
146
|
+
win[step.assignTo] = new Constructor(...args);
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
case 'loadScript':
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function executePhaseSteps(steps, context) {
|
|
154
|
+
if (0 === steps.length) return;
|
|
155
|
+
emitScriptDebugEvent({
|
|
156
|
+
source: 'manifest-runtime',
|
|
157
|
+
scope: 'phase',
|
|
158
|
+
action: 'phase_start',
|
|
159
|
+
message: `Manifest phase ${context.phase} started`,
|
|
160
|
+
scriptId: context.scriptId,
|
|
161
|
+
elementId: context.elementId,
|
|
162
|
+
hasConsent: context.hasConsent,
|
|
163
|
+
callback: context.callback,
|
|
164
|
+
phase: context.phase,
|
|
165
|
+
data: {
|
|
166
|
+
stepCount: steps.length
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
for (const [stepIndex, step] of steps.entries())try {
|
|
170
|
+
executeStep(step);
|
|
171
|
+
emitScriptDebugEvent({
|
|
172
|
+
source: 'manifest-runtime',
|
|
173
|
+
scope: 'step',
|
|
174
|
+
action: 'step_executed',
|
|
175
|
+
message: `Executed ${step.type}`,
|
|
176
|
+
scriptId: context.scriptId,
|
|
177
|
+
elementId: context.elementId,
|
|
178
|
+
hasConsent: context.hasConsent,
|
|
179
|
+
callback: context.callback,
|
|
180
|
+
phase: context.phase,
|
|
181
|
+
stepType: step.type,
|
|
182
|
+
stepIndex
|
|
183
|
+
});
|
|
184
|
+
} catch (error) {
|
|
185
|
+
emitScriptDebugEvent({
|
|
186
|
+
source: 'manifest-runtime',
|
|
187
|
+
scope: 'step',
|
|
188
|
+
action: 'step_error',
|
|
189
|
+
message: `Failed to execute ${step.type}`,
|
|
190
|
+
scriptId: context.scriptId,
|
|
191
|
+
elementId: context.elementId,
|
|
192
|
+
hasConsent: context.hasConsent,
|
|
193
|
+
callback: context.callback,
|
|
194
|
+
phase: context.phase,
|
|
195
|
+
stepType: step.type,
|
|
196
|
+
stepIndex,
|
|
197
|
+
data: {
|
|
198
|
+
error: error instanceof Error ? error.message : 'string' == typeof error ? error : 'Unknown error'
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
throw error;
|
|
202
|
+
}
|
|
203
|
+
emitScriptDebugEvent({
|
|
204
|
+
source: 'manifest-runtime',
|
|
205
|
+
scope: 'phase',
|
|
206
|
+
action: 'phase_complete',
|
|
207
|
+
message: `Manifest phase ${context.phase} completed`,
|
|
208
|
+
scriptId: context.scriptId,
|
|
209
|
+
elementId: context.elementId,
|
|
210
|
+
hasConsent: context.hasConsent,
|
|
211
|
+
callback: context.callback,
|
|
212
|
+
phase: context.phase,
|
|
213
|
+
data: {
|
|
214
|
+
stepCount: steps.length
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
function mapConsentState(mapping, consents) {
|
|
219
|
+
const result = {};
|
|
220
|
+
for (const [c15tCategory, vendorTypes] of Object.entries(mapping)){
|
|
221
|
+
const isGranted = consents[c15tCategory];
|
|
222
|
+
for (const vendorType of vendorTypes)result[vendorType] = isGranted ? 'granted' : 'denied';
|
|
223
|
+
}
|
|
224
|
+
return result;
|
|
225
|
+
}
|
|
226
|
+
function getConsentSignalSteps(resolvedManifest, mode, consents) {
|
|
227
|
+
if (!resolvedManifest.consentMapping || !resolvedManifest.consentSignal) return [];
|
|
228
|
+
const mapped = mapConsentState(resolvedManifest.consentMapping, consents);
|
|
229
|
+
switch(resolvedManifest.consentSignal){
|
|
230
|
+
case 'gtag':
|
|
231
|
+
return [
|
|
232
|
+
{
|
|
233
|
+
type: 'callGlobal',
|
|
234
|
+
global: resolvedManifest.consentSignalTarget ?? 'gtag',
|
|
235
|
+
args: [
|
|
236
|
+
'consent',
|
|
237
|
+
mode,
|
|
238
|
+
mapped
|
|
239
|
+
]
|
|
240
|
+
}
|
|
241
|
+
];
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
function resolvedManifestToScript(resolvedManifest) {
|
|
245
|
+
const hasConsentMapping = !!(resolvedManifest.consentMapping && resolvedManifest.consentSignal);
|
|
246
|
+
const hasLoadConsentBranches = !!(resolvedManifest.onLoadGrantedSteps.length > 0 || resolvedManifest.onLoadDeniedSteps.length > 0);
|
|
247
|
+
const hasConsentLifecycle = !!(resolvedManifest.onConsentChangeSteps.length > 0 || resolvedManifest.onConsentGrantedSteps.length > 0 || resolvedManifest.onConsentDeniedSteps.length > 0 || hasConsentMapping);
|
|
248
|
+
const script = {
|
|
249
|
+
id: resolvedManifest.vendor,
|
|
250
|
+
category: resolvedManifest.category,
|
|
251
|
+
alwaysLoad: resolvedManifest.alwaysLoad,
|
|
252
|
+
persistAfterConsentRevoked: resolvedManifest.persistAfterConsentRevoked,
|
|
253
|
+
callbackOnly: resolvedManifest.loadScript ? void 0 : true,
|
|
254
|
+
src: resolvedManifest.loadScript?.src,
|
|
255
|
+
async: resolvedManifest.loadScript?.async,
|
|
256
|
+
defer: resolvedManifest.loadScript?.defer,
|
|
257
|
+
attributes: resolvedManifest.loadScript?.attributes
|
|
258
|
+
};
|
|
259
|
+
if (resolvedManifest.bootstrapSteps.length > 0 || resolvedManifest.setupSteps.length > 0 || resolvedManifest.onBeforeLoadGrantedSteps.length > 0 || resolvedManifest.onBeforeLoadDeniedSteps.length > 0 || hasConsentMapping) script.onBeforeLoad = (info)=>{
|
|
260
|
+
const baseContext = {
|
|
261
|
+
scriptId: resolvedManifest.vendor,
|
|
262
|
+
elementId: info.elementId,
|
|
263
|
+
hasConsent: info.hasConsent,
|
|
264
|
+
callback: 'onBeforeLoad'
|
|
265
|
+
};
|
|
266
|
+
executePhaseSteps(resolvedManifest.bootstrapSteps, {
|
|
267
|
+
...baseContext,
|
|
268
|
+
phase: 'bootstrap'
|
|
269
|
+
});
|
|
270
|
+
executePhaseSteps(getConsentSignalSteps(resolvedManifest, 'default', info.consents), {
|
|
271
|
+
...baseContext,
|
|
272
|
+
phase: 'consent-default'
|
|
273
|
+
});
|
|
274
|
+
executePhaseSteps(resolvedManifest.setupSteps, {
|
|
275
|
+
...baseContext,
|
|
276
|
+
phase: 'setup'
|
|
277
|
+
});
|
|
278
|
+
executePhaseSteps(info.hasConsent ? resolvedManifest.onBeforeLoadGrantedSteps : resolvedManifest.onBeforeLoadDeniedSteps, {
|
|
279
|
+
...baseContext,
|
|
280
|
+
phase: info.hasConsent ? 'onBeforeLoadGranted' : 'onBeforeLoadDenied'
|
|
281
|
+
});
|
|
282
|
+
};
|
|
283
|
+
if (resolvedManifest.afterLoadSteps.length > 0) script.onLoad = (info)=>{
|
|
284
|
+
const baseContext = {
|
|
285
|
+
scriptId: resolvedManifest.vendor,
|
|
286
|
+
elementId: info.elementId,
|
|
287
|
+
hasConsent: info.hasConsent,
|
|
288
|
+
callback: 'onLoad'
|
|
289
|
+
};
|
|
290
|
+
executePhaseSteps(resolvedManifest.afterLoadSteps, {
|
|
291
|
+
...baseContext,
|
|
292
|
+
phase: 'afterLoad'
|
|
293
|
+
});
|
|
294
|
+
if (info.hasConsent && resolvedManifest.onLoadGrantedSteps.length > 0) executePhaseSteps(resolvedManifest.onLoadGrantedSteps, {
|
|
295
|
+
...baseContext,
|
|
296
|
+
phase: 'onLoadGranted'
|
|
297
|
+
});
|
|
298
|
+
else if (!info.hasConsent && resolvedManifest.onLoadDeniedSteps.length > 0) executePhaseSteps(resolvedManifest.onLoadDeniedSteps, {
|
|
299
|
+
...baseContext,
|
|
300
|
+
phase: 'onLoadDenied'
|
|
301
|
+
});
|
|
302
|
+
};
|
|
303
|
+
else if (hasLoadConsentBranches) script.onLoad = (info)=>{
|
|
304
|
+
const baseContext = {
|
|
305
|
+
scriptId: resolvedManifest.vendor,
|
|
306
|
+
elementId: info.elementId,
|
|
307
|
+
hasConsent: info.hasConsent,
|
|
308
|
+
callback: 'onLoad'
|
|
309
|
+
};
|
|
310
|
+
if (info.hasConsent && resolvedManifest.onLoadGrantedSteps.length > 0) executePhaseSteps(resolvedManifest.onLoadGrantedSteps, {
|
|
311
|
+
...baseContext,
|
|
312
|
+
phase: 'onLoadGranted'
|
|
313
|
+
});
|
|
314
|
+
else if (!info.hasConsent && resolvedManifest.onLoadDeniedSteps.length > 0) executePhaseSteps(resolvedManifest.onLoadDeniedSteps, {
|
|
315
|
+
...baseContext,
|
|
316
|
+
phase: 'onLoadDenied'
|
|
317
|
+
});
|
|
318
|
+
};
|
|
319
|
+
if (hasConsentLifecycle) script.onConsentChange = (info)=>{
|
|
320
|
+
const baseContext = {
|
|
321
|
+
scriptId: resolvedManifest.vendor,
|
|
322
|
+
elementId: info.elementId,
|
|
323
|
+
hasConsent: info.hasConsent,
|
|
324
|
+
callback: 'onConsentChange'
|
|
325
|
+
};
|
|
326
|
+
executePhaseSteps(getConsentSignalSteps(resolvedManifest, 'update', info.consents), {
|
|
327
|
+
...baseContext,
|
|
328
|
+
phase: 'consent-update'
|
|
329
|
+
});
|
|
330
|
+
if (resolvedManifest.onConsentChangeSteps.length > 0) executePhaseSteps(resolvedManifest.onConsentChangeSteps, {
|
|
331
|
+
...baseContext,
|
|
332
|
+
phase: 'onConsentChange'
|
|
333
|
+
});
|
|
334
|
+
if (info.hasConsent && resolvedManifest.onConsentGrantedSteps.length > 0) executePhaseSteps(resolvedManifest.onConsentGrantedSteps, {
|
|
335
|
+
...baseContext,
|
|
336
|
+
phase: 'onConsentGranted'
|
|
337
|
+
});
|
|
338
|
+
else if (!info.hasConsent && resolvedManifest.onConsentDeniedSteps.length > 0) executePhaseSteps(resolvedManifest.onConsentDeniedSteps, {
|
|
339
|
+
...baseContext,
|
|
340
|
+
phase: 'onConsentDenied'
|
|
341
|
+
});
|
|
342
|
+
};
|
|
343
|
+
return script;
|
|
344
|
+
}
|
|
345
|
+
export { resolvedManifestToScript };
|
|
@@ -13,7 +13,7 @@ var __webpack_require__ = {};
|
|
|
13
13
|
})();
|
|
14
14
|
(()=>{
|
|
15
15
|
__webpack_require__.r = (exports1)=>{
|
|
16
|
-
if (
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
17
|
value: 'Module'
|
|
18
18
|
});
|
|
19
19
|
Object.defineProperty(exports1, '__esModule', {
|
|
@@ -24,101 +24,93 @@ var __webpack_require__ = {};
|
|
|
24
24
|
var __webpack_exports__ = {};
|
|
25
25
|
__webpack_require__.r(__webpack_exports__);
|
|
26
26
|
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
-
|
|
28
|
-
googleTagManager: ()=>googleTagManager
|
|
29
|
-
mapConsentStateToGTM: ()=>mapConsentStateToGTM
|
|
27
|
+
googleTagManagerManifest: ()=>googleTagManagerManifest,
|
|
28
|
+
googleTagManager: ()=>googleTagManager
|
|
30
29
|
});
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
30
|
+
const external_resolve_cjs_namespaceObject = require("./resolve.cjs");
|
|
31
|
+
const external_types_cjs_namespaceObject = require("./types.cjs");
|
|
32
|
+
const googleTagManagerManifest = {
|
|
33
|
+
...external_types_cjs_namespaceObject.vendorManifestContract,
|
|
34
|
+
vendor: 'google-tag-manager',
|
|
35
|
+
category: 'necessary',
|
|
36
|
+
alwaysLoad: true,
|
|
37
|
+
bootstrap: [
|
|
38
|
+
{
|
|
39
|
+
type: 'setGlobal',
|
|
40
|
+
name: 'dataLayer',
|
|
41
|
+
value: [],
|
|
42
|
+
ifUndefined: true
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
type: 'defineQueueFunction',
|
|
46
|
+
name: 'gtag',
|
|
47
|
+
queue: 'dataLayer',
|
|
48
|
+
ifUndefined: true
|
|
49
|
+
}
|
|
46
50
|
],
|
|
47
|
-
|
|
48
|
-
|
|
51
|
+
install: [
|
|
52
|
+
{
|
|
53
|
+
type: 'pushToQueue',
|
|
54
|
+
queue: 'dataLayer',
|
|
55
|
+
value: {
|
|
56
|
+
'gtm.start': '{{loadTime}}',
|
|
57
|
+
event: 'gtm.js'
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
type: 'loadScript',
|
|
62
|
+
src: 'https://www.googletagmanager.com/gtm.js?id={{id}}',
|
|
63
|
+
async: true
|
|
64
|
+
}
|
|
49
65
|
],
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
66
|
+
onConsentChange: [
|
|
67
|
+
{
|
|
68
|
+
type: 'callGlobal',
|
|
69
|
+
global: 'gtag',
|
|
70
|
+
args: [
|
|
71
|
+
'event',
|
|
72
|
+
'{{updateEventName}}'
|
|
73
|
+
]
|
|
74
|
+
}
|
|
54
75
|
],
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
76
|
+
consentMapping: {
|
|
77
|
+
necessary: [
|
|
78
|
+
'security_storage'
|
|
79
|
+
],
|
|
80
|
+
functionality: [
|
|
81
|
+
'functionality_storage'
|
|
82
|
+
],
|
|
83
|
+
measurement: [
|
|
84
|
+
'analytics_storage'
|
|
85
|
+
],
|
|
86
|
+
marketing: [
|
|
87
|
+
'ad_storage',
|
|
88
|
+
'ad_user_data',
|
|
89
|
+
'ad_personalization'
|
|
90
|
+
],
|
|
91
|
+
experience: [
|
|
92
|
+
'personalization_storage'
|
|
93
|
+
]
|
|
94
|
+
},
|
|
95
|
+
consentSignal: 'gtag'
|
|
58
96
|
};
|
|
59
|
-
function
|
|
60
|
-
const
|
|
61
|
-
...
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return gtmConfig;
|
|
69
|
-
}
|
|
70
|
-
function googleTagManager({ id, script, updateEventName }) {
|
|
71
|
-
return {
|
|
72
|
-
...script,
|
|
73
|
-
id: script?.id ? script.id : 'google-tag-manager',
|
|
74
|
-
src: script?.src ? script.src : `https://www.googletagmanager.com/gtm.js?id=${id}`,
|
|
75
|
-
category: script?.category ?? 'necessary',
|
|
76
|
-
async: script?.async ?? true,
|
|
77
|
-
alwaysLoad: true,
|
|
78
|
-
onBeforeLoad: ({ consents, elementId, ...rest })=>{
|
|
79
|
-
const gtmConsent = consents ? mapConsentStateToGTM(consents) : DEFAULT_GTM_CONSENT_CONFIG;
|
|
80
|
-
const setupScript = document.createElement("script");
|
|
81
|
-
setupScript.id = `${elementId}-init`;
|
|
82
|
-
setupScript.textContent = `
|
|
83
|
-
window.dataLayer = window.dataLayer || [];
|
|
84
|
-
window.gtag = function gtag() {
|
|
85
|
-
window.dataLayer.push(arguments);
|
|
86
|
-
};
|
|
87
|
-
window.gtag('consent', 'default', {
|
|
88
|
-
...${JSON.stringify(gtmConsent)},
|
|
89
|
-
});
|
|
90
|
-
window.dataLayer.push({
|
|
91
|
-
'gtm.start': Date.now(),
|
|
92
|
-
event: 'gtm.js',
|
|
97
|
+
function googleTagManager({ id, updateEventName, consentMapping }) {
|
|
98
|
+
const manifest = consentMapping ? {
|
|
99
|
+
...googleTagManagerManifest,
|
|
100
|
+
consentMapping
|
|
101
|
+
} : googleTagManagerManifest;
|
|
102
|
+
const resolved = (0, external_resolve_cjs_namespaceObject.resolveManifest)(manifest, {
|
|
103
|
+
id,
|
|
104
|
+
loadTime: Date.now(),
|
|
105
|
+
updateEventName: updateEventName ?? 'consent-update'
|
|
93
106
|
});
|
|
94
|
-
|
|
95
|
-
if (!document.head) throw new Error("Document head is not available for script injection");
|
|
96
|
-
document.head.appendChild(setupScript);
|
|
97
|
-
if (script?.onBeforeLoad) script.onBeforeLoad({
|
|
98
|
-
consents,
|
|
99
|
-
elementId,
|
|
100
|
-
...rest
|
|
101
|
-
});
|
|
102
|
-
},
|
|
103
|
-
onConsentChange ({ consents, ...rest }) {
|
|
104
|
-
if (window.gtag) {
|
|
105
|
-
window.gtag('consent', 'update', mapConsentStateToGTM(consents));
|
|
106
|
-
window.gtag('event', updateEventName ?? 'consent-update');
|
|
107
|
-
}
|
|
108
|
-
if (script?.onConsentChange) script.onConsentChange({
|
|
109
|
-
consents,
|
|
110
|
-
...rest
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
};
|
|
107
|
+
return resolved;
|
|
114
108
|
}
|
|
115
|
-
exports.DEFAULT_GTM_CONSENT_CONFIG = __webpack_exports__.DEFAULT_GTM_CONSENT_CONFIG;
|
|
116
109
|
exports.googleTagManager = __webpack_exports__.googleTagManager;
|
|
117
|
-
exports.
|
|
110
|
+
exports.googleTagManagerManifest = __webpack_exports__.googleTagManagerManifest;
|
|
118
111
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
119
|
-
"DEFAULT_GTM_CONSENT_CONFIG",
|
|
120
112
|
"googleTagManager",
|
|
121
|
-
"
|
|
113
|
+
"googleTagManagerManifest"
|
|
122
114
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
123
115
|
Object.defineProperty(exports, '__esModule', {
|
|
124
116
|
value: true
|