@walkeros/web-destination-gtag 0.0.7
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 +330 -0
- package/dist/examples/index.d.mts +60 -0
- package/dist/examples/index.d.ts +60 -0
- package/dist/examples/index.js +279 -0
- package/dist/examples/index.mjs +257 -0
- package/dist/index.browser.js +1 -0
- package/dist/index.d.mts +123 -0
- package/dist/index.d.ts +123 -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 +56 -0
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/examples/index.ts
|
|
21
|
+
var examples_exports = {};
|
|
22
|
+
__export(examples_exports, {
|
|
23
|
+
events: () => events_exports,
|
|
24
|
+
mapping: () => mapping_exports
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(examples_exports);
|
|
27
|
+
|
|
28
|
+
// src/examples/events.ts
|
|
29
|
+
var events_exports = {};
|
|
30
|
+
__export(events_exports, {
|
|
31
|
+
adsConversion: () => adsConversion,
|
|
32
|
+
ga4AddToCart: () => ga4AddToCart,
|
|
33
|
+
ga4Purchase: () => ga4Purchase,
|
|
34
|
+
gtmEvent: () => gtmEvent
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// ../../../core/dist/index.mjs
|
|
38
|
+
var e;
|
|
39
|
+
var t;
|
|
40
|
+
var n = Object.getOwnPropertyNames;
|
|
41
|
+
var r = (e = { "package.json"(e2, t2) {
|
|
42
|
+
t2.exports = { name: "@walkeros/core", description: "Core types and platform-agnostic utilities for walkerOS", version: "0.0.7", main: "./dist/index.js", module: "./dist/index.mjs", types: "./dist/index.d.ts", license: "MIT", files: ["dist/**"], scripts: { build: "tsup --silent", clean: "rm -rf .turbo && rm -rf node_modules && rm -rf dist", dev: "jest --watchAll --colors", lint: 'tsc && eslint "**/*.ts*"', test: "jest", update: "npx npm-check-updates -u && npm update" }, dependencies: {}, devDependencies: {}, repository: { url: "git+https://github.com/elbwalker/walkerOS.git", directory: "packages/core" }, author: "elbwalker <hello@elbwalker.com>", homepage: "https://github.com/elbwalker/walkerOS#readme", bugs: { url: "https://github.com/elbwalker/walkerOS/issues" }, keywords: ["walker", "walkerOS", "analytics", "tracking", "data collection", "measurement", "data privacy", "privacy friendly", "web analytics", "product analytics", "core", "types", "utils"], funding: [{ type: "GitHub Sponsors", url: "https://github.com/sponsors/elbwalker" }] };
|
|
43
|
+
} }, function() {
|
|
44
|
+
return t || (0, e[n(e)[0]])((t = { exports: {} }).exports, t), t.exports;
|
|
45
|
+
});
|
|
46
|
+
var w = { merge: true, shallow: true, extend: true };
|
|
47
|
+
function v(e2, t2 = {}, n2 = {}) {
|
|
48
|
+
n2 = { ...w, ...n2 };
|
|
49
|
+
const r2 = Object.entries(t2).reduce((t3, [r3, o]) => {
|
|
50
|
+
const i = e2[r3];
|
|
51
|
+
return n2.merge && Array.isArray(i) && Array.isArray(o) ? t3[r3] = o.reduce((e3, t4) => e3.includes(t4) ? e3 : [...e3, t4], [...i]) : (n2.extend || r3 in e2) && (t3[r3] = o), t3;
|
|
52
|
+
}, {});
|
|
53
|
+
return n2.shallow ? { ...e2, ...r2 } : (Object.assign(e2, r2), e2);
|
|
54
|
+
}
|
|
55
|
+
function k(e2) {
|
|
56
|
+
return Array.isArray(e2);
|
|
57
|
+
}
|
|
58
|
+
function M(e2) {
|
|
59
|
+
return "object" == typeof e2 && null !== e2 && !k(e2) && "[object Object]" === Object.prototype.toString.call(e2);
|
|
60
|
+
}
|
|
61
|
+
var { version: V } = r();
|
|
62
|
+
function H(e2 = {}) {
|
|
63
|
+
var _a;
|
|
64
|
+
const t2 = e2.timestamp || (/* @__PURE__ */ new Date()).setHours(0, 13, 37, 0), n2 = e2.group || "gr0up", r2 = e2.count || 1, o = v({ event: "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: [{ type: "child", data: { is: "subordinated" }, nested: [], context: { element: ["child", 0] } }], consent: { functional: true }, id: `${t2}-${n2}-${r2}`, trigger: "test", entity: "entity", action: "action", timestamp: t2, timing: 3.14, group: n2, count: r2, version: { source: V, tagging: 1 }, source: { type: "web", id: "https://localhost:80", previous_id: "http://remotehost:9001" } }, e2, { merge: false });
|
|
65
|
+
if (e2.event) {
|
|
66
|
+
const [t3, n3] = (_a = e2.event.split(" ")) != null ? _a : [];
|
|
67
|
+
t3 && n3 && (o.entity = t3, o.action = n3);
|
|
68
|
+
}
|
|
69
|
+
return o;
|
|
70
|
+
}
|
|
71
|
+
function z(e2 = "entity action", t2 = {}) {
|
|
72
|
+
const n2 = t2.timestamp || (/* @__PURE__ */ new Date()).setHours(0, 13, 37, 0), r2 = { 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 } };
|
|
73
|
+
return H({ ...{ "cart view": { data: { currency: "EUR", value: 2 * r2.data.price }, context: { shopping: ["cart", 0] }, globals: { pagegroup: "shop" }, nested: [{ type: "product", data: { ...r2.data, quantity: 2 }, context: { shopping: ["cart", 0] }, nested: [] }], trigger: "load" }, "checkout view": { data: { step: "payment", currency: "EUR", value: r2.data.price + o.data.price }, context: { shopping: ["checkout", 0] }, globals: { pagegroup: "shop" }, nested: [{ type: "product", ...r2, context: { shopping: ["checkout", 0] }, nested: [] }, { type: "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: [{ type: "product", ...r2, context: { shopping: ["complete", 0] }, nested: [] }, { type: "product", ...o, context: { shopping: ["complete", 0] }, nested: [] }, { type: "gift", data: { name: "Surprise" }, context: { shopping: ["complete", 0] }, nested: [] }], trigger: "load" }, "page view": { data: { domain: "www.example.com", title: "walkerOS documentation", referrer: "https://www.elbwalker.com/", search: "?foo=bar", hash: "#hash", id: "/docs/" }, globals: { pagegroup: "docs" }, trigger: "load" }, "product add": { ...r2, context: { shopping: ["intent", 0] }, globals: { pagegroup: "shop" }, nested: [], trigger: "click" }, "product view": { ...r2, context: { shopping: ["detail", 0] }, globals: { pagegroup: "shop" }, nested: [], trigger: "load" }, "product visible": { data: { ...r2.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: n2, 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], ...t2, event: e2 });
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// src/examples/events.ts
|
|
77
|
+
function ga4Purchase() {
|
|
78
|
+
const event = z("order complete");
|
|
79
|
+
return [
|
|
80
|
+
"event",
|
|
81
|
+
"purchase",
|
|
82
|
+
{
|
|
83
|
+
transaction_id: event.data.id,
|
|
84
|
+
value: event.data.total,
|
|
85
|
+
tax: event.data.taxes,
|
|
86
|
+
shipping: event.data.shipping,
|
|
87
|
+
currency: "EUR",
|
|
88
|
+
items: event.nested.filter((item) => item.type === "product").map((item) => ({
|
|
89
|
+
item_id: item.data.id,
|
|
90
|
+
item_name: item.data.name,
|
|
91
|
+
quantity: 1
|
|
92
|
+
})),
|
|
93
|
+
send_to: "G-XXXXXX-1"
|
|
94
|
+
}
|
|
95
|
+
];
|
|
96
|
+
}
|
|
97
|
+
function ga4AddToCart() {
|
|
98
|
+
const event = z("product add");
|
|
99
|
+
return [
|
|
100
|
+
"event",
|
|
101
|
+
"add_to_cart",
|
|
102
|
+
{
|
|
103
|
+
currency: "EUR",
|
|
104
|
+
value: event.data.price,
|
|
105
|
+
items: [
|
|
106
|
+
{
|
|
107
|
+
item_id: event.data.id,
|
|
108
|
+
item_variant: event.data.color,
|
|
109
|
+
quantity: 1
|
|
110
|
+
}
|
|
111
|
+
],
|
|
112
|
+
send_to: "G-XXXXXX-1"
|
|
113
|
+
}
|
|
114
|
+
];
|
|
115
|
+
}
|
|
116
|
+
function adsConversion() {
|
|
117
|
+
const event = z("order complete");
|
|
118
|
+
return [
|
|
119
|
+
"event",
|
|
120
|
+
"conversion",
|
|
121
|
+
{
|
|
122
|
+
send_to: "AW-XXXXXXXXX/CONVERSION_LABEL",
|
|
123
|
+
currency: "EUR",
|
|
124
|
+
value: event.data.total,
|
|
125
|
+
transaction_id: event.data.id
|
|
126
|
+
}
|
|
127
|
+
];
|
|
128
|
+
}
|
|
129
|
+
function gtmEvent() {
|
|
130
|
+
const event = z("product view");
|
|
131
|
+
return {
|
|
132
|
+
event: "product_view",
|
|
133
|
+
product_id: event.data.id,
|
|
134
|
+
product_name: event.data.name,
|
|
135
|
+
product_category: event.data.category,
|
|
136
|
+
value: event.data.price,
|
|
137
|
+
currency: "EUR"
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// src/examples/mapping.ts
|
|
142
|
+
var mapping_exports = {};
|
|
143
|
+
__export(mapping_exports, {
|
|
144
|
+
adsConversion: () => adsConversion2,
|
|
145
|
+
combinedPurchase: () => combinedPurchase,
|
|
146
|
+
config: () => config,
|
|
147
|
+
ga4AddToCart: () => ga4AddToCart2,
|
|
148
|
+
ga4Purchase: () => ga4Purchase2,
|
|
149
|
+
gtmProductView: () => gtmProductView
|
|
150
|
+
});
|
|
151
|
+
var ga4Purchase2 = {
|
|
152
|
+
name: "purchase",
|
|
153
|
+
settings: {
|
|
154
|
+
ga4: {
|
|
155
|
+
include: ["data", "context"]
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
data: {
|
|
159
|
+
map: {
|
|
160
|
+
transaction_id: "data.id",
|
|
161
|
+
value: "data.total",
|
|
162
|
+
tax: "data.taxes",
|
|
163
|
+
shipping: "data.shipping",
|
|
164
|
+
currency: { key: "data.currency", value: "EUR" },
|
|
165
|
+
items: {
|
|
166
|
+
loop: [
|
|
167
|
+
"nested",
|
|
168
|
+
{
|
|
169
|
+
condition: (entity) => M(entity) && entity.type === "product",
|
|
170
|
+
map: {
|
|
171
|
+
item_id: "data.id",
|
|
172
|
+
item_name: "data.name",
|
|
173
|
+
quantity: { key: "data.quantity", value: 1 }
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
]
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
var ga4AddToCart2 = {
|
|
182
|
+
name: "add_to_cart",
|
|
183
|
+
settings: {
|
|
184
|
+
ga4: {
|
|
185
|
+
include: ["data"]
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
data: {
|
|
189
|
+
map: {
|
|
190
|
+
currency: { value: "EUR", key: "data.currency" },
|
|
191
|
+
value: "data.price",
|
|
192
|
+
items: {
|
|
193
|
+
loop: [
|
|
194
|
+
"this",
|
|
195
|
+
{
|
|
196
|
+
map: {
|
|
197
|
+
item_id: "data.id",
|
|
198
|
+
item_variant: "data.color",
|
|
199
|
+
quantity: { value: 1, key: "data.quantity" }
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
]
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
var adsConversion2 = {
|
|
208
|
+
name: "CONVERSION_LABEL",
|
|
209
|
+
// This becomes the conversion label
|
|
210
|
+
settings: {
|
|
211
|
+
ads: {}
|
|
212
|
+
},
|
|
213
|
+
data: {
|
|
214
|
+
map: {
|
|
215
|
+
value: "data.total",
|
|
216
|
+
currency: { value: "EUR", key: "data.currency" },
|
|
217
|
+
transaction_id: "data.id"
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
var gtmProductView = {
|
|
222
|
+
name: "product_view",
|
|
223
|
+
settings: {
|
|
224
|
+
gtm: {}
|
|
225
|
+
},
|
|
226
|
+
data: {
|
|
227
|
+
map: {
|
|
228
|
+
product_id: "data.id",
|
|
229
|
+
product_name: "data.name",
|
|
230
|
+
product_category: "data.category",
|
|
231
|
+
value: "data.price",
|
|
232
|
+
currency: { value: "EUR", key: "data.currency" }
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
var combinedPurchase = {
|
|
237
|
+
name: "purchase",
|
|
238
|
+
// GA4 event name
|
|
239
|
+
settings: {
|
|
240
|
+
ga4: {
|
|
241
|
+
include: ["data"]
|
|
242
|
+
},
|
|
243
|
+
ads: {},
|
|
244
|
+
// Will use 'purchase' as conversion label for ads
|
|
245
|
+
gtm: {}
|
|
246
|
+
},
|
|
247
|
+
data: {
|
|
248
|
+
map: {
|
|
249
|
+
transaction_id: "data.id",
|
|
250
|
+
value: "data.total",
|
|
251
|
+
currency: { value: "EUR", key: "data.currency" },
|
|
252
|
+
items: {
|
|
253
|
+
loop: [
|
|
254
|
+
"nested",
|
|
255
|
+
{
|
|
256
|
+
condition: (entity) => M(entity) && entity.type === "product",
|
|
257
|
+
map: {
|
|
258
|
+
item_id: "data.id",
|
|
259
|
+
item_name: "data.name",
|
|
260
|
+
quantity: { value: 1, key: "data.quantity" }
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
]
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
var config = {
|
|
269
|
+
order: { complete: combinedPurchase },
|
|
270
|
+
product: {
|
|
271
|
+
add: ga4AddToCart2,
|
|
272
|
+
view: gtmProductView
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
276
|
+
0 && (module.exports = {
|
|
277
|
+
events,
|
|
278
|
+
mapping
|
|
279
|
+
});
|
|
@@ -0,0 +1,257 @@
|
|
|
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/events.ts
|
|
8
|
+
var events_exports = {};
|
|
9
|
+
__export(events_exports, {
|
|
10
|
+
adsConversion: () => adsConversion,
|
|
11
|
+
ga4AddToCart: () => ga4AddToCart,
|
|
12
|
+
ga4Purchase: () => ga4Purchase,
|
|
13
|
+
gtmEvent: () => gtmEvent
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
// ../../../core/dist/index.mjs
|
|
17
|
+
var e;
|
|
18
|
+
var t;
|
|
19
|
+
var n = Object.getOwnPropertyNames;
|
|
20
|
+
var r = (e = { "package.json"(e2, t2) {
|
|
21
|
+
t2.exports = { name: "@walkeros/core", description: "Core types and platform-agnostic utilities for walkerOS", version: "0.0.7", main: "./dist/index.js", module: "./dist/index.mjs", types: "./dist/index.d.ts", license: "MIT", files: ["dist/**"], scripts: { build: "tsup --silent", clean: "rm -rf .turbo && rm -rf node_modules && rm -rf dist", dev: "jest --watchAll --colors", lint: 'tsc && eslint "**/*.ts*"', test: "jest", update: "npx npm-check-updates -u && npm update" }, dependencies: {}, devDependencies: {}, repository: { url: "git+https://github.com/elbwalker/walkerOS.git", directory: "packages/core" }, author: "elbwalker <hello@elbwalker.com>", homepage: "https://github.com/elbwalker/walkerOS#readme", bugs: { url: "https://github.com/elbwalker/walkerOS/issues" }, keywords: ["walker", "walkerOS", "analytics", "tracking", "data collection", "measurement", "data privacy", "privacy friendly", "web analytics", "product analytics", "core", "types", "utils"], funding: [{ type: "GitHub Sponsors", url: "https://github.com/sponsors/elbwalker" }] };
|
|
22
|
+
} }, function() {
|
|
23
|
+
return t || (0, e[n(e)[0]])((t = { exports: {} }).exports, t), t.exports;
|
|
24
|
+
});
|
|
25
|
+
var w = { merge: true, shallow: true, extend: true };
|
|
26
|
+
function v(e2, t2 = {}, n2 = {}) {
|
|
27
|
+
n2 = { ...w, ...n2 };
|
|
28
|
+
const r2 = Object.entries(t2).reduce((t3, [r3, o]) => {
|
|
29
|
+
const i = e2[r3];
|
|
30
|
+
return n2.merge && Array.isArray(i) && Array.isArray(o) ? t3[r3] = o.reduce((e3, t4) => e3.includes(t4) ? e3 : [...e3, t4], [...i]) : (n2.extend || r3 in e2) && (t3[r3] = o), t3;
|
|
31
|
+
}, {});
|
|
32
|
+
return n2.shallow ? { ...e2, ...r2 } : (Object.assign(e2, r2), e2);
|
|
33
|
+
}
|
|
34
|
+
function k(e2) {
|
|
35
|
+
return Array.isArray(e2);
|
|
36
|
+
}
|
|
37
|
+
function M(e2) {
|
|
38
|
+
return "object" == typeof e2 && null !== e2 && !k(e2) && "[object Object]" === Object.prototype.toString.call(e2);
|
|
39
|
+
}
|
|
40
|
+
var { version: V } = r();
|
|
41
|
+
function H(e2 = {}) {
|
|
42
|
+
var _a;
|
|
43
|
+
const t2 = e2.timestamp || (/* @__PURE__ */ new Date()).setHours(0, 13, 37, 0), n2 = e2.group || "gr0up", r2 = e2.count || 1, o = v({ event: "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: [{ type: "child", data: { is: "subordinated" }, nested: [], context: { element: ["child", 0] } }], consent: { functional: true }, id: `${t2}-${n2}-${r2}`, trigger: "test", entity: "entity", action: "action", timestamp: t2, timing: 3.14, group: n2, count: r2, version: { source: V, tagging: 1 }, source: { type: "web", id: "https://localhost:80", previous_id: "http://remotehost:9001" } }, e2, { merge: false });
|
|
44
|
+
if (e2.event) {
|
|
45
|
+
const [t3, n3] = (_a = e2.event.split(" ")) != null ? _a : [];
|
|
46
|
+
t3 && n3 && (o.entity = t3, o.action = n3);
|
|
47
|
+
}
|
|
48
|
+
return o;
|
|
49
|
+
}
|
|
50
|
+
function z(e2 = "entity action", t2 = {}) {
|
|
51
|
+
const n2 = t2.timestamp || (/* @__PURE__ */ new Date()).setHours(0, 13, 37, 0), r2 = { 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 } };
|
|
52
|
+
return H({ ...{ "cart view": { data: { currency: "EUR", value: 2 * r2.data.price }, context: { shopping: ["cart", 0] }, globals: { pagegroup: "shop" }, nested: [{ type: "product", data: { ...r2.data, quantity: 2 }, context: { shopping: ["cart", 0] }, nested: [] }], trigger: "load" }, "checkout view": { data: { step: "payment", currency: "EUR", value: r2.data.price + o.data.price }, context: { shopping: ["checkout", 0] }, globals: { pagegroup: "shop" }, nested: [{ type: "product", ...r2, context: { shopping: ["checkout", 0] }, nested: [] }, { type: "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: [{ type: "product", ...r2, context: { shopping: ["complete", 0] }, nested: [] }, { type: "product", ...o, context: { shopping: ["complete", 0] }, nested: [] }, { type: "gift", data: { name: "Surprise" }, context: { shopping: ["complete", 0] }, nested: [] }], trigger: "load" }, "page view": { data: { domain: "www.example.com", title: "walkerOS documentation", referrer: "https://www.elbwalker.com/", search: "?foo=bar", hash: "#hash", id: "/docs/" }, globals: { pagegroup: "docs" }, trigger: "load" }, "product add": { ...r2, context: { shopping: ["intent", 0] }, globals: { pagegroup: "shop" }, nested: [], trigger: "click" }, "product view": { ...r2, context: { shopping: ["detail", 0] }, globals: { pagegroup: "shop" }, nested: [], trigger: "load" }, "product visible": { data: { ...r2.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: n2, 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], ...t2, event: e2 });
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// src/examples/events.ts
|
|
56
|
+
function ga4Purchase() {
|
|
57
|
+
const event = z("order complete");
|
|
58
|
+
return [
|
|
59
|
+
"event",
|
|
60
|
+
"purchase",
|
|
61
|
+
{
|
|
62
|
+
transaction_id: event.data.id,
|
|
63
|
+
value: event.data.total,
|
|
64
|
+
tax: event.data.taxes,
|
|
65
|
+
shipping: event.data.shipping,
|
|
66
|
+
currency: "EUR",
|
|
67
|
+
items: event.nested.filter((item) => item.type === "product").map((item) => ({
|
|
68
|
+
item_id: item.data.id,
|
|
69
|
+
item_name: item.data.name,
|
|
70
|
+
quantity: 1
|
|
71
|
+
})),
|
|
72
|
+
send_to: "G-XXXXXX-1"
|
|
73
|
+
}
|
|
74
|
+
];
|
|
75
|
+
}
|
|
76
|
+
function ga4AddToCart() {
|
|
77
|
+
const event = z("product add");
|
|
78
|
+
return [
|
|
79
|
+
"event",
|
|
80
|
+
"add_to_cart",
|
|
81
|
+
{
|
|
82
|
+
currency: "EUR",
|
|
83
|
+
value: event.data.price,
|
|
84
|
+
items: [
|
|
85
|
+
{
|
|
86
|
+
item_id: event.data.id,
|
|
87
|
+
item_variant: event.data.color,
|
|
88
|
+
quantity: 1
|
|
89
|
+
}
|
|
90
|
+
],
|
|
91
|
+
send_to: "G-XXXXXX-1"
|
|
92
|
+
}
|
|
93
|
+
];
|
|
94
|
+
}
|
|
95
|
+
function adsConversion() {
|
|
96
|
+
const event = z("order complete");
|
|
97
|
+
return [
|
|
98
|
+
"event",
|
|
99
|
+
"conversion",
|
|
100
|
+
{
|
|
101
|
+
send_to: "AW-XXXXXXXXX/CONVERSION_LABEL",
|
|
102
|
+
currency: "EUR",
|
|
103
|
+
value: event.data.total,
|
|
104
|
+
transaction_id: event.data.id
|
|
105
|
+
}
|
|
106
|
+
];
|
|
107
|
+
}
|
|
108
|
+
function gtmEvent() {
|
|
109
|
+
const event = z("product view");
|
|
110
|
+
return {
|
|
111
|
+
event: "product_view",
|
|
112
|
+
product_id: event.data.id,
|
|
113
|
+
product_name: event.data.name,
|
|
114
|
+
product_category: event.data.category,
|
|
115
|
+
value: event.data.price,
|
|
116
|
+
currency: "EUR"
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// src/examples/mapping.ts
|
|
121
|
+
var mapping_exports = {};
|
|
122
|
+
__export(mapping_exports, {
|
|
123
|
+
adsConversion: () => adsConversion2,
|
|
124
|
+
combinedPurchase: () => combinedPurchase,
|
|
125
|
+
config: () => config,
|
|
126
|
+
ga4AddToCart: () => ga4AddToCart2,
|
|
127
|
+
ga4Purchase: () => ga4Purchase2,
|
|
128
|
+
gtmProductView: () => gtmProductView
|
|
129
|
+
});
|
|
130
|
+
var ga4Purchase2 = {
|
|
131
|
+
name: "purchase",
|
|
132
|
+
settings: {
|
|
133
|
+
ga4: {
|
|
134
|
+
include: ["data", "context"]
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
data: {
|
|
138
|
+
map: {
|
|
139
|
+
transaction_id: "data.id",
|
|
140
|
+
value: "data.total",
|
|
141
|
+
tax: "data.taxes",
|
|
142
|
+
shipping: "data.shipping",
|
|
143
|
+
currency: { key: "data.currency", value: "EUR" },
|
|
144
|
+
items: {
|
|
145
|
+
loop: [
|
|
146
|
+
"nested",
|
|
147
|
+
{
|
|
148
|
+
condition: (entity) => M(entity) && entity.type === "product",
|
|
149
|
+
map: {
|
|
150
|
+
item_id: "data.id",
|
|
151
|
+
item_name: "data.name",
|
|
152
|
+
quantity: { key: "data.quantity", value: 1 }
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
]
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
var ga4AddToCart2 = {
|
|
161
|
+
name: "add_to_cart",
|
|
162
|
+
settings: {
|
|
163
|
+
ga4: {
|
|
164
|
+
include: ["data"]
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
data: {
|
|
168
|
+
map: {
|
|
169
|
+
currency: { value: "EUR", key: "data.currency" },
|
|
170
|
+
value: "data.price",
|
|
171
|
+
items: {
|
|
172
|
+
loop: [
|
|
173
|
+
"this",
|
|
174
|
+
{
|
|
175
|
+
map: {
|
|
176
|
+
item_id: "data.id",
|
|
177
|
+
item_variant: "data.color",
|
|
178
|
+
quantity: { value: 1, key: "data.quantity" }
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
]
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
var adsConversion2 = {
|
|
187
|
+
name: "CONVERSION_LABEL",
|
|
188
|
+
// This becomes the conversion label
|
|
189
|
+
settings: {
|
|
190
|
+
ads: {}
|
|
191
|
+
},
|
|
192
|
+
data: {
|
|
193
|
+
map: {
|
|
194
|
+
value: "data.total",
|
|
195
|
+
currency: { value: "EUR", key: "data.currency" },
|
|
196
|
+
transaction_id: "data.id"
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
var gtmProductView = {
|
|
201
|
+
name: "product_view",
|
|
202
|
+
settings: {
|
|
203
|
+
gtm: {}
|
|
204
|
+
},
|
|
205
|
+
data: {
|
|
206
|
+
map: {
|
|
207
|
+
product_id: "data.id",
|
|
208
|
+
product_name: "data.name",
|
|
209
|
+
product_category: "data.category",
|
|
210
|
+
value: "data.price",
|
|
211
|
+
currency: { value: "EUR", key: "data.currency" }
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
var combinedPurchase = {
|
|
216
|
+
name: "purchase",
|
|
217
|
+
// GA4 event name
|
|
218
|
+
settings: {
|
|
219
|
+
ga4: {
|
|
220
|
+
include: ["data"]
|
|
221
|
+
},
|
|
222
|
+
ads: {},
|
|
223
|
+
// Will use 'purchase' as conversion label for ads
|
|
224
|
+
gtm: {}
|
|
225
|
+
},
|
|
226
|
+
data: {
|
|
227
|
+
map: {
|
|
228
|
+
transaction_id: "data.id",
|
|
229
|
+
value: "data.total",
|
|
230
|
+
currency: { value: "EUR", key: "data.currency" },
|
|
231
|
+
items: {
|
|
232
|
+
loop: [
|
|
233
|
+
"nested",
|
|
234
|
+
{
|
|
235
|
+
condition: (entity) => M(entity) && entity.type === "product",
|
|
236
|
+
map: {
|
|
237
|
+
item_id: "data.id",
|
|
238
|
+
item_name: "data.name",
|
|
239
|
+
quantity: { value: 1, key: "data.quantity" }
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
]
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
var config = {
|
|
248
|
+
order: { complete: combinedPurchase },
|
|
249
|
+
product: {
|
|
250
|
+
add: ga4AddToCart2,
|
|
251
|
+
view: gtmProductView
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
export {
|
|
255
|
+
events_exports as events,
|
|
256
|
+
mapping_exports as mapping
|
|
257
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var Destination=(()=>{var e=Object.defineProperty,t=Object.getOwnPropertyDescriptor,a=Object.getOwnPropertyNames,n=Object.prototype.hasOwnProperty,r=(t,a)=>{for(var n in a)e(t,n,{get:a[n],enumerable:!0})},o={};r(o,{DestinationGtag:()=>k,default:()=>z,destinationGtag:()=>P,examples:()=>x});var i,s,c=new Set;function d(e,t="https://www.googletagmanager.com/gtag/js?id="){if(c.has(e))return;const a=document.createElement("script");a.src=t+e,document.head.appendChild(a),c.add(e)}function u(){const e=window;e.dataLayer=e.dataLayer||[],e.gtag||(e.gtag=function(){e.dataLayer.push(arguments)})}function p(e){return e("gtag",window.gtag)}var l=Object.getOwnPropertyNames,g=(i={"package.json"(e,t){t.exports={name:"@walkeros/core",description:"Core types and platform-agnostic utilities for walkerOS",version:"0.0.7",main:"./dist/index.js",module:"./dist/index.mjs",types:"./dist/index.d.ts",license:"MIT",files:["dist/**"],scripts:{build:"tsup --silent",clean:"rm -rf .turbo && rm -rf node_modules && rm -rf dist",dev:"jest --watchAll --colors",lint:'tsc && eslint "**/*.ts*"',test:"jest",update:"npx npm-check-updates -u && npm update"},dependencies:{},devDependencies:{},repository:{url:"git+https://github.com/elbwalker/walkerOS.git",directory:"packages/core"},author:"elbwalker <hello@elbwalker.com>",homepage:"https://github.com/elbwalker/walkerOS#readme",bugs:{url:"https://github.com/elbwalker/walkerOS/issues"},keywords:["walker","walkerOS","analytics","tracking","data collection","measurement","data privacy","privacy friendly","web analytics","product analytics","core","types","utils"],funding:[{type:"GitHub Sponsors",url:"https://github.com/sponsors/elbwalker"}]}}},function(){return s||(0,i[l(i)[0]])((s={exports:{}}).exports,s),s.exports}),m={merge:!0,shallow:!0,extend:!0};function y(e){return"object"==typeof e&&null!==e&&!function(e){return Array.isArray(e)}(e)&&"[object Object]"===Object.prototype.toString.call(e)}var{version:v}=g();function h(e={}){var t;const a=e.timestamp||(new Date).setHours(0,13,37,0),n=e.group||"gr0up",r=e.count||1,o=function(e,t={},a={}){a={...m,...a};const n=Object.entries(t).reduce((t,[n,r])=>{const o=e[n];return a.merge&&Array.isArray(o)&&Array.isArray(r)?t[n]=r.reduce((e,t)=>e.includes(t)?e:[...e,t],[...o]):(a.extend||n in e)&&(t[n]=r),t},{});return a.shallow?{...e,...n}:(Object.assign(e,n),e)}({event:"entity action",data:{string:"foo",number:1,boolean:!0,array:[0,"text",!1],not:void 0},context:{dev:["test",1]},globals:{lang:"elb"},custom:{completely:"random"},user:{id:"us3r",device:"c00k13",session:"s3ss10n"},nested:[{type:"child",data:{is:"subordinated"},nested:[],context:{element:["child",0]}}],consent:{functional:!0},id:`${a}-${n}-${r}`,trigger:"test",entity:"entity",action:"action",timestamp:a,timing:3.14,group:n,count:r,version:{source:v,tagging:1},source:{type:"web",id:"https://localhost:80",previous_id:"http://remotehost:9001"}},e,{merge:!1});if(e.event){const[a,n]=null!=(t=e.event.split(" "))?t:[];a&&n&&(o.entity=a,o.action=n)}return o}function w(e="entity action",t={}){const a=t.timestamp||(new Date).setHours(0,13,37,0),n={data:{id:"ers",name:"Everyday Ruck Snack",color:"black",size:"l",price:420}},r={data:{id:"cc",name:"Cool Cap",size:"one size",price:42}};return h({...{"cart view":{data:{currency:"EUR",value:2*n.data.price},context:{shopping:["cart",0]},globals:{pagegroup:"shop"},nested:[{type:"product",data:{...n.data,quantity:2},context:{shopping:["cart",0]},nested:[]}],trigger:"load"},"checkout view":{data:{step:"payment",currency:"EUR",value:n.data.price+r.data.price},context:{shopping:["checkout",0]},globals:{pagegroup:"shop"},nested:[{type:"product",...n,context:{shopping:["checkout",0]},nested:[]},{type:"product",...r,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:[{type:"product",...n,context:{shopping:["complete",0]},nested:[]},{type:"product",...r,context:{shopping:["complete",0]},nested:[]},{type:"gift",data:{name:"Surprise"},context:{shopping:["complete",0]},nested:[]}],trigger:"load"},"page view":{data:{domain:"www.example.com",title:"walkerOS documentation",referrer:"https://www.elbwalker.com/",search:"?foo=bar",hash:"#hash",id:"/docs/"},globals:{pagegroup:"docs"},trigger:"load"},"product add":{...n,context:{shopping:["intent",0]},globals:{pagegroup:"shop"},nested:[],trigger:"click"},"product view":{...n,context:{shopping:["detail",0]},globals:{pagegroup:"shop"},nested:[],trigger:"load"},"product visible":{data:{...n.data,position:3,promo:!0},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:a,isNew:!0,count:1,runs:1,isStart:!0,storage:!0,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:!0,custom:"value"}}}[e],...t,event:e})}function b(e,t,a={},n,r){if(!t.measurementId)return;const o=y(n)?n:{},i=function(e,t){const a={};return t.includes("all")&&(t=["context","data","event","globals","source","user","version"]),t.forEach(t=>{let n=e[t]||{};"event"==t&&(n={id:e.id,timing:e.timing,trigger:e.trigger,entity:e.entity,action:e.action,group:e.group,count:e.count}),Object.entries(n).forEach(([e,n])=>{"context"==t&&(n=n[0]),a[`${t}_${e}`]=n})}),a}(e,a.include||t.include||["data"]),s={...i,...o};let c=e.event;!1!==t.snakeCase&&(c=function(e,t=!0){return t?e.replace(/\s+/g,"_").toLowerCase():e}(c)),s.send_to=t.measurementId,t.debug&&(s.debug_mode=!0);p(r)("event",c,s)}var f="dataLayer";function _(e,t,a){const{containerId:n,dataLayer:r,domain:o}=e,i=r||f,s=window;i===f?s.dataLayer=s.dataLayer||[]:s[i]=s[i]||[];const c=s[i];t("dataLayer.push",c.push.bind(c))({"gtm.start":(new Date).getTime(),event:"gtm.js"}),a&&n&&function(e,t,a){const n=a!=f?"&l="+a:"",r=document.createElement("script");r.src=t+e+n,document.head.appendChild(r)}(n,o||"https://www.googletagmanager.com/gtm.js?id=",i)}var k={},x={};r(x,{events:()=>E,mapping:()=>S});var E={};function O(){const e=w("order complete");return["event","purchase",{transaction_id:e.data.id,value:e.data.total,tax:e.data.taxes,shipping:e.data.shipping,currency:"EUR",items:e.nested.filter(e=>"product"===e.type).map(e=>({item_id:e.data.id,item_name:e.data.name,quantity:1})),send_to:"G-XXXXXX-1"}]}function j(){const e=w("product add");return["event","add_to_cart",{currency:"EUR",value:e.data.price,items:[{item_id:e.data.id,item_variant:e.data.color,quantity:1}],send_to:"G-XXXXXX-1"}]}function X(){const e=w("order complete");return["event","conversion",{send_to:"AW-XXXXXXXXX/CONVERSION_LABEL",currency:"EUR",value:e.data.total,transaction_id:e.data.id}]}function I(){const e=w("product view");return{event:"product_view",product_id:e.data.id,product_name:e.data.name,product_category:e.data.category,value:e.data.price,currency:"EUR"}}r(E,{adsConversion:()=>X,ga4AddToCart:()=>j,ga4Purchase:()=>O,gtmEvent:()=>I});var S={};r(S,{adsConversion:()=>U,combinedPurchase:()=>D,config:()=>q,ga4AddToCart:()=>C,ga4Purchase:()=>L,gtmProductView:()=>A});var R,L={name:"purchase",settings:{ga4:{include:["data","context"]}},data:{map:{transaction_id:"data.id",value:"data.total",tax:"data.taxes",shipping:"data.shipping",currency:{key:"data.currency",value:"EUR"},items:{loop:["nested",{condition:e=>y(e)&&"product"===e.type,map:{item_id:"data.id",item_name:"data.name",quantity:{key:"data.quantity",value:1}}}]}}}},C={name:"add_to_cart",settings:{ga4:{include:["data"]}},data:{map:{currency:{value:"EUR",key:"data.currency"},value:"data.price",items:{loop:["this",{map:{item_id:"data.id",item_variant:"data.color",quantity:{value:1,key:"data.quantity"}}}]}}}},U={name:"CONVERSION_LABEL",settings:{ads:{}},data:{map:{value:"data.total",currency:{value:"EUR",key:"data.currency"},transaction_id:"data.id"}}},A={name:"product_view",settings:{gtm:{}},data:{map:{product_id:"data.id",product_name:"data.name",product_category:"data.category",value:"data.price",currency:{value:"EUR",key:"data.currency"}}}},D={name:"purchase",settings:{ga4:{include:["data"]},ads:{},gtm:{}},data:{map:{transaction_id:"data.id",value:"data.total",currency:{value:"EUR",key:"data.currency"},items:{loop:["nested",{condition:e=>y(e)&&"product"===e.type,map:{item_id:"data.id",item_name:"data.name",quantity:{value:1,key:"data.quantity"}}}]}}}},q={order:{complete:D},product:{add:C,view:A}},P={type:"google-gtag",config:{settings:{}},init({config:e,wrap:t}){const{settings:a={},loadScript:n}=e,{ga4:r,ads:o,gtm:i}=a;return(null==r?void 0:r.measurementId)&&function(e,t,a){const{measurementId:n,transport_url:r,server_container_url:o,pageview:i}=e;if(!n)return;a&&d(n),u();const s={};r&&(s.transport_url=r),o&&(s.server_container_url=o),!1===i&&(s.send_page_view=!1);const c=p(t);c("js",new Date),c("config",n,s)}(r,t,n),(null==o?void 0:o.conversionId)&&function(e,t,a){const{conversionId:n}=e;if(!n)return;e.currency||(e.currency="EUR"),a&&d(n),u();const r=p(t);r("js",new Date),r("config",n)}(o,t,n),(null==i?void 0:i.containerId)&&_(i,t,n),!!((null==r?void 0:r.measurementId)||(null==o?void 0:o.conversionId)||(null==i?void 0:i.containerId))&&e},push(e,{config:t,mapping:a={},data:n,wrap:r}){const{settings:o={}}=t,{ga4:i,ads:s,gtm:c}=o,d=a.settings||{};(null==i?void 0:i.measurementId)&&b(e,i,d.ga4,n,r),(null==s?void 0:s.conversionId)&&a.name&&function(e,t,a={},n,r,o){const{conversionId:i,currency:s}=t,c=y(n)?n:{},d=a.label||o;if(!d)return;const u={send_to:`${i}/${d}`,currency:s||"EUR",...c};p(r)("event","conversion",u)}(0,s,d.ads,n,r,a.name),(null==c?void 0:c.containerId)&&function(e,t,a={},n,r){const o=window;r("dataLayer.push",o.dataLayer.push.bind(o.dataLayer))({event:e.event,...y(n)?n:e})}(e,0,d.gtm,n,r)}},z=P;return R=o,((r,o,i,s)=>{if(o&&"object"==typeof o||"function"==typeof o)for(let c of a(o))n.call(r,c)||c===i||e(r,c,{get:()=>o[c],enumerable:!(s=t(o,c))||s.enumerable});return r})(e({},"__esModule",{value:!0}),R)})();
|