@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.
@@ -0,0 +1,89 @@
1
+ import { 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
+ interface AdsMapping {
28
+ label?: string;
29
+ }
30
+ interface Mapping {
31
+ ga4?: GA4Mapping;
32
+ ads?: AdsMapping;
33
+ gtm?: GTMMapping;
34
+ }
35
+ interface GA4Mapping {
36
+ include?: Include;
37
+ }
38
+ interface GTMMapping {
39
+ }
40
+ type Rule = Mapping$1.Rule<Mapping>;
41
+ type Include = Array<'all' | 'context' | 'data' | 'event' | 'globals' | 'source' | 'user' | 'version'>;
42
+
43
+ declare const init: Env | undefined;
44
+ declare const push: Env;
45
+ declare const simulation: string[];
46
+
47
+ declare const env_init: typeof init;
48
+ declare const env_push: typeof push;
49
+ declare const env_simulation: typeof simulation;
50
+ declare namespace env {
51
+ export { env_init as init, env_push as push, env_simulation as simulation };
52
+ }
53
+
54
+ declare function ga4Purchase$1(): unknown[];
55
+ declare function ga4AddToCart$1(): unknown[];
56
+ declare function adsConversion$1(): unknown[];
57
+ declare function gtmEvent(): Record<string, unknown>;
58
+
59
+ declare const events_gtmEvent: typeof gtmEvent;
60
+ declare namespace events {
61
+ export { adsConversion$1 as adsConversion, ga4AddToCart$1 as ga4AddToCart, ga4Purchase$1 as ga4Purchase, events_gtmEvent as gtmEvent };
62
+ }
63
+
64
+ declare const ga4Purchase: Rule;
65
+ declare const ga4AddToCart: Rule;
66
+ declare const adsConversion: Rule;
67
+ declare const gtmProductView: Rule;
68
+ declare const combinedPurchase: Rule;
69
+ declare const config: {
70
+ order: {
71
+ complete: Rule;
72
+ };
73
+ product: {
74
+ add: Rule;
75
+ view: Rule;
76
+ };
77
+ };
78
+
79
+ declare const mapping_adsConversion: typeof adsConversion;
80
+ declare const mapping_combinedPurchase: typeof combinedPurchase;
81
+ declare const mapping_config: typeof config;
82
+ declare const mapping_ga4AddToCart: typeof ga4AddToCart;
83
+ declare const mapping_ga4Purchase: typeof ga4Purchase;
84
+ declare const mapping_gtmProductView: typeof gtmProductView;
85
+ declare namespace mapping {
86
+ export { mapping_adsConversion as adsConversion, mapping_combinedPurchase as combinedPurchase, mapping_config as config, mapping_ga4AddToCart as ga4AddToCart, mapping_ga4Purchase as ga4Purchase, mapping_gtmProductView as gtmProductView };
87
+ }
88
+
89
+ export { env, events, mapping };
@@ -0,0 +1,89 @@
1
+ import { 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
+ interface AdsMapping {
28
+ label?: string;
29
+ }
30
+ interface Mapping {
31
+ ga4?: GA4Mapping;
32
+ ads?: AdsMapping;
33
+ gtm?: GTMMapping;
34
+ }
35
+ interface GA4Mapping {
36
+ include?: Include;
37
+ }
38
+ interface GTMMapping {
39
+ }
40
+ type Rule = Mapping$1.Rule<Mapping>;
41
+ type Include = Array<'all' | 'context' | 'data' | 'event' | 'globals' | 'source' | 'user' | 'version'>;
42
+
43
+ declare const init: Env | undefined;
44
+ declare const push: Env;
45
+ declare const simulation: string[];
46
+
47
+ declare const env_init: typeof init;
48
+ declare const env_push: typeof push;
49
+ declare const env_simulation: typeof simulation;
50
+ declare namespace env {
51
+ export { env_init as init, env_push as push, env_simulation as simulation };
52
+ }
53
+
54
+ declare function ga4Purchase$1(): unknown[];
55
+ declare function ga4AddToCart$1(): unknown[];
56
+ declare function adsConversion$1(): unknown[];
57
+ declare function gtmEvent(): Record<string, unknown>;
58
+
59
+ declare const events_gtmEvent: typeof gtmEvent;
60
+ declare namespace events {
61
+ export { adsConversion$1 as adsConversion, ga4AddToCart$1 as ga4AddToCart, ga4Purchase$1 as ga4Purchase, events_gtmEvent as gtmEvent };
62
+ }
63
+
64
+ declare const ga4Purchase: Rule;
65
+ declare const ga4AddToCart: Rule;
66
+ declare const adsConversion: Rule;
67
+ declare const gtmProductView: Rule;
68
+ declare const combinedPurchase: Rule;
69
+ declare const config: {
70
+ order: {
71
+ complete: Rule;
72
+ };
73
+ product: {
74
+ add: Rule;
75
+ view: Rule;
76
+ };
77
+ };
78
+
79
+ declare const mapping_adsConversion: typeof adsConversion;
80
+ declare const mapping_combinedPurchase: typeof combinedPurchase;
81
+ declare const mapping_config: typeof config;
82
+ declare const mapping_ga4AddToCart: typeof ga4AddToCart;
83
+ declare const mapping_ga4Purchase: typeof ga4Purchase;
84
+ declare const mapping_gtmProductView: typeof gtmProductView;
85
+ declare namespace mapping {
86
+ export { mapping_adsConversion as adsConversion, mapping_combinedPurchase as combinedPurchase, mapping_config as config, mapping_ga4AddToCart as ga4AddToCart, mapping_ga4Purchase as ga4Purchase, mapping_gtmProductView as gtmProductView };
87
+ }
88
+
89
+ export { env, events, mapping };
@@ -0,0 +1,328 @@
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
+ env: () => env_exports,
24
+ events: () => events_exports,
25
+ mapping: () => mapping_exports
26
+ });
27
+ module.exports = __toCommonJS(examples_exports);
28
+
29
+ // src/examples/env.ts
30
+ var env_exports = {};
31
+ __export(env_exports, {
32
+ init: () => init,
33
+ push: () => push,
34
+ simulation: () => simulation
35
+ });
36
+ var noop = () => {
37
+ };
38
+ var init = {
39
+ window: {
40
+ gtag: void 0,
41
+ dataLayer: []
42
+ },
43
+ document: {
44
+ createElement: () => ({
45
+ src: "",
46
+ setAttribute: () => {
47
+ },
48
+ removeAttribute: () => {
49
+ }
50
+ }),
51
+ head: { appendChild: () => {
52
+ } }
53
+ }
54
+ };
55
+ var push = {
56
+ window: {
57
+ gtag: Object.assign(noop, {
58
+ // Add any gtag-specific properties if needed
59
+ }),
60
+ dataLayer: []
61
+ },
62
+ document: {
63
+ createElement: () => ({
64
+ src: "",
65
+ setAttribute: () => {
66
+ },
67
+ removeAttribute: () => {
68
+ }
69
+ }),
70
+ head: { appendChild: () => {
71
+ } }
72
+ }
73
+ };
74
+ var simulation = [
75
+ "call:window.gtag"
76
+ // Track gtag function calls
77
+ ];
78
+
79
+ // src/examples/events.ts
80
+ var events_exports = {};
81
+ __export(events_exports, {
82
+ adsConversion: () => adsConversion,
83
+ ga4AddToCart: () => ga4AddToCart,
84
+ ga4Purchase: () => ga4Purchase,
85
+ gtmEvent: () => gtmEvent
86
+ });
87
+
88
+ // ../../../core/dist/index.mjs
89
+ var e = Object.defineProperty;
90
+ var c = {};
91
+ ((t, n) => {
92
+ for (var r in n) e(t, r, { get: n[r], enumerable: true });
93
+ })(c, { Level: () => a });
94
+ var a = ((e2) => (e2[e2.ERROR = 0] = "ERROR", e2[e2.INFO = 1] = "INFO", e2[e2.DEBUG = 2] = "DEBUG", e2))(a || {});
95
+ var E = { merge: true, shallow: true, extend: true };
96
+ function S(e2, t = {}, n = {}) {
97
+ n = { ...E, ...n };
98
+ const r = Object.entries(t).reduce((t2, [r2, o]) => {
99
+ const i = e2[r2];
100
+ 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;
101
+ }, {});
102
+ return n.shallow ? { ...e2, ...r } : (Object.assign(e2, r), e2);
103
+ }
104
+ function A(e2) {
105
+ return Array.isArray(e2);
106
+ }
107
+ function _(e2) {
108
+ return "object" == typeof e2 && null !== e2 && !A(e2) && "[object Object]" === Object.prototype.toString.call(e2);
109
+ }
110
+ function W(e2 = {}) {
111
+ var _a;
112
+ 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 });
113
+ if (e2.name) {
114
+ const [t2, n2] = (_a = e2.name.split(" ")) != null ? _a : [];
115
+ t2 && n2 && (o.entity = t2, o.action = n2);
116
+ }
117
+ return o;
118
+ }
119
+ function B(e2 = "entity action", t = {}) {
120
+ 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 } };
121
+ 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 });
122
+ }
123
+
124
+ // src/examples/events.ts
125
+ function ga4Purchase() {
126
+ const event = B("order complete");
127
+ return [
128
+ "event",
129
+ "purchase",
130
+ {
131
+ transaction_id: event.data.id,
132
+ value: event.data.total,
133
+ tax: event.data.taxes,
134
+ shipping: event.data.shipping,
135
+ currency: "EUR",
136
+ items: event.nested.filter((item) => item.entity === "product").map((item) => ({
137
+ item_id: item.data.id,
138
+ item_name: item.data.name,
139
+ quantity: 1
140
+ })),
141
+ send_to: "G-XXXXXX-1"
142
+ }
143
+ ];
144
+ }
145
+ function ga4AddToCart() {
146
+ const event = B("product add");
147
+ return [
148
+ "event",
149
+ "add_to_cart",
150
+ {
151
+ currency: "EUR",
152
+ value: event.data.price,
153
+ items: [
154
+ {
155
+ item_id: event.data.id,
156
+ item_variant: event.data.color,
157
+ quantity: 1
158
+ }
159
+ ],
160
+ send_to: "G-XXXXXX-1"
161
+ }
162
+ ];
163
+ }
164
+ function adsConversion() {
165
+ const event = B("order complete");
166
+ return [
167
+ "event",
168
+ "conversion",
169
+ {
170
+ send_to: "AW-XXXXXXXXX/CONVERSION_LABEL",
171
+ currency: "EUR",
172
+ value: event.data.total,
173
+ transaction_id: event.data.id
174
+ }
175
+ ];
176
+ }
177
+ function gtmEvent() {
178
+ const event = B("product view");
179
+ return {
180
+ event: "product_view",
181
+ product_id: event.data.id,
182
+ product_name: event.data.name,
183
+ product_category: event.data.category,
184
+ value: event.data.price,
185
+ currency: "EUR"
186
+ };
187
+ }
188
+
189
+ // src/examples/mapping.ts
190
+ var mapping_exports = {};
191
+ __export(mapping_exports, {
192
+ adsConversion: () => adsConversion2,
193
+ combinedPurchase: () => combinedPurchase,
194
+ config: () => config,
195
+ ga4AddToCart: () => ga4AddToCart2,
196
+ ga4Purchase: () => ga4Purchase2,
197
+ gtmProductView: () => gtmProductView
198
+ });
199
+ var ga4Purchase2 = {
200
+ name: "purchase",
201
+ settings: {
202
+ ga4: {
203
+ include: ["data", "context"]
204
+ }
205
+ },
206
+ data: {
207
+ map: {
208
+ transaction_id: "data.id",
209
+ value: "data.total",
210
+ tax: "data.taxes",
211
+ shipping: "data.shipping",
212
+ currency: { key: "data.currency", value: "EUR" },
213
+ items: {
214
+ loop: [
215
+ "nested",
216
+ {
217
+ condition: (entity) => _(entity) && entity.entity === "product",
218
+ map: {
219
+ item_id: "data.id",
220
+ item_name: "data.name",
221
+ quantity: { key: "data.quantity", value: 1 }
222
+ }
223
+ }
224
+ ]
225
+ }
226
+ }
227
+ }
228
+ };
229
+ var ga4AddToCart2 = {
230
+ name: "add_to_cart",
231
+ settings: {
232
+ ga4: {
233
+ include: ["data"]
234
+ }
235
+ },
236
+ data: {
237
+ map: {
238
+ currency: { value: "EUR", key: "data.currency" },
239
+ value: "data.price",
240
+ items: {
241
+ loop: [
242
+ "this",
243
+ {
244
+ map: {
245
+ item_id: "data.id",
246
+ item_variant: "data.color",
247
+ quantity: { value: 1, key: "data.quantity" }
248
+ }
249
+ }
250
+ ]
251
+ }
252
+ }
253
+ }
254
+ };
255
+ var adsConversion2 = {
256
+ name: "CONVERSION_LABEL",
257
+ // This becomes the conversion label
258
+ settings: {
259
+ ads: {}
260
+ },
261
+ data: {
262
+ map: {
263
+ value: "data.total",
264
+ currency: { value: "EUR", key: "data.currency" },
265
+ transaction_id: "data.id"
266
+ }
267
+ }
268
+ };
269
+ var gtmProductView = {
270
+ name: "product_view",
271
+ settings: {
272
+ gtm: {}
273
+ },
274
+ data: {
275
+ map: {
276
+ product_id: "data.id",
277
+ product_name: "data.name",
278
+ product_category: "data.category",
279
+ value: "data.price",
280
+ currency: { value: "EUR", key: "data.currency" }
281
+ }
282
+ }
283
+ };
284
+ var combinedPurchase = {
285
+ name: "purchase",
286
+ // GA4 event name
287
+ settings: {
288
+ ga4: {
289
+ include: ["data"]
290
+ },
291
+ ads: {},
292
+ // Will use 'purchase' as conversion label for ads
293
+ gtm: {}
294
+ },
295
+ data: {
296
+ map: {
297
+ transaction_id: "data.id",
298
+ value: "data.total",
299
+ currency: { value: "EUR", key: "data.currency" },
300
+ items: {
301
+ loop: [
302
+ "nested",
303
+ {
304
+ condition: (entity) => _(entity) && entity.entity === "product",
305
+ map: {
306
+ item_id: "data.id",
307
+ item_name: "data.name",
308
+ quantity: { value: 1, key: "data.quantity" }
309
+ }
310
+ }
311
+ ]
312
+ }
313
+ }
314
+ }
315
+ };
316
+ var config = {
317
+ order: { complete: combinedPurchase },
318
+ product: {
319
+ add: ga4AddToCart2,
320
+ view: gtmProductView
321
+ }
322
+ };
323
+ // Annotate the CommonJS export names for ESM import in node:
324
+ 0 && (module.exports = {
325
+ env,
326
+ events,
327
+ mapping
328
+ });