@walkeros/web-destination-gtag 0.0.0-next-20251219153324
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 +314 -0
- package/dist/dev.d.mts +240 -0
- package/dist/dev.d.ts +240 -0
- package/dist/dev.js +1 -0
- package/dist/dev.js.map +1 -0
- package/dist/dev.mjs +1 -0
- package/dist/dev.mjs.map +1 -0
- package/dist/examples/index.d.mts +89 -0
- package/dist/examples/index.d.ts +89 -0
- package/dist/examples/index.js +328 -0
- package/dist/examples/index.mjs +305 -0
- package/dist/index.browser.js +1 -0
- package/dist/index.d.mts +109 -0
- package/dist/index.d.ts +109 -0
- package/dist/index.es5.js +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +66 -0
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// src/examples/env.ts
|
|
8
|
+
var env_exports = {};
|
|
9
|
+
__export(env_exports, {
|
|
10
|
+
init: () => init,
|
|
11
|
+
push: () => push,
|
|
12
|
+
simulation: () => simulation
|
|
13
|
+
});
|
|
14
|
+
var noop = () => {
|
|
15
|
+
};
|
|
16
|
+
var init = {
|
|
17
|
+
window: {
|
|
18
|
+
gtag: void 0,
|
|
19
|
+
dataLayer: []
|
|
20
|
+
},
|
|
21
|
+
document: {
|
|
22
|
+
createElement: () => ({
|
|
23
|
+
src: "",
|
|
24
|
+
setAttribute: () => {
|
|
25
|
+
},
|
|
26
|
+
removeAttribute: () => {
|
|
27
|
+
}
|
|
28
|
+
}),
|
|
29
|
+
head: { appendChild: () => {
|
|
30
|
+
} }
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var push = {
|
|
34
|
+
window: {
|
|
35
|
+
gtag: Object.assign(noop, {
|
|
36
|
+
// Add any gtag-specific properties if needed
|
|
37
|
+
}),
|
|
38
|
+
dataLayer: []
|
|
39
|
+
},
|
|
40
|
+
document: {
|
|
41
|
+
createElement: () => ({
|
|
42
|
+
src: "",
|
|
43
|
+
setAttribute: () => {
|
|
44
|
+
},
|
|
45
|
+
removeAttribute: () => {
|
|
46
|
+
}
|
|
47
|
+
}),
|
|
48
|
+
head: { appendChild: () => {
|
|
49
|
+
} }
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
var simulation = [
|
|
53
|
+
"call:window.gtag"
|
|
54
|
+
// Track gtag function calls
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
// src/examples/events.ts
|
|
58
|
+
var events_exports = {};
|
|
59
|
+
__export(events_exports, {
|
|
60
|
+
adsConversion: () => adsConversion,
|
|
61
|
+
ga4AddToCart: () => ga4AddToCart,
|
|
62
|
+
ga4Purchase: () => ga4Purchase,
|
|
63
|
+
gtmEvent: () => gtmEvent
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// ../../../core/dist/index.mjs
|
|
67
|
+
var e = Object.defineProperty;
|
|
68
|
+
var c = {};
|
|
69
|
+
((t, n) => {
|
|
70
|
+
for (var r in n) e(t, r, { get: n[r], enumerable: true });
|
|
71
|
+
})(c, { Level: () => a });
|
|
72
|
+
var a = ((e2) => (e2[e2.ERROR = 0] = "ERROR", e2[e2.INFO = 1] = "INFO", e2[e2.DEBUG = 2] = "DEBUG", e2))(a || {});
|
|
73
|
+
var E = { merge: true, shallow: true, extend: true };
|
|
74
|
+
function S(e2, t = {}, n = {}) {
|
|
75
|
+
n = { ...E, ...n };
|
|
76
|
+
const r = Object.entries(t).reduce((t2, [r2, o]) => {
|
|
77
|
+
const i = e2[r2];
|
|
78
|
+
return n.merge && Array.isArray(i) && Array.isArray(o) ? t2[r2] = o.reduce((e3, t3) => e3.includes(t3) ? e3 : [...e3, t3], [...i]) : (n.extend || r2 in e2) && (t2[r2] = o), t2;
|
|
79
|
+
}, {});
|
|
80
|
+
return n.shallow ? { ...e2, ...r } : (Object.assign(e2, r), e2);
|
|
81
|
+
}
|
|
82
|
+
function A(e2) {
|
|
83
|
+
return Array.isArray(e2);
|
|
84
|
+
}
|
|
85
|
+
function _(e2) {
|
|
86
|
+
return "object" == typeof e2 && null !== e2 && !A(e2) && "[object Object]" === Object.prototype.toString.call(e2);
|
|
87
|
+
}
|
|
88
|
+
function W(e2 = {}) {
|
|
89
|
+
var _a;
|
|
90
|
+
const t = e2.timestamp || (/* @__PURE__ */ new Date()).setHours(0, 13, 37, 0), n = e2.group || "gr0up", r = e2.count || 1, o = S({ name: "entity action", data: { string: "foo", number: 1, boolean: true, array: [0, "text", false], not: void 0 }, context: { dev: ["test", 1] }, globals: { lang: "elb" }, custom: { completely: "random" }, user: { id: "us3r", device: "c00k13", session: "s3ss10n" }, nested: [{ entity: "child", data: { is: "subordinated" }, nested: [], context: { element: ["child", 0] } }], consent: { functional: true }, id: `${t}-${n}-${r}`, trigger: "test", entity: "entity", action: "action", timestamp: t, timing: 3.14, group: n, count: r, version: { source: "0.5.1-next.0", tagging: 1 }, source: { type: "web", id: "https://localhost:80", previous_id: "http://remotehost:9001" } }, e2, { merge: false });
|
|
91
|
+
if (e2.name) {
|
|
92
|
+
const [t2, n2] = (_a = e2.name.split(" ")) != null ? _a : [];
|
|
93
|
+
t2 && n2 && (o.entity = t2, o.action = n2);
|
|
94
|
+
}
|
|
95
|
+
return o;
|
|
96
|
+
}
|
|
97
|
+
function B(e2 = "entity action", t = {}) {
|
|
98
|
+
const n = t.timestamp || (/* @__PURE__ */ new Date()).setHours(0, 13, 37, 0), r = { data: { id: "ers", name: "Everyday Ruck Snack", color: "black", size: "l", price: 420 } }, o = { data: { id: "cc", name: "Cool Cap", size: "one size", price: 42 } };
|
|
99
|
+
return W({ ...{ "cart view": { data: { currency: "EUR", value: 2 * r.data.price }, context: { shopping: ["cart", 0] }, globals: { pagegroup: "shop" }, nested: [{ entity: "product", data: { ...r.data, quantity: 2 }, context: { shopping: ["cart", 0] }, nested: [] }], trigger: "load" }, "checkout view": { data: { step: "payment", currency: "EUR", value: r.data.price + o.data.price }, context: { shopping: ["checkout", 0] }, globals: { pagegroup: "shop" }, nested: [{ entity: "product", ...r, context: { shopping: ["checkout", 0] }, nested: [] }, { entity: "product", ...o, context: { shopping: ["checkout", 0] }, nested: [] }], trigger: "load" }, "order complete": { data: { id: "0rd3r1d", currency: "EUR", shipping: 5.22, taxes: 73.76, total: 555 }, context: { shopping: ["complete", 0] }, globals: { pagegroup: "shop" }, nested: [{ entity: "product", ...r, context: { shopping: ["complete", 0] }, nested: [] }, { entity: "product", ...o, context: { shopping: ["complete", 0] }, nested: [] }, { entity: "gift", data: { name: "Surprise" }, context: { shopping: ["complete", 0] }, nested: [] }], trigger: "load" }, "page view": { data: { domain: "www.example.com", title: "walkerOS documentation", referrer: "https://www.walkeros.io/", search: "?foo=bar", hash: "#hash", id: "/docs/" }, globals: { pagegroup: "docs" }, trigger: "load" }, "product add": { ...r, context: { shopping: ["intent", 0] }, globals: { pagegroup: "shop" }, nested: [], trigger: "click" }, "product view": { ...r, context: { shopping: ["detail", 0] }, globals: { pagegroup: "shop" }, nested: [], trigger: "load" }, "product visible": { data: { ...r.data, position: 3, promo: true }, context: { shopping: ["discover", 0] }, globals: { pagegroup: "shop" }, nested: [], trigger: "load" }, "promotion visible": { data: { name: "Setting up tracking easily", position: "hero" }, context: { ab_test: ["engagement", 0] }, globals: { pagegroup: "homepage" }, trigger: "visible" }, "session start": { data: { id: "s3ss10n", start: n, isNew: true, count: 1, runs: 1, isStart: true, storage: true, referrer: "", device: "c00k13" }, user: { id: "us3r", device: "c00k13", session: "s3ss10n", hash: "h4sh", address: "street number", email: "user@example.com", phone: "+49 123 456 789", userAgent: "Mozilla...", browser: "Chrome", browserVersion: "90", deviceType: "desktop", language: "de-DE", country: "DE", region: "HH", city: "Hamburg", zip: "20354", timezone: "Berlin", os: "walkerOS", osVersion: "1.0", screenSize: "1337x420", ip: "127.0.0.0", internal: true, custom: "value" } } }[e2], ...t, name: e2 });
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// src/examples/events.ts
|
|
103
|
+
function ga4Purchase() {
|
|
104
|
+
const event = B("order complete");
|
|
105
|
+
return [
|
|
106
|
+
"event",
|
|
107
|
+
"purchase",
|
|
108
|
+
{
|
|
109
|
+
transaction_id: event.data.id,
|
|
110
|
+
value: event.data.total,
|
|
111
|
+
tax: event.data.taxes,
|
|
112
|
+
shipping: event.data.shipping,
|
|
113
|
+
currency: "EUR",
|
|
114
|
+
items: event.nested.filter((item) => item.entity === "product").map((item) => ({
|
|
115
|
+
item_id: item.data.id,
|
|
116
|
+
item_name: item.data.name,
|
|
117
|
+
quantity: 1
|
|
118
|
+
})),
|
|
119
|
+
send_to: "G-XXXXXX-1"
|
|
120
|
+
}
|
|
121
|
+
];
|
|
122
|
+
}
|
|
123
|
+
function ga4AddToCart() {
|
|
124
|
+
const event = B("product add");
|
|
125
|
+
return [
|
|
126
|
+
"event",
|
|
127
|
+
"add_to_cart",
|
|
128
|
+
{
|
|
129
|
+
currency: "EUR",
|
|
130
|
+
value: event.data.price,
|
|
131
|
+
items: [
|
|
132
|
+
{
|
|
133
|
+
item_id: event.data.id,
|
|
134
|
+
item_variant: event.data.color,
|
|
135
|
+
quantity: 1
|
|
136
|
+
}
|
|
137
|
+
],
|
|
138
|
+
send_to: "G-XXXXXX-1"
|
|
139
|
+
}
|
|
140
|
+
];
|
|
141
|
+
}
|
|
142
|
+
function adsConversion() {
|
|
143
|
+
const event = B("order complete");
|
|
144
|
+
return [
|
|
145
|
+
"event",
|
|
146
|
+
"conversion",
|
|
147
|
+
{
|
|
148
|
+
send_to: "AW-XXXXXXXXX/CONVERSION_LABEL",
|
|
149
|
+
currency: "EUR",
|
|
150
|
+
value: event.data.total,
|
|
151
|
+
transaction_id: event.data.id
|
|
152
|
+
}
|
|
153
|
+
];
|
|
154
|
+
}
|
|
155
|
+
function gtmEvent() {
|
|
156
|
+
const event = B("product view");
|
|
157
|
+
return {
|
|
158
|
+
event: "product_view",
|
|
159
|
+
product_id: event.data.id,
|
|
160
|
+
product_name: event.data.name,
|
|
161
|
+
product_category: event.data.category,
|
|
162
|
+
value: event.data.price,
|
|
163
|
+
currency: "EUR"
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// src/examples/mapping.ts
|
|
168
|
+
var mapping_exports = {};
|
|
169
|
+
__export(mapping_exports, {
|
|
170
|
+
adsConversion: () => adsConversion2,
|
|
171
|
+
combinedPurchase: () => combinedPurchase,
|
|
172
|
+
config: () => config,
|
|
173
|
+
ga4AddToCart: () => ga4AddToCart2,
|
|
174
|
+
ga4Purchase: () => ga4Purchase2,
|
|
175
|
+
gtmProductView: () => gtmProductView
|
|
176
|
+
});
|
|
177
|
+
var ga4Purchase2 = {
|
|
178
|
+
name: "purchase",
|
|
179
|
+
settings: {
|
|
180
|
+
ga4: {
|
|
181
|
+
include: ["data", "context"]
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
data: {
|
|
185
|
+
map: {
|
|
186
|
+
transaction_id: "data.id",
|
|
187
|
+
value: "data.total",
|
|
188
|
+
tax: "data.taxes",
|
|
189
|
+
shipping: "data.shipping",
|
|
190
|
+
currency: { key: "data.currency", value: "EUR" },
|
|
191
|
+
items: {
|
|
192
|
+
loop: [
|
|
193
|
+
"nested",
|
|
194
|
+
{
|
|
195
|
+
condition: (entity) => _(entity) && entity.entity === "product",
|
|
196
|
+
map: {
|
|
197
|
+
item_id: "data.id",
|
|
198
|
+
item_name: "data.name",
|
|
199
|
+
quantity: { key: "data.quantity", value: 1 }
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
]
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
var ga4AddToCart2 = {
|
|
208
|
+
name: "add_to_cart",
|
|
209
|
+
settings: {
|
|
210
|
+
ga4: {
|
|
211
|
+
include: ["data"]
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
data: {
|
|
215
|
+
map: {
|
|
216
|
+
currency: { value: "EUR", key: "data.currency" },
|
|
217
|
+
value: "data.price",
|
|
218
|
+
items: {
|
|
219
|
+
loop: [
|
|
220
|
+
"this",
|
|
221
|
+
{
|
|
222
|
+
map: {
|
|
223
|
+
item_id: "data.id",
|
|
224
|
+
item_variant: "data.color",
|
|
225
|
+
quantity: { value: 1, key: "data.quantity" }
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
]
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
var adsConversion2 = {
|
|
234
|
+
name: "CONVERSION_LABEL",
|
|
235
|
+
// This becomes the conversion label
|
|
236
|
+
settings: {
|
|
237
|
+
ads: {}
|
|
238
|
+
},
|
|
239
|
+
data: {
|
|
240
|
+
map: {
|
|
241
|
+
value: "data.total",
|
|
242
|
+
currency: { value: "EUR", key: "data.currency" },
|
|
243
|
+
transaction_id: "data.id"
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
var gtmProductView = {
|
|
248
|
+
name: "product_view",
|
|
249
|
+
settings: {
|
|
250
|
+
gtm: {}
|
|
251
|
+
},
|
|
252
|
+
data: {
|
|
253
|
+
map: {
|
|
254
|
+
product_id: "data.id",
|
|
255
|
+
product_name: "data.name",
|
|
256
|
+
product_category: "data.category",
|
|
257
|
+
value: "data.price",
|
|
258
|
+
currency: { value: "EUR", key: "data.currency" }
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
var combinedPurchase = {
|
|
263
|
+
name: "purchase",
|
|
264
|
+
// GA4 event name
|
|
265
|
+
settings: {
|
|
266
|
+
ga4: {
|
|
267
|
+
include: ["data"]
|
|
268
|
+
},
|
|
269
|
+
ads: {},
|
|
270
|
+
// Will use 'purchase' as conversion label for ads
|
|
271
|
+
gtm: {}
|
|
272
|
+
},
|
|
273
|
+
data: {
|
|
274
|
+
map: {
|
|
275
|
+
transaction_id: "data.id",
|
|
276
|
+
value: "data.total",
|
|
277
|
+
currency: { value: "EUR", key: "data.currency" },
|
|
278
|
+
items: {
|
|
279
|
+
loop: [
|
|
280
|
+
"nested",
|
|
281
|
+
{
|
|
282
|
+
condition: (entity) => _(entity) && entity.entity === "product",
|
|
283
|
+
map: {
|
|
284
|
+
item_id: "data.id",
|
|
285
|
+
item_name: "data.name",
|
|
286
|
+
quantity: { value: 1, key: "data.quantity" }
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
]
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
var config = {
|
|
295
|
+
order: { complete: combinedPurchase },
|
|
296
|
+
product: {
|
|
297
|
+
add: ga4AddToCart2,
|
|
298
|
+
view: gtmProductView
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
export {
|
|
302
|
+
env_exports as env,
|
|
303
|
+
events_exports as events,
|
|
304
|
+
mapping_exports as mapping
|
|
305
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var Destination=(()=>{var t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,e=Object.getOwnPropertyNames,o=Object.prototype.hasOwnProperty,r={};((n,e)=>{for(var o in e)t(n,o,{get:e[o],enumerable:!0})})(r,{DestinationGtag:()=>L,default:()=>S,destinationGtag:()=>N,resetConsentState:()=>k});var a=new Set;function i(t,n="https://www.googletagmanager.com/gtag/js?id=",e=globalThis.document){if(a.has(t))return;const o=e.createElement("script");o.src=n+t,e.head.appendChild(o),a.add(t)}function c(t){const n=t;return n.dataLayer=n.dataLayer||[],n.gtag||(n.gtag=function(){n.dataLayer.push(arguments)}),n.gtag}var s=Object.defineProperty;((t,n)=>{for(var e in n)s(t,e,{get:n[e],enumerable:!0})})({},{Level:()=>d});var u,d=((u=d||{})[u.ERROR=0]="ERROR",u[u.INFO=1]="INFO",u[u.DEBUG=2]="DEBUG",u),l={merge:!0,shallow:!0,extend:!0};function g(t,n={},e={}){e={...l,...e};const o=Object.entries(n).reduce((n,[o,r])=>{const a=t[o];return e.merge&&Array.isArray(a)&&Array.isArray(r)?n[o]=r.reduce((t,n)=>t.includes(n)?t:[...t,n],[...a]):(e.extend||o in t)&&(n[o]=r),n},{});return e.shallow?{...t,...o}:(Object.assign(t,o),t)}function f(t){return Array.isArray(t)}function m(t){return void 0!==t}function v(t){return"object"==typeof t&&null!==t&&!f(t)&&"[object Object]"===Object.prototype.toString.call(t)}function w(t){return"string"==typeof t}function y(t,n="",e){const o=n.split(".");let r=t;for(let t=0;t<o.length;t++){const n=o[t];if("*"===n&&f(r)){const n=o.slice(t+1).join("."),a=[];for(const t of r){const o=y(t,n,e);a.push(o)}return a}if(r=r instanceof Object?r[n]:void 0,!r)break}return m(r)?r:e}function p(t){return function(t){return"boolean"==typeof t}(t)||w(t)||function(t){return"number"==typeof t&&!Number.isNaN(t)}(t)||!m(t)||f(t)&&t.every(p)||v(t)&&Object.values(t).every(p)}function b(t){return p(t)?t:void 0}function h(t,n,e){return async function(...o){try{return await t(...o)}catch(t){if(!n)return;return await n(t)}finally{await(null==e?void 0:e())}}}async function j(t,n={},e={}){var o;if(!m(t))return;const r=v(t)&&t.consent||e.consent||(null==(o=e.collector)?void 0:o.consent),a=f(n)?n:[n];for(const n of a){const o=await h(O)(t,n,{...e,consent:r});if(m(o))return o}}async function O(t,n,e={}){const{collector:o,consent:r}=e;return(f(n)?n:[n]).reduce(async(n,a)=>{const i=await n;if(i)return i;const c=w(a)?{key:a}:a;if(!Object.keys(c).length)return;const{condition:s,consent:u,fn:d,key:l,loop:g,map:v,set:p,validate:I,value:_}=c;if(s&&!await h(s)(t,a,o))return;if(u&&!function(t,n={},e={}){const o={...n,...e},r={};let a=void 0===t;return Object.keys(o).forEach(n=>{o[n]&&(r[n]=!0,t&&t[n]&&(a=!0))}),!!a&&r}(u,r))return _;let E=m(_)?_:t;if(d&&(E=await h(d)(t,a,e)),l&&(E=y(t,l,_)),g){const[n,o]=g,r="this"===n?[t]:await j(t,n,e);f(r)&&(E=(await Promise.all(r.map(t=>j(t,o,e)))).filter(m))}else v?E=await Object.entries(v).reduce(async(n,[o,r])=>{const a=await n,i=await j(t,r,e);return m(i)&&(a[o]=i),a},Promise.resolve({})):p&&(E=await Promise.all(p.map(n=>O(t,n,e))));I&&!await h(I)(E)&&(E=void 0);const A=b(E);return m(A)?A:b(_)},Promise.resolve(void 0))}function I(t){return{window:"undefined"!=typeof window?window:globalThis.window,document:"undefined"!=typeof document?document:globalThis.document,...t}}async function _(t,n,e,o,r){const a=v(n)?n:{},i=e.data?await j(t,e.data,{collector:r}):{},c=(null==o?void 0:o.data)?await j(t,o.data,{collector:r}):{},s=v(i)?i:{},u=v(c)?c:{};return g(g(a,s),u)}function E(t,n,e={},o,r,a){const{window:i}=I(r);n.measurementId||a.throw("Config settings ga4.measurementId missing");const c=v(o)?o:{},s=function(t,n){const e={};return n.includes("all")&&(n=["context","data","event","globals","source","user","version"]),n.forEach(n=>{let o=t[n]||{};"event"==n&&(o={id:t.id,timing:t.timing,trigger:t.trigger,entity:t.entity,action:t.action,group:t.group,count:t.count}),Object.entries(o).forEach(([t,o])=>{"context"==n&&(o=o[0]),e[`${n}_${t}`]=o})}),e}(t,e.include||n.include||["data"]),u={...s,...c};let d=t.name;!1!==n.snakeCase&&(d=function(t,n=!0){return n?t.replace(/\s+/g,"_").toLowerCase():t}(d)),u.send_to=n.measurementId,n.debug&&(u.debug_mode=!0);(0,i.gtag)("event",d,u)}var A="dataLayer";function C(t,n,e,o){const{window:r,document:a}=I(e),{containerId:i,dataLayer:c,domain:s}=t,u=c||A;u===A?r.dataLayer=r.dataLayer||[]:r[u]=r[u]||[];r[u].push({"gtm.start":(new Date).getTime(),event:"gtm.js"}),n&&i&&function(t,n,e,o=globalThis.document){const r=e!=A?"&l="+e:"",a=o.createElement("script");a.src=n+t+r,o.head.appendChild(a)}(i,s||"https://www.googletagmanager.com/gtm.js?id=",u,a)}var L={},P=!1;function k(){P=!1}var D,R={marketing:["ad_storage","ad_user_data","ad_personalization"],functional:["analytics_storage"]},N={type:"google-gtag",config:{settings:{}},init({config:t,env:n,logger:e}){const{settings:o={},loadScript:r}=t,{ga4:a,ads:s,gtm:u}=o;return(null==a?void 0:a.measurementId)||(null==s?void 0:s.conversionId)||(null==u?void 0:u.containerId)||e.throw("Config settings missing. Set ga4.measurementId, ads.conversionId, or gtm.containerId"),(null==a?void 0:a.measurementId)&&function(t,n,e,o){const{window:r,document:a}=I(e),{measurementId:s,transport_url:u,server_container_url:d,pageview:l}=t;s||o.throw("Config settings ga4.measurementId missing"),n&&i(s,void 0,a),c(r);const g={};u&&(g.transport_url=u),d&&(g.server_container_url=d),!1===l&&(g.send_page_view=!1);const f=r.gtag;f("js",new Date),f("config",s,g)}(a,r,n,e),(null==s?void 0:s.conversionId)&&function(t,n,e,o){const{window:r,document:a}=I(e),{conversionId:s}=t;s||o.throw("Config settings ads.conversionId missing"),t.currency||(t.currency="EUR"),n&&i(s,void 0,a),c(r);const u=r.gtag;u("js",new Date),u("config",s)}(s,r,n,e),(null==u?void 0:u.containerId)&&C(u,r,n),t},async push(t,{config:n,mapping:e={},data:o,env:r,collector:a,logger:i}){const{settings:c={}}=n,{ga4:s,ads:u,gtm:d}=c,l=e.settings||{},g=await _(t,o,n,s,a),f=await _(t,o,n,u,a),m=await _(t,o,n,d,a);(null==s?void 0:s.measurementId)&&E(t,s,l.ga4,g,r,i),(null==u?void 0:u.conversionId)&&e.name&&function(t,n,e={},o,r,a,i){const{conversionId:c,currency:s}=n,u=v(o)?o:{},d=e.label||r;d||i.throw("Config mapping ads.label missing");const l={send_to:`${c}/${d}`,currency:s||"EUR",...u},{window:g}=I(a);(0,g.gtag)("event","conversion",l)}(0,u,l.ads,f,e.name,r,i),(null==d?void 0:d.containerId)&&function(t,n,e={},o,r){const{window:a}=I(r),i={event:t.name};a.dataLayer.push({...i,...v(o)?o:t})}(t,0,l.gtm,m,r)},on(t,n){var e;if("consent"!==t||!n.data)return;const o=n.data,r=(null==(e=n.config)?void 0:e.settings)||{},{como:a=!0}=r;if(!a)return;const{window:i}=I(n.env),s=c(i);if(!s)return;const u=!0===a?R:a;if(!P){const t=new Set;if(Object.values(u).forEach(n=>{(Array.isArray(n)?n:[n]).forEach(n=>t.add(n))}),t.size>0){const n={};t.forEach(t=>{n[t]="denied"}),s("consent","default",n)}P=!0}const d={};Object.entries(o).forEach(([t,n])=>{const e=u[t];if(!e)return;const o=Array.isArray(e)?e:[e],r=n?"granted":"denied";o.forEach(t=>{d[t]=r})}),0!==Object.keys(d).length&&s("consent","update",d)}},S=N;return D=r,((r,a,i,c)=>{if(a&&"object"==typeof a||"function"==typeof a)for(let s of e(a))o.call(r,s)||s===i||t(r,s,{get:()=>a[s],enumerable:!(c=n(a,s))||c.enumerable});return r})(t({},"__esModule",{value:!0}),D)})();
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { Destination as Destination$1, Mapping as Mapping$1 } from '@walkeros/core';
|
|
2
|
+
import { DestinationWeb } from '@walkeros/web-core';
|
|
3
|
+
|
|
4
|
+
declare global {
|
|
5
|
+
interface Window {
|
|
6
|
+
gtag?: Gtag.Gtag;
|
|
7
|
+
[key: string]: unknown;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
interface Env extends DestinationWeb.Env {
|
|
11
|
+
window: {
|
|
12
|
+
gtag: Gtag.Gtag;
|
|
13
|
+
dataLayer: unknown[];
|
|
14
|
+
};
|
|
15
|
+
document: {
|
|
16
|
+
createElement: (tagName: string) => {
|
|
17
|
+
src: string;
|
|
18
|
+
async?: boolean;
|
|
19
|
+
setAttribute: (name: string, value: string) => void;
|
|
20
|
+
removeAttribute: (name: string) => void;
|
|
21
|
+
};
|
|
22
|
+
head: {
|
|
23
|
+
appendChild: (node: unknown) => void;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
type ConsentMode = false | true | ConsentMapping;
|
|
28
|
+
interface ConsentMapping {
|
|
29
|
+
[walkerOSConsentGroup: string]: string | string[];
|
|
30
|
+
}
|
|
31
|
+
type Types = Destination$1.Types<Settings, Mapping, Env, InitSettings>;
|
|
32
|
+
type Destination = DestinationWeb.Destination<Types>;
|
|
33
|
+
type Config = DestinationWeb.Config<Types>;
|
|
34
|
+
interface BaseSettings {
|
|
35
|
+
data?: Mapping$1.Value | Mapping$1.Values;
|
|
36
|
+
}
|
|
37
|
+
interface Settings {
|
|
38
|
+
como?: ConsentMode;
|
|
39
|
+
ga4?: GA4Settings;
|
|
40
|
+
ads?: AdsSettings;
|
|
41
|
+
gtm?: GTMSettings;
|
|
42
|
+
}
|
|
43
|
+
type InitSettings = Partial<Settings>;
|
|
44
|
+
interface GA4Settings extends BaseSettings {
|
|
45
|
+
measurementId: string;
|
|
46
|
+
debug?: boolean;
|
|
47
|
+
include?: Include;
|
|
48
|
+
pageview?: boolean;
|
|
49
|
+
server_container_url?: string;
|
|
50
|
+
snakeCase?: boolean;
|
|
51
|
+
transport_url?: string;
|
|
52
|
+
}
|
|
53
|
+
interface AdsSettings extends BaseSettings {
|
|
54
|
+
conversionId: string;
|
|
55
|
+
currency?: string;
|
|
56
|
+
}
|
|
57
|
+
interface AdsMapping {
|
|
58
|
+
label?: string;
|
|
59
|
+
}
|
|
60
|
+
interface GTMSettings extends BaseSettings {
|
|
61
|
+
containerId: string;
|
|
62
|
+
dataLayer?: string;
|
|
63
|
+
domain?: string;
|
|
64
|
+
}
|
|
65
|
+
interface Mapping {
|
|
66
|
+
ga4?: GA4Mapping;
|
|
67
|
+
ads?: AdsMapping;
|
|
68
|
+
gtm?: GTMMapping;
|
|
69
|
+
}
|
|
70
|
+
interface GA4Mapping {
|
|
71
|
+
include?: Include;
|
|
72
|
+
}
|
|
73
|
+
interface GTMMapping {
|
|
74
|
+
}
|
|
75
|
+
type Rule = Mapping$1.Rule<Mapping>;
|
|
76
|
+
type Rules = Mapping$1.Rules<Rule>;
|
|
77
|
+
type Param = Mapping$1.Value;
|
|
78
|
+
type Include = Array<'all' | 'context' | 'data' | 'event' | 'globals' | 'source' | 'user' | 'version'>;
|
|
79
|
+
type Parameters = Gtag.ControlParams & Gtag.EventParams & Gtag.CustomParams;
|
|
80
|
+
|
|
81
|
+
type index_AdsMapping = AdsMapping;
|
|
82
|
+
type index_AdsSettings = AdsSettings;
|
|
83
|
+
type index_BaseSettings = BaseSettings;
|
|
84
|
+
type index_Config = Config;
|
|
85
|
+
type index_ConsentMapping = ConsentMapping;
|
|
86
|
+
type index_ConsentMode = ConsentMode;
|
|
87
|
+
type index_Destination = Destination;
|
|
88
|
+
type index_Env = Env;
|
|
89
|
+
type index_GA4Mapping = GA4Mapping;
|
|
90
|
+
type index_GA4Settings = GA4Settings;
|
|
91
|
+
type index_GTMMapping = GTMMapping;
|
|
92
|
+
type index_GTMSettings = GTMSettings;
|
|
93
|
+
type index_Include = Include;
|
|
94
|
+
type index_InitSettings = InitSettings;
|
|
95
|
+
type index_Mapping = Mapping;
|
|
96
|
+
type index_Param = Param;
|
|
97
|
+
type index_Parameters = Parameters;
|
|
98
|
+
type index_Rule = Rule;
|
|
99
|
+
type index_Rules = Rules;
|
|
100
|
+
type index_Settings = Settings;
|
|
101
|
+
type index_Types = Types;
|
|
102
|
+
declare namespace index {
|
|
103
|
+
export type { index_AdsMapping as AdsMapping, index_AdsSettings as AdsSettings, index_BaseSettings as BaseSettings, index_Config as Config, index_ConsentMapping as ConsentMapping, index_ConsentMode as ConsentMode, index_Destination as Destination, index_Env as Env, index_GA4Mapping as GA4Mapping, index_GA4Settings as GA4Settings, index_GTMMapping as GTMMapping, index_GTMSettings as GTMSettings, index_Include as Include, index_InitSettings as InitSettings, index_Mapping as Mapping, index_Param as Param, index_Parameters as Parameters, index_Rule as Rule, index_Rules as Rules, index_Settings as Settings, index_Types as Types };
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
declare function resetConsentState(): void;
|
|
107
|
+
declare const destinationGtag: Destination;
|
|
108
|
+
|
|
109
|
+
export { index as DestinationGtag, destinationGtag as default, destinationGtag, resetConsentState };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { Destination as Destination$1, Mapping as Mapping$1 } from '@walkeros/core';
|
|
2
|
+
import { DestinationWeb } from '@walkeros/web-core';
|
|
3
|
+
|
|
4
|
+
declare global {
|
|
5
|
+
interface Window {
|
|
6
|
+
gtag?: Gtag.Gtag;
|
|
7
|
+
[key: string]: unknown;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
interface Env extends DestinationWeb.Env {
|
|
11
|
+
window: {
|
|
12
|
+
gtag: Gtag.Gtag;
|
|
13
|
+
dataLayer: unknown[];
|
|
14
|
+
};
|
|
15
|
+
document: {
|
|
16
|
+
createElement: (tagName: string) => {
|
|
17
|
+
src: string;
|
|
18
|
+
async?: boolean;
|
|
19
|
+
setAttribute: (name: string, value: string) => void;
|
|
20
|
+
removeAttribute: (name: string) => void;
|
|
21
|
+
};
|
|
22
|
+
head: {
|
|
23
|
+
appendChild: (node: unknown) => void;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
type ConsentMode = false | true | ConsentMapping;
|
|
28
|
+
interface ConsentMapping {
|
|
29
|
+
[walkerOSConsentGroup: string]: string | string[];
|
|
30
|
+
}
|
|
31
|
+
type Types = Destination$1.Types<Settings, Mapping, Env, InitSettings>;
|
|
32
|
+
type Destination = DestinationWeb.Destination<Types>;
|
|
33
|
+
type Config = DestinationWeb.Config<Types>;
|
|
34
|
+
interface BaseSettings {
|
|
35
|
+
data?: Mapping$1.Value | Mapping$1.Values;
|
|
36
|
+
}
|
|
37
|
+
interface Settings {
|
|
38
|
+
como?: ConsentMode;
|
|
39
|
+
ga4?: GA4Settings;
|
|
40
|
+
ads?: AdsSettings;
|
|
41
|
+
gtm?: GTMSettings;
|
|
42
|
+
}
|
|
43
|
+
type InitSettings = Partial<Settings>;
|
|
44
|
+
interface GA4Settings extends BaseSettings {
|
|
45
|
+
measurementId: string;
|
|
46
|
+
debug?: boolean;
|
|
47
|
+
include?: Include;
|
|
48
|
+
pageview?: boolean;
|
|
49
|
+
server_container_url?: string;
|
|
50
|
+
snakeCase?: boolean;
|
|
51
|
+
transport_url?: string;
|
|
52
|
+
}
|
|
53
|
+
interface AdsSettings extends BaseSettings {
|
|
54
|
+
conversionId: string;
|
|
55
|
+
currency?: string;
|
|
56
|
+
}
|
|
57
|
+
interface AdsMapping {
|
|
58
|
+
label?: string;
|
|
59
|
+
}
|
|
60
|
+
interface GTMSettings extends BaseSettings {
|
|
61
|
+
containerId: string;
|
|
62
|
+
dataLayer?: string;
|
|
63
|
+
domain?: string;
|
|
64
|
+
}
|
|
65
|
+
interface Mapping {
|
|
66
|
+
ga4?: GA4Mapping;
|
|
67
|
+
ads?: AdsMapping;
|
|
68
|
+
gtm?: GTMMapping;
|
|
69
|
+
}
|
|
70
|
+
interface GA4Mapping {
|
|
71
|
+
include?: Include;
|
|
72
|
+
}
|
|
73
|
+
interface GTMMapping {
|
|
74
|
+
}
|
|
75
|
+
type Rule = Mapping$1.Rule<Mapping>;
|
|
76
|
+
type Rules = Mapping$1.Rules<Rule>;
|
|
77
|
+
type Param = Mapping$1.Value;
|
|
78
|
+
type Include = Array<'all' | 'context' | 'data' | 'event' | 'globals' | 'source' | 'user' | 'version'>;
|
|
79
|
+
type Parameters = Gtag.ControlParams & Gtag.EventParams & Gtag.CustomParams;
|
|
80
|
+
|
|
81
|
+
type index_AdsMapping = AdsMapping;
|
|
82
|
+
type index_AdsSettings = AdsSettings;
|
|
83
|
+
type index_BaseSettings = BaseSettings;
|
|
84
|
+
type index_Config = Config;
|
|
85
|
+
type index_ConsentMapping = ConsentMapping;
|
|
86
|
+
type index_ConsentMode = ConsentMode;
|
|
87
|
+
type index_Destination = Destination;
|
|
88
|
+
type index_Env = Env;
|
|
89
|
+
type index_GA4Mapping = GA4Mapping;
|
|
90
|
+
type index_GA4Settings = GA4Settings;
|
|
91
|
+
type index_GTMMapping = GTMMapping;
|
|
92
|
+
type index_GTMSettings = GTMSettings;
|
|
93
|
+
type index_Include = Include;
|
|
94
|
+
type index_InitSettings = InitSettings;
|
|
95
|
+
type index_Mapping = Mapping;
|
|
96
|
+
type index_Param = Param;
|
|
97
|
+
type index_Parameters = Parameters;
|
|
98
|
+
type index_Rule = Rule;
|
|
99
|
+
type index_Rules = Rules;
|
|
100
|
+
type index_Settings = Settings;
|
|
101
|
+
type index_Types = Types;
|
|
102
|
+
declare namespace index {
|
|
103
|
+
export type { index_AdsMapping as AdsMapping, index_AdsSettings as AdsSettings, index_BaseSettings as BaseSettings, index_Config as Config, index_ConsentMapping as ConsentMapping, index_ConsentMode as ConsentMode, index_Destination as Destination, index_Env as Env, index_GA4Mapping as GA4Mapping, index_GA4Settings as GA4Settings, index_GTMMapping as GTMMapping, index_GTMSettings as GTMSettings, index_Include as Include, index_InitSettings as InitSettings, index_Mapping as Mapping, index_Param as Param, index_Parameters as Parameters, index_Rule as Rule, index_Rules as Rules, index_Settings as Settings, index_Types as Types };
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
declare function resetConsentState(): void;
|
|
107
|
+
declare const destinationGtag: Destination;
|
|
108
|
+
|
|
109
|
+
export { index as DestinationGtag, destinationGtag as default, destinationGtag, resetConsentState };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";function _array_like_to_array(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function _array_with_holes(e){if(Array.isArray(e))return e}function _array_without_holes(e){if(Array.isArray(e))return _array_like_to_array(e)}function asyncGeneratorStep(e,t,n,r,o,a,i){try{var c=e[a](i),u=c.value}catch(e){return void n(e)}c.done?t(u):Promise.resolve(u).then(r,o)}function _async_to_generator(e){return function(){var t=this,n=arguments;return new Promise(function(r,o){var a=e.apply(t,n);function i(e){asyncGeneratorStep(a,r,o,i,c,"next",e)}function c(e){asyncGeneratorStep(a,r,o,i,c,"throw",e)}i(void 0)})}}function _define_property(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function _instanceof(e,t){return null!=t&&"undefined"!=typeof Symbol&&t[Symbol.hasInstance]?!!t[Symbol.hasInstance](e):e instanceof t}function _iterable_to_array(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function _iterable_to_array_limit(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,o,a=[],i=!0,c=!1;try{for(n=n.call(e);!(i=(r=n.next()).done)&&(a.push(r.value),!t||a.length!==t);i=!0);}catch(e){c=!0,o=e}finally{try{i||null==n.return||n.return()}finally{if(c)throw o}}return a}}function _non_iterable_rest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _non_iterable_spread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _object_spread(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){_define_property(e,t,n[t])})}return e}function ownKeys(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function _object_spread_props(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):ownKeys(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}),e}function _sliced_to_array(e,t){return _array_with_holes(e)||_iterable_to_array_limit(e,t)||_unsupported_iterable_to_array(e,t)||_non_iterable_rest()}function _to_consumable_array(e){return _array_without_holes(e)||_iterable_to_array(e)||_unsupported_iterable_to_array(e)||_non_iterable_spread()}function _type_of(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}function _unsupported_iterable_to_array(e,t){if(e){if("string"==typeof e)return _array_like_to_array(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(n):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_array_like_to_array(e,t):void 0}}function _ts_generator(e,t){var n,r,o,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),c=Object.defineProperty;return c(i,"next",{value:u(0)}),c(i,"throw",{value:u(1)}),c(i,"return",{value:u(2)}),"function"==typeof Symbol&&c(i,Symbol.iterator,{value:function(){return this}}),i;function u(c){return function(u){return function(c){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,r=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){a=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){a.label=c[1];break}if(6===c[0]&&a.label<o[1]){a.label=o[1],o=c;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(c);break}o[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,u])}}}var Destination=function(){var e=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"https://www.googletagmanager.com/gtag/js?id=",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:globalThis.document;if(!m.has(e)){var r=n.createElement("script");r.src=t+e,n.head.appendChild(r),m.add(e)}},t=function(e){var t=e;return t.dataLayer=t.dataLayer||[],t.gtag||(t.gtag=function(){t.dataLayer.push(arguments)}),t.gtag},n=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};n=_object_spread({},I,n);var r=Object.entries(t).reduce(function(t,r){var o=_sliced_to_array(r,2),a=o[0],i=o[1],c=e[a];return n.merge&&Array.isArray(c)&&Array.isArray(i)?t[a]=i.reduce(function(e,t){return e.includes(t)?e:_to_consumable_array(e).concat([t])},_to_consumable_array(c)):(n.extend||a in e)&&(t[a]=i),t},{});return n.shallow?_object_spread({},e,r):(Object.assign(e,r),e)},r=function(e){return Array.isArray(e)},o=function(e){return void 0!==e},a=function(e){return"object"==(void 0===e?"undefined":_type_of(e))&&null!==e&&!r(e)&&"[object Object]"===Object.prototype.toString.call(e)},i=function(e){return"string"==typeof e},c=function(e){return P(e)?e:void 0},u=function(e,t,n){return function(){for(var r=arguments.length,o=new Array(r),a=0;a<r;a++)o[a]=arguments[a];return _async_to_generator(function(){var r;return _ts_generator(this,function(a){switch(a.label){case 0:return a.trys.push([0,2,4,6]),[4,e.apply(void 0,_to_consumable_array(o))];case 1:case 3:return[2,a.sent()];case 2:return r=a.sent(),t?[4,t(r)]:[2];case 4:return[4,null==n?void 0:n()];case 5:return a.sent(),[7];case 6:return[2]}})})()}},s=function(e){return _async_to_generator(function(e){var t,n,i,c,s,l,d,f,_,y,v,g,p,b=arguments;return _ts_generator(this,function(h){switch(h.label){case 0:if(t=b.length>1&&void 0!==b[1]?b[1]:{},n=b.length>2&&void 0!==b[2]?b[2]:{},!o(e))return[2];c=a(e)&&e.consent||n.consent||(null===(i=n.collector)||void 0===i?void 0:i.consent),s=r(t)?t:[t],l=!0,d=!1,f=void 0,h.label=1;case 1:h.trys.push([1,6,7,8]),_=s[Symbol.iterator](),h.label=2;case 2:return(l=(y=_.next()).done)?[3,5]:(v=y.value,[4,u(E)(e,v,_object_spread_props(_object_spread({},n),{consent:c}))]);case 3:if(g=h.sent(),o(g))return[2,g];h.label=4;case 4:return l=!0,[3,2];case 5:return[3,8];case 6:return p=h.sent(),d=!0,f=p,[3,8];case 7:try{l||null==_.return||_.return()}finally{if(d)throw f}return[7];case 8:return[2]}})}).apply(this,arguments)},l=function(e){return _object_spread({window:"undefined"!=typeof window?window:globalThis.window,document:"undefined"!=typeof document?document:globalThis.document},e)},d=function(e,t,r,o,i){return _async_to_generator(function(){var c,u,l,d,f,_,y;return _ts_generator(this,function(v){switch(v.label){case 0:return c=a(t)?t:{},r.data?[4,s(e,r.data,{collector:i})]:[3,2];case 1:return l=v.sent(),[3,3];case 2:l={},v.label=3;case 3:return u=l,(null==o?void 0:o.data)?[4,s(e,o.data,{collector:i})]:[3,5];case 4:return f=v.sent(),[3,6];case 5:f={},v.label=6;case 6:return d=f,_=a(u)?u:{},y=a(d)?d:{},[2,n(n(c,_),y)]}})})()},f=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=arguments.length>3?arguments[3]:void 0,o=arguments.length>5?arguments[5]:void 0,i=l(arguments.length>4?arguments[4]:void 0).window;t.measurementId||o.throw("Config settings ga4.measurementId missing");var c=a(r)?r:{},u=function(e,t){var n={};return t.includes("all")&&(t=["context","data","event","globals","source","user","version"]),t.forEach(function(t){var r=e[t]||{};"event"==t&&(r={id:e.id,timing:e.timing,trigger:e.trigger,entity:e.entity,action:e.action,group:e.group,count:e.count}),Object.entries(r).forEach(function(e){var r=_sliced_to_array(e,2),o=r[0],a=r[1];"context"==t&&(a=a[0]),n["".concat(t,"_").concat(o)]=a})}),n}(e,n.include||t.include||["data"]),s=_object_spread({},u,c),d=e.name;!1!==t.snakeCase&&(d=function(e){return arguments.length>1&&void 0!==arguments[1]&&!arguments[1]?e:e.replace(/\s+/g,"_").toLowerCase()}(d)),s.send_to=t.measurementId,t.debug&&(s.debug_mode=!0),(0,i.gtag)("event",d,s)},_=function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:globalThis.document,o=n!=k?"&l="+n:"",a=r.createElement("script");a.src=t+e+o,r.head.appendChild(a)},y=function(){C=!1},v=Object.defineProperty,g=Object.getOwnPropertyDescriptor,p=Object.getOwnPropertyNames,b=Object.prototype.hasOwnProperty,h={};!function(e,t){for(var n in t)v(e,n,{get:t[n],enumerable:!0})}(h,{DestinationGtag:function(){return x},default:function(){return R},destinationGtag:function(){return G},resetConsentState:function(){return y}});var m=new Set,w=Object.defineProperty;!function(e,t){for(var n in t)w(e,n,{get:t[n],enumerable:!0})}({},{Level:function(){return O}});var j,O=((j=O||{})[j.ERROR=0]="ERROR",j[j.INFO=1]="INFO",j[j.DEBUG=2]="DEBUG",j),I={merge:!0,shallow:!0,extend:!0};function S(e){for(var t=arguments.length>2?arguments[2]:void 0,n=(arguments.length>1&&void 0!==arguments[1]?arguments[1]:"").split("."),a=e,i=0;i<n.length;i++){var c=n[i];if("*"===c&&r(a)){var u=n.slice(i+1).join("."),s=[],l=!0,d=!1,f=void 0;try{for(var _,y=a[Symbol.iterator]();!(l=(_=y.next()).done);l=!0){var v=S(_.value,u,t);s.push(v)}}catch(e){d=!0,f=e}finally{try{l||null==y.return||y.return()}finally{if(d)throw f}}return s}if(!(a=_instanceof(a,Object)?a[c]:void 0))break}return o(a)?a:t}function P(e){return function(e){return"boolean"==typeof e}(e)||i(e)||function(e){return"number"==typeof e&&!Number.isNaN(e)}(e)||!o(e)||r(e)&&e.every(P)||a(e)&&Object.values(e).every(P)}function E(e,t){return _async_to_generator(function(e,t){var n,a,l,d=arguments;return _ts_generator(this,function(f){return a=(n=d.length>2&&void 0!==d[2]?d[2]:{}).collector,l=n.consent,[2,(r(t)?t:[t]).reduce(function(t,d){return _async_to_generator(function(){var f,_,y,v,g,p,b,h,m,w,j,O,I,P,A,k,D,x,C,L,G;return _ts_generator(this,function(R){switch(R.label){case 0:return[4,t];case 1:return(f=R.sent())?[2,f]:(_=i(d)?{key:d}:d,Object.keys(_).length?(y=_.condition,v=_.consent,g=_.fn,p=_.key,b=_.loop,h=_.map,m=_.set,w=_.validate,j=_.value,(O=y)?[4,u(y)(e,d,a)]:[3,3]):[2]);case 2:O=!R.sent(),R.label=3;case 3:return O?[2]:v&&!function(e){var t=_object_spread({},arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},arguments.length>2&&void 0!==arguments[2]?arguments[2]:{}),n={},r=void 0===e;return Object.keys(t).forEach(function(o){t[o]&&(n[o]=!0,e&&e[o]&&(r=!0))}),!!r&&n}(v,l)?[2,j]:(I=o(j)?j:e,g?[4,u(g)(e,d,n)]:[3,5]);case 4:I=R.sent(),R.label=5;case 5:return p&&(I=S(e,p,j)),b?(P=_sliced_to_array(b,2),A=P[0],k=P[1],"this"!==A?[3,6]:(x=[e],[3,8])):[3,11];case 6:return[4,s(e,A,n)];case 7:x=R.sent(),R.label=8;case 8:return r(D=x)?[4,Promise.all(D.map(function(e){return s(e,k,n)}))]:[3,10];case 9:I=R.sent().filter(o),R.label=10;case 10:return[3,17];case 11:return h?[4,Object.entries(h).reduce(function(t,r){var a=_sliced_to_array(r,2),i=a[0],c=a[1];return _async_to_generator(function(){var r,a;return _ts_generator(this,function(u){switch(u.label){case 0:return[4,t];case 1:return r=u.sent(),[4,s(e,c,n)];case 2:return a=u.sent(),[2,(o(a)&&(r[i]=a),r)]}})})()},Promise.resolve({}))]:[3,13];case 12:return I=R.sent(),[3,16];case 13:return(C=m)?[4,Promise.all(m.map(function(t){return E(e,t,n)}))]:[3,15];case 14:C=I=R.sent(),R.label=15;case 15:R.label=16;case 16:R.label=17;case 17:return(L=w)?[4,u(w)(I)]:[3,19];case 18:L=!R.sent(),R.label=19;case 19:return L&&(I=void 0),G=c(I),[2,o(G)?G:c(j)]}})})()},Promise.resolve(void 0))]})}).apply(this,arguments)}var A,k="dataLayer",D="https://www.googletagmanager.com/gtm.js?id=",x={},C=!1,L={marketing:["ad_storage","ad_user_data","ad_personalization"],functional:["analytics_storage"]},G={type:"google-gtag",config:{settings:{}},init:function(n){var r=n.config,o=n.env,a=n.logger,i=r.settings,c=void 0===i?{}:i,u=r.loadScript,s=c.ga4,d=c.ads,f=c.gtm;return(null==s?void 0:s.measurementId)||(null==d?void 0:d.conversionId)||(null==f?void 0:f.containerId)||a.throw("Config settings missing. Set ga4.measurementId, ads.conversionId, or gtm.containerId"),(null==s?void 0:s.measurementId)&&function(n,r,o,a){var i=l(o),c=i.window,u=i.document,s=n.measurementId,d=n.transport_url,f=n.server_container_url,_=n.pageview;s||a.throw("Config settings ga4.measurementId missing"),r&&e(s,void 0,u),t(c);var y={};d&&(y.transport_url=d),f&&(y.server_container_url=f),!1===_&&(y.send_page_view=!1);var v=c.gtag;v("js",new Date),v("config",s,y)}(s,u,o,a),(null==d?void 0:d.conversionId)&&function(n,r,o,a){var i=l(o),c=i.window,u=i.document,s=n.conversionId;s||a.throw("Config settings ads.conversionId missing"),n.currency||(n.currency="EUR"),r&&e(s,void 0,u),t(c);var d=c.gtag;d("js",new Date),d("config",s)}(d,u,o,a),(null==f?void 0:f.containerId)&&function(e,t,n){var r=l(n),o=r.window,a=r.document,i=e.containerId,c=e.dataLayer,u=e.domain,s=c||k;s===k?o.dataLayer=o.dataLayer||[]:o[s]=o[s]||[],o[s].push({"gtm.start":(new Date).getTime(),event:"gtm.js"}),t&&i&&_(i,u||D,s,a)}(f,u,o),r},push:function(e,t){return _async_to_generator(function(e,t){var n,r,o,i,c,u,s,_,y,v,g,p,b,h,m,w;return _ts_generator(this,function(j){switch(j.label){case 0:return n=t.config,r=t.mapping,o=void 0===r?{}:r,i=t.data,c=t.env,u=t.collector,s=t.logger,_=n.settings,v=(y=void 0===_?{}:_).ga4,g=y.ads,p=y.gtm,b=o.settings||{},[4,d(e,i,n,v,u)];case 1:return h=j.sent(),[4,d(e,i,n,g,u)];case 2:return m=j.sent(),[4,d(e,i,n,p,u)];case 3:return w=j.sent(),(null==v?void 0:v.measurementId)&&f(e,v,b.ga4,h,c,s),(null==g?void 0:g.conversionId)&&o.name&&function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=arguments.length>3?arguments[3]:void 0,o=arguments.length>4?arguments[4]:void 0,i=arguments.length>5?arguments[5]:void 0,c=arguments.length>6?arguments[6]:void 0,u=t.conversionId,s=t.currency,d=a(r)?r:{},f=n.label||o;f||c.throw("Config mapping ads.label missing");var _=_object_spread({send_to:"".concat(u,"/").concat(f),currency:s||"EUR"},d);(0,l(i).window.gtag)("event","conversion",_)}(e,g,b.ads,m,o.name,c,s),(null==p?void 0:p.containerId)&&function(e,t){var n=arguments.length>3?arguments[3]:void 0,r=l(arguments.length>4?arguments[4]:void 0).window,o={event:e.name};r.dataLayer.push(_object_spread({},o,a(n)?n:e))}(e,p,b.gtm,w,c,s),[2]}})}).apply(this,arguments)},on:function(e,n){var r;if("consent"===e&&n.data){var o=n.data,a=((null===(r=n.config)||void 0===r?void 0:r.settings)||{}).como,i=void 0===a||a;if(i){var c=l(n.env).window,u=t(c);if(u){var s=!0===i?L:i;if(!C){var d=new Set;if(Object.values(s).forEach(function(e){(Array.isArray(e)?e:[e]).forEach(function(e){return d.add(e)})}),d.size>0){var f={};d.forEach(function(e){f[e]="denied"}),u("consent","default",f)}C=!0}var _={};Object.entries(o).forEach(function(e){var t=_sliced_to_array(e,2),n=t[0],r=t[1],o=s[n];if(o){var a=Array.isArray(o)?o:[o],i=r?"granted":"denied";a.forEach(function(e){_[e]=i})}}),0!==Object.keys(_).length&&u("consent","update",_)}}}}},R=G;return A=h,function(e,t,n,r){if(t&&"object"===(void 0===t?"undefined":_type_of(t))||"function"==typeof t){var o=!0,a=!1,i=void 0;try{for(var c,u=function(){var o=c.value;b.call(e,o)||o===n||v(e,o,{get:function(){return t[o]},enumerable:!(r=g(t,o))||r.enumerable})},s=p(t)[Symbol.iterator]();!(o=(c=s.next()).done);o=!0)u()}catch(e){a=!0,i=e}finally{try{o||null==s.return||s.return()}finally{if(a)throw i}}}return e}(v({},"__esModule",{value:!0}),A)}();
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,o=Object.prototype.hasOwnProperty,a={};((e,n)=>{for(var r in n)t(e,r,{get:n[r],enumerable:!0})})(a,{DestinationGtag:()=>S,default:()=>T,destinationGtag:()=>$,resetConsentState:()=>G}),module.exports=(e=a,((e,a,i,c)=>{if(a&&"object"==typeof a||"function"==typeof a)for(let s of r(a))o.call(e,s)||s===i||t(e,s,{get:()=>a[s],enumerable:!(c=n(a,s))||c.enumerable});return e})(t({},"__esModule",{value:!0}),e));var i=new Set;function c(e,t="https://www.googletagmanager.com/gtag/js?id=",n=globalThis.document){if(i.has(e))return;const r=n.createElement("script");r.src=t+e,n.head.appendChild(r),i.add(e)}function s(e){const t=e;return t.dataLayer=t.dataLayer||[],t.gtag||(t.gtag=function(){t.dataLayer.push(arguments)}),t.gtag}var u=require("@walkeros/web-core");var d=Object.defineProperty;((e,t)=>{for(var n in t)d(e,n,{get:t[n],enumerable:!0})})({},{Level:()=>g});var l,g=((l=g||{})[l.ERROR=0]="ERROR",l[l.INFO=1]="INFO",l[l.DEBUG=2]="DEBUG",l),f={merge:!0,shallow:!0,extend:!0};function v(e,t={},n={}){n={...f,...n};const r=Object.entries(t).reduce((t,[r,o])=>{const a=e[r];return n.merge&&Array.isArray(a)&&Array.isArray(o)?t[r]=o.reduce((e,t)=>e.includes(t)?e:[...e,t],[...a]):(n.extend||r in e)&&(t[r]=o),t},{});return n.shallow?{...e,...r}:(Object.assign(e,r),e)}function m(e){return Array.isArray(e)}function w(e){return void 0!==e}function y(e){return"object"==typeof e&&null!==e&&!m(e)&&"[object Object]"===Object.prototype.toString.call(e)}function p(e){return"string"==typeof e}function b(e,t="",n){const r=t.split(".");let o=e;for(let e=0;e<r.length;e++){const t=r[e];if("*"===t&&m(o)){const t=r.slice(e+1).join("."),a=[];for(const e of o){const r=b(e,t,n);a.push(r)}return a}if(o=o instanceof Object?o[t]:void 0,!o)break}return w(o)?o:n}function h(e){return function(e){return"boolean"==typeof e}(e)||p(e)||function(e){return"number"==typeof e&&!Number.isNaN(e)}(e)||!w(e)||m(e)&&e.every(h)||y(e)&&Object.values(e).every(h)}function j(e){return h(e)?e:void 0}function O(e,t,n){return async function(...r){try{return await e(...r)}catch(e){if(!t)return;return await t(e)}finally{await(null==n?void 0:n())}}}async function E(e,t={},n={}){var r;if(!w(e))return;const o=y(e)&&e.consent||n.consent||(null==(r=n.collector)?void 0:r.consent),a=m(t)?t:[t];for(const t of a){const r=await O(I)(e,t,{...n,consent:o});if(w(r))return r}}async function I(e,t,n={}){const{collector:r,consent:o}=n;return(m(t)?t:[t]).reduce(async(t,a)=>{const i=await t;if(i)return i;const c=p(a)?{key:a}:a;if(!Object.keys(c).length)return;const{condition:s,consent:u,fn:d,key:l,loop:g,map:f,set:v,validate:y,value:h}=c;if(s&&!await O(s)(e,a,r))return;if(u&&!function(e,t={},n={}){const r={...t,...n},o={};let a=void 0===e;return Object.keys(r).forEach(t=>{r[t]&&(o[t]=!0,e&&e[t]&&(a=!0))}),!!a&&o}(u,o))return h;let _=w(h)?h:e;if(d&&(_=await O(d)(e,a,n)),l&&(_=b(e,l,h)),g){const[t,r]=g,o="this"===t?[e]:await E(e,t,n);m(o)&&(_=(await Promise.all(o.map(e=>E(e,r,n)))).filter(w))}else f?_=await Object.entries(f).reduce(async(t,[r,o])=>{const a=await t,i=await E(e,o,n);return w(i)&&(a[r]=i),a},Promise.resolve({})):v&&(_=await Promise.all(v.map(t=>I(e,t,n))));y&&!await O(y)(_)&&(_=void 0);const k=j(_);return w(k)?k:j(h)},Promise.resolve(void 0))}async function _(e,t,n,r,o){const a=y(t)?t:{},i=n.data?await E(e,n.data,{collector:o}):{},c=(null==r?void 0:r.data)?await E(e,r.data,{collector:o}):{},s=y(i)?i:{},u=y(c)?c:{};return v(v(a,s),u)}var k=require("@walkeros/web-core");function A(e,t,n={},r,o,a){const{window:i}=(0,k.getEnv)(o);t.measurementId||a.throw("Config settings ga4.measurementId missing");const c=y(r)?r:{},s=function(e,t){const n={};return t.includes("all")&&(t=["context","data","event","globals","source","user","version"]),t.forEach(t=>{let r=e[t]||{};"event"==t&&(r={id:e.id,timing:e.timing,trigger:e.trigger,entity:e.entity,action:e.action,group:e.group,count:e.count}),Object.entries(r).forEach(([e,r])=>{"context"==t&&(r=r[0]),n[`${t}_${e}`]=r})}),n}(e,n.include||t.include||["data"]),u={...s,...c};let d=e.name;!1!==t.snakeCase&&(d=function(e,t=!0){return t?e.replace(/\s+/g,"_").toLowerCase():e}(d)),u.send_to=t.measurementId,t.debug&&(u.debug_mode=!0);(0,i.gtag)("event",d,u)}var C=require("@walkeros/web-core");var L=require("@walkeros/web-core");var P=require("@walkeros/web-core"),R="dataLayer";function q(e,t,n,r){const{window:o,document:a}=(0,P.getEnv)(n),{containerId:i,dataLayer:c,domain:s}=e,u=c||R;u===R?o.dataLayer=o.dataLayer||[]:o[u]=o[u]||[];o[u].push({"gtm.start":(new Date).getTime(),event:"gtm.js"}),t&&i&&function(e,t,n,r=globalThis.document){const o=n!=R?"&l="+n:"",a=r.createElement("script");a.src=t+e+o,r.head.appendChild(a)}(i,s||"https://www.googletagmanager.com/gtm.js?id=",u,a)}var D=require("@walkeros/web-core");var N=require("@walkeros/web-core"),S={},x=!1;function G(){x=!1}var U={marketing:["ad_storage","ad_user_data","ad_personalization"],functional:["analytics_storage"]},$={type:"google-gtag",config:{settings:{}},init({config:e,env:t,logger:n}){const{settings:r={},loadScript:o}=e,{ga4:a,ads:i,gtm:d}=r;return(null==a?void 0:a.measurementId)||(null==i?void 0:i.conversionId)||(null==d?void 0:d.containerId)||n.throw("Config settings missing. Set ga4.measurementId, ads.conversionId, or gtm.containerId"),(null==a?void 0:a.measurementId)&&function(e,t,n,r){const{window:o,document:a}=(0,u.getEnv)(n),{measurementId:i,transport_url:d,server_container_url:l,pageview:g}=e;i||r.throw("Config settings ga4.measurementId missing"),t&&c(i,void 0,a),s(o);const f={};d&&(f.transport_url=d),l&&(f.server_container_url=l),!1===g&&(f.send_page_view=!1);const v=o.gtag;v("js",new Date),v("config",i,f)}(a,o,t,n),(null==i?void 0:i.conversionId)&&function(e,t,n,r){const{window:o,document:a}=(0,C.getEnv)(n),{conversionId:i}=e;i||r.throw("Config settings ads.conversionId missing"),e.currency||(e.currency="EUR"),t&&c(i,void 0,a),s(o);const u=o.gtag;u("js",new Date),u("config",i)}(i,o,t,n),(null==d?void 0:d.containerId)&&q(d,o,t),e},async push(e,{config:t,mapping:n={},data:r,env:o,collector:a,logger:i}){const{settings:c={}}=t,{ga4:s,ads:u,gtm:d}=c,l=n.settings||{},g=await _(e,r,t,s,a),f=await _(e,r,t,u,a),v=await _(e,r,t,d,a);(null==s?void 0:s.measurementId)&&A(e,s,l.ga4,g,o,i),(null==u?void 0:u.conversionId)&&n.name&&function(e,t,n={},r,o,a,i){const{conversionId:c,currency:s}=t,u=y(r)?r:{},d=n.label||o;d||i.throw("Config mapping ads.label missing");const l={send_to:`${c}/${d}`,currency:s||"EUR",...u},{window:g}=(0,L.getEnv)(a);(0,g.gtag)("event","conversion",l)}(0,u,l.ads,f,n.name,o,i),(null==d?void 0:d.containerId)&&function(e,t,n={},r,o){const{window:a}=(0,D.getEnv)(o),i={event:e.name};a.dataLayer.push({...i,...y(r)?r:e})}(e,0,l.gtm,v,o)},on(e,t){var n;if("consent"!==e||!t.data)return;const r=t.data,o=(null==(n=t.config)?void 0:n.settings)||{},{como:a=!0}=o;if(!a)return;const{window:i}=(0,N.getEnv)(t.env),c=s(i);if(!c)return;const u=!0===a?U:a;if(!x){const e=new Set;if(Object.values(u).forEach(t=>{(Array.isArray(t)?t:[t]).forEach(t=>e.add(t))}),e.size>0){const t={};e.forEach(e=>{t[e]="denied"}),c("consent","default",t)}x=!0}const d={};Object.entries(r).forEach(([e,t])=>{const n=u[e];if(!n)return;const r=Array.isArray(n)?n:[n],o=t?"granted":"denied";r.forEach(e=>{d[e]=o})}),0!==Object.keys(d).length&&c("consent","update",d)}},T=$;//# sourceMappingURL=index.js.map
|