@walkeros/web-destination-meta 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -30,10 +30,10 @@ npm install @walkeros/web-destination-meta
30
30
  Here's a basic example of how to use the Meta Pixel destination:
31
31
 
32
32
  ```typescript
33
- import { createCollector } from '@walkeros/collector';
33
+ import { startFlow } from '@walkeros/collector';
34
34
  import { destinationMeta } from '@walkeros/web-destination-meta';
35
35
 
36
- const { elb } = await createCollector();
36
+ const { elb } = await startFlow();
37
37
 
38
38
  elb('walker destination', destinationMeta, {
39
39
  settings: {
@@ -1,13 +1,5 @@
1
1
  import { Mapping as Mapping$1 } from '@walkeros/core';
2
-
3
- declare function Purchase$1(): unknown[];
4
- declare function AddToCart$1(): unknown[];
5
- declare function InitiateCheckout$1(): unknown[];
6
- declare function ViewContent$1(): unknown[];
7
-
8
- declare namespace events {
9
- export { AddToCart$1 as AddToCart, InitiateCheckout$1 as InitiateCheckout, Purchase$1 as Purchase, ViewContent$1 as ViewContent };
10
- }
2
+ import { DestinationWeb } from '@walkeros/web-core';
11
3
 
12
4
  declare global {
13
5
  interface Window {
@@ -19,9 +11,39 @@ interface Mapping {
19
11
  track?: StandardEventNames;
20
12
  trackCustom?: string;
21
13
  }
14
+ interface Env extends DestinationWeb.Env {
15
+ window: {
16
+ fbq: facebook.Pixel.Event;
17
+ _fbq?: facebook.Pixel.Event;
18
+ };
19
+ document: {
20
+ createElement: (tagName: string) => Element;
21
+ head: {
22
+ appendChild: (node: unknown) => void;
23
+ };
24
+ };
25
+ }
22
26
  type Rule = Mapping$1.Rule<Mapping>;
23
27
  type StandardEventNames = 'PageView' | 'AddPaymentInfo' | 'AddToCart' | 'AddToWishlist' | 'CompleteRegistration' | 'Contact' | 'CustomizeProduct' | 'Donate' | 'FindLocation' | 'InitiateCheckout' | 'Lead' | 'Purchase' | 'Schedule' | 'Search' | 'StartTrial' | 'SubmitApplication' | 'Subscribe' | 'ViewContent' | string;
24
28
 
29
+ declare const init: Env | undefined;
30
+ declare const push: Env;
31
+
32
+ declare const env_init: typeof init;
33
+ declare const env_push: typeof push;
34
+ declare namespace env {
35
+ export { env_init as init, env_push as push };
36
+ }
37
+
38
+ declare function Purchase$1(): unknown[];
39
+ declare function AddToCart$1(): unknown[];
40
+ declare function InitiateCheckout$1(): unknown[];
41
+ declare function ViewContent$1(): unknown[];
42
+
43
+ declare namespace events {
44
+ export { AddToCart$1 as AddToCart, InitiateCheckout$1 as InitiateCheckout, Purchase$1 as Purchase, ViewContent$1 as ViewContent };
45
+ }
46
+
25
47
  declare const Purchase: Rule;
26
48
  declare const AddToCart: Rule;
27
49
  declare const InitiateCheckout: Rule;
@@ -48,4 +70,4 @@ declare namespace mapping {
48
70
  export { mapping_AddToCart as AddToCart, mapping_InitiateCheckout as InitiateCheckout, mapping_Purchase as Purchase, mapping_ViewContent as ViewContent, mapping_config as config };
49
71
  }
50
72
 
51
- export { events, mapping };
73
+ export { env, events, mapping };
@@ -1,13 +1,5 @@
1
1
  import { Mapping as Mapping$1 } from '@walkeros/core';
2
-
3
- declare function Purchase$1(): unknown[];
4
- declare function AddToCart$1(): unknown[];
5
- declare function InitiateCheckout$1(): unknown[];
6
- declare function ViewContent$1(): unknown[];
7
-
8
- declare namespace events {
9
- export { AddToCart$1 as AddToCart, InitiateCheckout$1 as InitiateCheckout, Purchase$1 as Purchase, ViewContent$1 as ViewContent };
10
- }
2
+ import { DestinationWeb } from '@walkeros/web-core';
11
3
 
12
4
  declare global {
13
5
  interface Window {
@@ -19,9 +11,39 @@ interface Mapping {
19
11
  track?: StandardEventNames;
20
12
  trackCustom?: string;
21
13
  }
14
+ interface Env extends DestinationWeb.Env {
15
+ window: {
16
+ fbq: facebook.Pixel.Event;
17
+ _fbq?: facebook.Pixel.Event;
18
+ };
19
+ document: {
20
+ createElement: (tagName: string) => Element;
21
+ head: {
22
+ appendChild: (node: unknown) => void;
23
+ };
24
+ };
25
+ }
22
26
  type Rule = Mapping$1.Rule<Mapping>;
23
27
  type StandardEventNames = 'PageView' | 'AddPaymentInfo' | 'AddToCart' | 'AddToWishlist' | 'CompleteRegistration' | 'Contact' | 'CustomizeProduct' | 'Donate' | 'FindLocation' | 'InitiateCheckout' | 'Lead' | 'Purchase' | 'Schedule' | 'Search' | 'StartTrial' | 'SubmitApplication' | 'Subscribe' | 'ViewContent' | string;
24
28
 
29
+ declare const init: Env | undefined;
30
+ declare const push: Env;
31
+
32
+ declare const env_init: typeof init;
33
+ declare const env_push: typeof push;
34
+ declare namespace env {
35
+ export { env_init as init, env_push as push };
36
+ }
37
+
38
+ declare function Purchase$1(): unknown[];
39
+ declare function AddToCart$1(): unknown[];
40
+ declare function InitiateCheckout$1(): unknown[];
41
+ declare function ViewContent$1(): unknown[];
42
+
43
+ declare namespace events {
44
+ export { AddToCart$1 as AddToCart, InitiateCheckout$1 as InitiateCheckout, Purchase$1 as Purchase, ViewContent$1 as ViewContent };
45
+ }
46
+
25
47
  declare const Purchase: Rule;
26
48
  declare const AddToCart: Rule;
27
49
  declare const InitiateCheckout: Rule;
@@ -48,4 +70,4 @@ declare namespace mapping {
48
70
  export { mapping_AddToCart as AddToCart, mapping_InitiateCheckout as InitiateCheckout, mapping_Purchase as Purchase, mapping_ViewContent as ViewContent, mapping_config as config };
49
71
  }
50
72
 
51
- export { events, mapping };
73
+ export { env, events, mapping };
@@ -20,11 +20,72 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/examples/index.ts
21
21
  var examples_exports = {};
22
22
  __export(examples_exports, {
23
+ env: () => env_exports,
23
24
  events: () => events_exports,
24
25
  mapping: () => mapping_exports
25
26
  });
26
27
  module.exports = __toCommonJS(examples_exports);
27
28
 
29
+ // src/examples/env.ts
30
+ var env_exports = {};
31
+ __export(env_exports, {
32
+ init: () => init,
33
+ push: () => push
34
+ });
35
+ var noop = () => {
36
+ };
37
+ var init = {
38
+ // Environment before initialization (fbq not loaded yet)
39
+ window: {
40
+ fbq: void 0,
41
+ _fbq: void 0
42
+ },
43
+ document: {
44
+ createElement: () => ({
45
+ src: "",
46
+ async: false,
47
+ setAttribute: () => {
48
+ },
49
+ removeAttribute: () => {
50
+ }
51
+ }),
52
+ head: { appendChild: () => {
53
+ } }
54
+ }
55
+ };
56
+ var push = {
57
+ // Standard mock environment for testing
58
+ window: {
59
+ fbq: Object.assign(noop, {
60
+ // Add Meta Pixel specific properties
61
+ callMethod: noop,
62
+ queue: [],
63
+ push: noop,
64
+ loaded: true,
65
+ version: "2.0"
66
+ }),
67
+ _fbq: Object.assign(noop, {
68
+ callMethod: noop,
69
+ queue: [],
70
+ push: noop,
71
+ loaded: true,
72
+ version: "2.0"
73
+ })
74
+ },
75
+ document: {
76
+ createElement: () => ({
77
+ src: "",
78
+ async: false,
79
+ setAttribute: () => {
80
+ },
81
+ removeAttribute: () => {
82
+ }
83
+ }),
84
+ head: { appendChild: () => {
85
+ } }
86
+ }
87
+ };
88
+
28
89
  // src/examples/events.ts
29
90
  var events_exports = {};
30
91
  __export(events_exports, {
@@ -35,47 +96,38 @@ __export(events_exports, {
35
96
  });
36
97
 
37
98
  // ../../../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.1.2", 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;
99
+ var m = { merge: true, shallow: true, extend: true };
100
+ function y(e, t = {}, n = {}) {
101
+ n = { ...m, ...n };
102
+ const r = Object.entries(t).reduce((t2, [r2, o]) => {
103
+ const i = e[r2];
104
+ return n.merge && Array.isArray(i) && Array.isArray(o) ? t2[r2] = o.reduce((e2, t3) => e2.includes(t3) ? e2 : [...e2, t3], [...i]) : (n.extend || r2 in e) && (t2[r2] = o), t2;
52
105
  }, {});
53
- return n2.shallow ? { ...e2, ...r2 } : (Object.assign(e2, r2), e2);
106
+ return n.shallow ? { ...e, ...r } : (Object.assign(e, r), e);
54
107
  }
55
- function k(e2) {
56
- return Array.isArray(e2);
108
+ function b(e) {
109
+ return Array.isArray(e);
57
110
  }
58
- function M(e2) {
59
- return "object" == typeof e2 && null !== e2 && !k(e2) && "[object Object]" === Object.prototype.toString.call(e2);
111
+ function O(e) {
112
+ return "object" == typeof e && null !== e && !b(e) && "[object Object]" === Object.prototype.toString.call(e);
60
113
  }
61
- var { version: R } = r();
62
- function V(e2 = {}) {
114
+ function C(e = {}) {
63
115
  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({ 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: `${t2}-${n2}-${r2}`, trigger: "test", entity: "entity", action: "action", timestamp: t2, timing: 3.14, group: n2, count: r2, version: { source: R, tagging: 1 }, source: { type: "web", id: "https://localhost:80", previous_id: "http://remotehost:9001" } }, e2, { merge: false });
65
- if (e2.name) {
66
- const [t3, n3] = (_a = e2.name.split(" ")) != null ? _a : [];
67
- t3 && n3 && (o.entity = t3, o.action = n3);
116
+ const t = e.timestamp || (/* @__PURE__ */ new Date()).setHours(0, 13, 37, 0), n = e.group || "gr0up", r = e.count || 1, o = y({ 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.2.0", tagging: 1 }, source: { type: "web", id: "https://localhost:80", previous_id: "http://remotehost:9001" } }, e, { merge: false });
117
+ if (e.name) {
118
+ const [t2, n2] = (_a = e.name.split(" ")) != null ? _a : [];
119
+ t2 && n2 && (o.entity = t2, o.action = n2);
68
120
  }
69
121
  return o;
70
122
  }
71
- function H(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 V({ ...{ "cart view": { data: { currency: "EUR", value: 2 * r2.data.price }, context: { shopping: ["cart", 0] }, globals: { pagegroup: "shop" }, nested: [{ entity: "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: [{ entity: "product", ...r2, 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", ...r2, 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.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, name: e2 });
123
+ function _(e = "entity action", t = {}) {
124
+ 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 } };
125
+ return C({ ...{ "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.elbwalker.com/", 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" } } }[e], ...t, name: e });
74
126
  }
75
127
 
76
128
  // src/examples/events.ts
77
129
  function Purchase() {
78
- const event = H("order complete");
130
+ const event = _("order complete");
79
131
  return [
80
132
  "track",
81
133
  "Purchase",
@@ -90,7 +142,7 @@ function Purchase() {
90
142
  ];
91
143
  }
92
144
  function AddToCart() {
93
- const event = H("product add");
145
+ const event = _("product add");
94
146
  return [
95
147
  "track",
96
148
  "AddToCart",
@@ -104,7 +156,7 @@ function AddToCart() {
104
156
  ];
105
157
  }
106
158
  function InitiateCheckout() {
107
- const event = H("cart view");
159
+ const event = _("cart view");
108
160
  return [
109
161
  "track",
110
162
  "InitiateCheckout",
@@ -121,7 +173,7 @@ function InitiateCheckout() {
121
173
  ];
122
174
  }
123
175
  function ViewContent() {
124
- const event = H("product view");
176
+ const event = _("product view");
125
177
  return [
126
178
  "track",
127
179
  "ViewContent",
@@ -154,7 +206,7 @@ var Purchase2 = {
154
206
  loop: [
155
207
  "nested",
156
208
  {
157
- condition: (entity) => M(entity) && entity.entity === "product",
209
+ condition: (entity) => O(entity) && entity.entity === "product",
158
210
  map: {
159
211
  id: "data.id",
160
212
  quantity: { key: "data.quantity", value: 1 }
@@ -201,7 +253,7 @@ var InitiateCheckout2 = {
201
253
  loop: [
202
254
  "nested",
203
255
  {
204
- condition: (entity) => M(entity) && entity.entity === "product",
256
+ condition: (entity) => O(entity) && entity.entity === "product",
205
257
  map: {
206
258
  id: "data.id",
207
259
  quantity: { key: "data.quantity", value: 1 }
@@ -244,6 +296,7 @@ var config = {
244
296
  };
245
297
  // Annotate the CommonJS export names for ESM import in node:
246
298
  0 && (module.exports = {
299
+ env,
247
300
  events,
248
301
  mapping
249
302
  });
@@ -4,6 +4,66 @@ var __export = (target, all) => {
4
4
  __defProp(target, name, { get: all[name], enumerable: true });
5
5
  };
6
6
 
7
+ // src/examples/env.ts
8
+ var env_exports = {};
9
+ __export(env_exports, {
10
+ init: () => init,
11
+ push: () => push
12
+ });
13
+ var noop = () => {
14
+ };
15
+ var init = {
16
+ // Environment before initialization (fbq not loaded yet)
17
+ window: {
18
+ fbq: void 0,
19
+ _fbq: void 0
20
+ },
21
+ document: {
22
+ createElement: () => ({
23
+ src: "",
24
+ async: false,
25
+ setAttribute: () => {
26
+ },
27
+ removeAttribute: () => {
28
+ }
29
+ }),
30
+ head: { appendChild: () => {
31
+ } }
32
+ }
33
+ };
34
+ var push = {
35
+ // Standard mock environment for testing
36
+ window: {
37
+ fbq: Object.assign(noop, {
38
+ // Add Meta Pixel specific properties
39
+ callMethod: noop,
40
+ queue: [],
41
+ push: noop,
42
+ loaded: true,
43
+ version: "2.0"
44
+ }),
45
+ _fbq: Object.assign(noop, {
46
+ callMethod: noop,
47
+ queue: [],
48
+ push: noop,
49
+ loaded: true,
50
+ version: "2.0"
51
+ })
52
+ },
53
+ document: {
54
+ createElement: () => ({
55
+ src: "",
56
+ async: false,
57
+ setAttribute: () => {
58
+ },
59
+ removeAttribute: () => {
60
+ }
61
+ }),
62
+ head: { appendChild: () => {
63
+ } }
64
+ }
65
+ };
66
+
7
67
  // src/examples/events.ts
8
68
  var events_exports = {};
9
69
  __export(events_exports, {
@@ -14,47 +74,38 @@ __export(events_exports, {
14
74
  });
15
75
 
16
76
  // ../../../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.1.2", 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;
77
+ var m = { merge: true, shallow: true, extend: true };
78
+ function y(e, t = {}, n = {}) {
79
+ n = { ...m, ...n };
80
+ const r = Object.entries(t).reduce((t2, [r2, o]) => {
81
+ const i = e[r2];
82
+ return n.merge && Array.isArray(i) && Array.isArray(o) ? t2[r2] = o.reduce((e2, t3) => e2.includes(t3) ? e2 : [...e2, t3], [...i]) : (n.extend || r2 in e) && (t2[r2] = o), t2;
31
83
  }, {});
32
- return n2.shallow ? { ...e2, ...r2 } : (Object.assign(e2, r2), e2);
84
+ return n.shallow ? { ...e, ...r } : (Object.assign(e, r), e);
33
85
  }
34
- function k(e2) {
35
- return Array.isArray(e2);
86
+ function b(e) {
87
+ return Array.isArray(e);
36
88
  }
37
- function M(e2) {
38
- return "object" == typeof e2 && null !== e2 && !k(e2) && "[object Object]" === Object.prototype.toString.call(e2);
89
+ function O(e) {
90
+ return "object" == typeof e && null !== e && !b(e) && "[object Object]" === Object.prototype.toString.call(e);
39
91
  }
40
- var { version: R } = r();
41
- function V(e2 = {}) {
92
+ function C(e = {}) {
42
93
  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({ 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: `${t2}-${n2}-${r2}`, trigger: "test", entity: "entity", action: "action", timestamp: t2, timing: 3.14, group: n2, count: r2, version: { source: R, tagging: 1 }, source: { type: "web", id: "https://localhost:80", previous_id: "http://remotehost:9001" } }, e2, { merge: false });
44
- if (e2.name) {
45
- const [t3, n3] = (_a = e2.name.split(" ")) != null ? _a : [];
46
- t3 && n3 && (o.entity = t3, o.action = n3);
94
+ const t = e.timestamp || (/* @__PURE__ */ new Date()).setHours(0, 13, 37, 0), n = e.group || "gr0up", r = e.count || 1, o = y({ 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.2.0", tagging: 1 }, source: { type: "web", id: "https://localhost:80", previous_id: "http://remotehost:9001" } }, e, { merge: false });
95
+ if (e.name) {
96
+ const [t2, n2] = (_a = e.name.split(" ")) != null ? _a : [];
97
+ t2 && n2 && (o.entity = t2, o.action = n2);
47
98
  }
48
99
  return o;
49
100
  }
50
- function H(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 V({ ...{ "cart view": { data: { currency: "EUR", value: 2 * r2.data.price }, context: { shopping: ["cart", 0] }, globals: { pagegroup: "shop" }, nested: [{ entity: "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: [{ entity: "product", ...r2, 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", ...r2, 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.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, name: e2 });
101
+ function _(e = "entity action", t = {}) {
102
+ 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 } };
103
+ return C({ ...{ "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.elbwalker.com/", 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" } } }[e], ...t, name: e });
53
104
  }
54
105
 
55
106
  // src/examples/events.ts
56
107
  function Purchase() {
57
- const event = H("order complete");
108
+ const event = _("order complete");
58
109
  return [
59
110
  "track",
60
111
  "Purchase",
@@ -69,7 +120,7 @@ function Purchase() {
69
120
  ];
70
121
  }
71
122
  function AddToCart() {
72
- const event = H("product add");
123
+ const event = _("product add");
73
124
  return [
74
125
  "track",
75
126
  "AddToCart",
@@ -83,7 +134,7 @@ function AddToCart() {
83
134
  ];
84
135
  }
85
136
  function InitiateCheckout() {
86
- const event = H("cart view");
137
+ const event = _("cart view");
87
138
  return [
88
139
  "track",
89
140
  "InitiateCheckout",
@@ -100,7 +151,7 @@ function InitiateCheckout() {
100
151
  ];
101
152
  }
102
153
  function ViewContent() {
103
- const event = H("product view");
154
+ const event = _("product view");
104
155
  return [
105
156
  "track",
106
157
  "ViewContent",
@@ -133,7 +184,7 @@ var Purchase2 = {
133
184
  loop: [
134
185
  "nested",
135
186
  {
136
- condition: (entity) => M(entity) && entity.entity === "product",
187
+ condition: (entity) => O(entity) && entity.entity === "product",
137
188
  map: {
138
189
  id: "data.id",
139
190
  quantity: { key: "data.quantity", value: 1 }
@@ -180,7 +231,7 @@ var InitiateCheckout2 = {
180
231
  loop: [
181
232
  "nested",
182
233
  {
183
- condition: (entity) => M(entity) && entity.entity === "product",
234
+ condition: (entity) => O(entity) && entity.entity === "product",
184
235
  map: {
185
236
  id: "data.id",
186
237
  quantity: { key: "data.quantity", value: 1 }
@@ -222,6 +273,7 @@ var config = {
222
273
  cart: { view: InitiateCheckout2 }
223
274
  };
224
275
  export {
276
+ env_exports as env,
225
277
  events_exports as events,
226
278
  mapping_exports as mapping
227
279
  };
@@ -1 +1 @@
1
- "use strict";var Destination=(()=>{var e,t,n=Object.defineProperty,a=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,r=Object.prototype.hasOwnProperty,i=(e,t)=>{for(var a in t)n(e,a,{get:t[a],enumerable:!0})},s={};i(s,{DestinationMeta:()=>h,default:()=>A,destinationMeta:()=>D,examples:()=>v});var c=Object.getOwnPropertyNames,d=(e={"package.json"(e,t){t.exports={name:"@walkeros/core",description:"Core types and platform-agnostic utilities for walkerOS",version:"0.1.2",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 t||(0,e[c(e)[0]])((t={exports:{}}).exports,t),t.exports}),u={merge:!0,shallow:!0,extend:!0};function p(e){return"object"==typeof e&&null!==e&&!function(e){return Array.isArray(e)}(e)&&"[object Object]"===Object.prototype.toString.call(e)}var{version:l}=d();function g(e={}){var t;const n=e.timestamp||(new Date).setHours(0,13,37,0),a=e.group||"gr0up",o=e.count||1,r=function(e,t={},n={}){n={...u,...n};const a=Object.entries(t).reduce((t,[a,o])=>{const r=e[a];return n.merge&&Array.isArray(r)&&Array.isArray(o)?t[a]=o.reduce((e,t)=>e.includes(t)?e:[...e,t],[...r]):(n.extend||a in e)&&(t[a]=o),t},{});return n.shallow?{...e,...a}:(Object.assign(e,a),e)}({name:"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:[{entity:"child",data:{is:"subordinated"},nested:[],context:{element:["child",0]}}],consent:{functional:!0},id:`${n}-${a}-${o}`,trigger:"test",entity:"entity",action:"action",timestamp:n,timing:3.14,group:a,count:o,version:{source:l,tagging:1},source:{type:"web",id:"https://localhost:80",previous_id:"http://remotehost:9001"}},e,{merge:!1});if(e.name){const[n,a]=null!=(t=e.name.split(" "))?t:[];n&&a&&(r.entity=n,r.action=a)}return r}function m(e="entity action",t={}){const n=t.timestamp||(new Date).setHours(0,13,37,0),a={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}};return g({...{"cart view":{data:{currency:"EUR",value:2*a.data.price},context:{shopping:["cart",0]},globals:{pagegroup:"shop"},nested:[{entity:"product",data:{...a.data,quantity:2},context:{shopping:["cart",0]},nested:[]}],trigger:"load"},"checkout view":{data:{step:"payment",currency:"EUR",value:a.data.price+o.data.price},context:{shopping:["checkout",0]},globals:{pagegroup:"shop"},nested:[{entity:"product",...a,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",...a,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.elbwalker.com/",search:"?foo=bar",hash:"#hash",id:"/docs/"},globals:{pagegroup:"docs"},trigger:"load"},"product add":{...a,context:{shopping:["intent",0]},globals:{pagegroup:"shop"},nested:[],trigger:"click"},"product view":{...a,context:{shopping:["detail",0]},globals:{pagegroup:"shop"},nested:[],trigger:"load"},"product visible":{data:{...a.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:n,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,name:e})}function y(e){const t={window:globalThis.window,document:globalThis.document};return e?{...t,...e}:t}var h={},v={};i(v,{events:()=>b,mapping:()=>q});var b={};function w(){const e=m("order complete");return["track","Purchase",{value:e.data.total,currency:"EUR",contents:e.nested.filter(e=>"product"===e.entity).map(e=>({id:e.data.id,quantity:1})),content_type:"product",num_items:2},{eventID:e.id}]}function f(){const e=m("product add");return["track","AddToCart",{currency:"EUR",value:e.data.price,contents:[{id:e.data.id,quantity:1}],content_type:"product"},{eventID:e.id}]}function k(){const e=m("cart view");return["track","InitiateCheckout",{currency:"EUR",value:e.data.value,contents:e.nested.filter(e=>"product"===e.entity).map(e=>({id:e.data.id,quantity:e.data.quantity})),num_items:e.nested.filter(e=>"product"===e.entity).length},{eventID:e.id}]}function x(){const e=m("product view");return["track","ViewContent",{currency:"EUR",value:e.data.price,contents:[{id:e.data.id,quantity:1}],content_type:"product"},{eventID:e.id}]}i(b,{AddToCart:()=>f,InitiateCheckout:()=>k,Purchase:()=>w,ViewContent:()=>x});var q={};i(q,{AddToCart:()=>j,InitiateCheckout:()=>_,Purchase:()=>C,ViewContent:()=>S,config:()=>E});var O,C={name:"Purchase",data:{map:{value:"data.total",currency:{value:"EUR"},contents:{loop:["nested",{condition:e=>p(e)&&"product"===e.entity,map:{id:"data.id",quantity:{key:"data.quantity",value:1}}}]},content_type:{value:"product"},num_items:{fn:e=>e.nested.filter(e=>"product"===e.entity).length}}}},j={name:"AddToCart",data:{map:{value:"data.price",currency:{value:"EUR"},contents:{set:[{map:{id:"data.id",quantity:{key:"data.quantity",value:1}}}]},content_type:{value:"product"}}}},_={name:"InitiateCheckout",data:{map:{value:"data.value",currency:{value:"EUR"},contents:{loop:["nested",{condition:e=>p(e)&&"product"===e.entity,map:{id:"data.id",quantity:{key:"data.quantity",value:1}}}]},num_items:{fn:e=>e.nested.filter(e=>"product"===e.entity).length}}}},S={name:"ViewContent",data:{map:{value:"data.price",currency:{value:"EUR"},content_type:{value:"product"},contents:{set:[{map:{id:"data.id",quantity:{key:"data.quantity",value:1}}}]}}}},E={order:{complete:C},product:{view:S,add:j},cart:{view:_}},D={type:"meta-pixel",config:{},init({config:e,env:t}){const{settings:n={},loadScript:a}=e,{pixelId:o}=n;if(a&&function(e,t="https://connect.facebook.net/en_US/fbevents.js"){const{document:n}=y(e),a=n.createElement("script");a.src=t,a.async=!0,n.head.appendChild(a)}(t),!o)return!1;!function(e){const{window:t}=y(e),n=t;if(n.fbq)return;const a=function(...e){a.callMethod?a.callMethod.apply(a,e):a.queue.push(e)};n.fbq=a,n._fbq||(n._fbq=a),a.push=a,a.loaded=!0,a.version="2.0",a.queue=[]}(t);const{window:r}=y(t);return(0,r.fbq)("init",o),e},push(e,{config:t,mapping:n={},data:a,env:o}){const{track:r,trackCustom:i}=n.settings||{},{window:s}=y(o),c=s.fbq;"page view"!==e.name||n.settings||(e.name="PageView");const d=r||i||e.name;c(i?"trackCustom":"track",String(d),p(a)?a:{},{eventID:e.id})}},A=D;return O=s,((e,t,i,s)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let c of o(t))r.call(e,c)||c===i||n(e,c,{get:()=>t[c],enumerable:!(s=a(t,c))||s.enumerable});return e})(n({},"__esModule",{value:!0}),O)})();
1
+ "use strict";var Destination=(()=>{var t=Object.defineProperty,e=Object.getOwnPropertyDescriptor,n=Object.getOwnPropertyNames,a=Object.prototype.hasOwnProperty,o=(e,n)=>{for(var a in n)t(e,a,{get:n[a],enumerable:!0})},i={};o(i,{DestinationMeta:()=>p,default:()=>D,destinationMeta:()=>j,examples:()=>l});var r={merge:!0,shallow:!0,extend:!0};function c(t){return"object"==typeof t&&null!==t&&!function(t){return Array.isArray(t)}(t)&&"[object Object]"===Object.prototype.toString.call(t)}function s(t={}){var e;const n=t.timestamp||(new Date).setHours(0,13,37,0),a=t.group||"gr0up",o=t.count||1,i=function(t,e={},n={}){n={...r,...n};const a=Object.entries(e).reduce((e,[a,o])=>{const i=t[a];return n.merge&&Array.isArray(i)&&Array.isArray(o)?e[a]=o.reduce((t,e)=>t.includes(e)?t:[...t,e],[...i]):(n.extend||a in t)&&(e[a]=o),e},{});return n.shallow?{...t,...a}:(Object.assign(t,a),t)}({name:"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:[{entity:"child",data:{is:"subordinated"},nested:[],context:{element:["child",0]}}],consent:{functional:!0},id:`${n}-${a}-${o}`,trigger:"test",entity:"entity",action:"action",timestamp:n,timing:3.14,group:a,count:o,version:{source:"0.2.0",tagging:1},source:{type:"web",id:"https://localhost:80",previous_id:"http://remotehost:9001"}},t,{merge:!1});if(t.name){const[n,a]=null!=(e=t.name.split(" "))?e:[];n&&a&&(i.entity=n,i.action=a)}return i}function d(t="entity action",e={}){const n=e.timestamp||(new Date).setHours(0,13,37,0),a={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}};return s({...{"cart view":{data:{currency:"EUR",value:2*a.data.price},context:{shopping:["cart",0]},globals:{pagegroup:"shop"},nested:[{entity:"product",data:{...a.data,quantity:2},context:{shopping:["cart",0]},nested:[]}],trigger:"load"},"checkout view":{data:{step:"payment",currency:"EUR",value:a.data.price+o.data.price},context:{shopping:["checkout",0]},globals:{pagegroup:"shop"},nested:[{entity:"product",...a,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",...a,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.elbwalker.com/",search:"?foo=bar",hash:"#hash",id:"/docs/"},globals:{pagegroup:"docs"},trigger:"load"},"product add":{...a,context:{shopping:["intent",0]},globals:{pagegroup:"shop"},nested:[],trigger:"click"},"product view":{...a,context:{shopping:["detail",0]},globals:{pagegroup:"shop"},nested:[],trigger:"load"},"product visible":{data:{...a.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:n,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"}}}[t],...e,name:t})}function u(t){return{window:"undefined"!=typeof window?window:globalThis.window,document:"undefined"!=typeof document?document:globalThis.document,...t}}var p={},l={};o(l,{env:()=>g,events:()=>v,mapping:()=>q});var g={};o(g,{init:()=>y,push:()=>h});var m=()=>{},y={window:{fbq:void 0,_fbq:void 0},document:{createElement:()=>({src:"",async:!1,setAttribute:()=>{},removeAttribute:()=>{}}),head:{appendChild:()=>{}}}},h={window:{fbq:Object.assign(m,{callMethod:m,queue:[],push:m,loaded:!0,version:"2.0"}),_fbq:Object.assign(m,{callMethod:m,queue:[],push:m,loaded:!0,version:"2.0"})},document:{createElement:()=>({src:"",async:!1,setAttribute:()=>{},removeAttribute:()=>{}}),head:{appendChild:()=>{}}}},v={};function b(){const t=d("order complete");return["track","Purchase",{value:t.data.total,currency:"EUR",contents:t.nested.filter(t=>"product"===t.entity).map(t=>({id:t.data.id,quantity:1})),content_type:"product",num_items:2},{eventID:t.id}]}function f(){const t=d("product add");return["track","AddToCart",{currency:"EUR",value:t.data.price,contents:[{id:t.data.id,quantity:1}],content_type:"product"},{eventID:t.id}]}function w(){const t=d("cart view");return["track","InitiateCheckout",{currency:"EUR",value:t.data.value,contents:t.nested.filter(t=>"product"===t.entity).map(t=>({id:t.data.id,quantity:t.data.quantity})),num_items:t.nested.filter(t=>"product"===t.entity).length},{eventID:t.id}]}function k(){const t=d("product view");return["track","ViewContent",{currency:"EUR",value:t.data.price,contents:[{id:t.data.id,quantity:1}],content_type:"product"},{eventID:t.id}]}o(v,{AddToCart:()=>f,InitiateCheckout:()=>w,Purchase:()=>b,ViewContent:()=>k});var q={};o(q,{AddToCart:()=>_,InitiateCheckout:()=>E,Purchase:()=>C,ViewContent:()=>A,config:()=>O});var x,C={name:"Purchase",data:{map:{value:"data.total",currency:{value:"EUR"},contents:{loop:["nested",{condition:t=>c(t)&&"product"===t.entity,map:{id:"data.id",quantity:{key:"data.quantity",value:1}}}]},content_type:{value:"product"},num_items:{fn:t=>t.nested.filter(t=>"product"===t.entity).length}}}},_={name:"AddToCart",data:{map:{value:"data.price",currency:{value:"EUR"},contents:{set:[{map:{id:"data.id",quantity:{key:"data.quantity",value:1}}}]},content_type:{value:"product"}}}},E={name:"InitiateCheckout",data:{map:{value:"data.value",currency:{value:"EUR"},contents:{loop:["nested",{condition:t=>c(t)&&"product"===t.entity,map:{id:"data.id",quantity:{key:"data.quantity",value:1}}}]},num_items:{fn:t=>t.nested.filter(t=>"product"===t.entity).length}}}},A={name:"ViewContent",data:{map:{value:"data.price",currency:{value:"EUR"},content_type:{value:"product"},contents:{set:[{map:{id:"data.id",quantity:{key:"data.quantity",value:1}}}]}}}},O={order:{complete:C},product:{view:A,add:_},cart:{view:E}},j={type:"meta-pixel",config:{},init({config:t,env:e}){const{settings:n={},loadScript:a}=t,{pixelId:o}=n;if(a&&function(t,e="https://connect.facebook.net/en_US/fbevents.js"){const{document:n}=u(t),a=n.createElement("script");a.src=e,a.async=!0,n.head.appendChild(a)}(e),!o)return!1;!function(t){const{window:e}=u(t),n=e;if(n.fbq)return;const a=function(...t){a.callMethod?a.callMethod.apply(a,t):a.queue.push(t)};n.fbq=a,n._fbq||(n._fbq=a),a.push=a,a.loaded=!0,a.version="2.0",a.queue=[]}(e);const{window:i}=u(e);return(0,i.fbq)("init",o),t},push(t,{config:e,mapping:n={},data:a,env:o}){const{track:i,trackCustom:r}=n.settings||{},{window:s}=u(o),d=s.fbq;"page view"!==t.name||n.settings||(t.name="PageView");const p=i||r||t.name;d(r?"trackCustom":"track",String(p),c(a)?a:{},{eventID:t.id})}},D=j;return x=i,((o,i,r,c)=>{if(i&&"object"==typeof i||"function"==typeof i)for(let s of n(i))a.call(o,s)||s===r||t(o,s,{get:()=>i[s],enumerable:!(c=e(i,s))||c.enumerable});return o})(t({},"__esModule",{value:!0}),x)})();
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { Mapping as Mapping$1 } from '@walkeros/core';
1
+ import { Destination as Destination$1, Mapping as Mapping$1 } from '@walkeros/core';
2
2
  import { DestinationWeb } from '@walkeros/web-core';
3
3
 
4
4
  declare global {
@@ -7,15 +7,6 @@ declare global {
7
7
  fbq?: facebook.Pixel.Event;
8
8
  }
9
9
  }
10
- interface MetaEnvironment {
11
- window: {
12
- fbq: facebook.Pixel.Event;
13
- _fbq?: facebook.Pixel.Event;
14
- };
15
- document: Document;
16
- }
17
- type Destination = DestinationWeb.Destination<Settings, Mapping>;
18
- type Config = DestinationWeb.Config<Settings, Mapping>;
19
10
  interface Settings {
20
11
  pixelId?: string;
21
12
  }
@@ -23,20 +14,45 @@ interface Mapping {
23
14
  track?: StandardEventNames;
24
15
  trackCustom?: string;
25
16
  }
17
+ interface Env extends DestinationWeb.Env {
18
+ window: {
19
+ fbq: facebook.Pixel.Event;
20
+ _fbq?: facebook.Pixel.Event;
21
+ };
22
+ document: {
23
+ createElement: (tagName: string) => Element;
24
+ head: {
25
+ appendChild: (node: unknown) => void;
26
+ };
27
+ };
28
+ }
29
+ type Types = Destination$1.Types<Settings, Mapping, Env>;
30
+ type Destination = DestinationWeb.Destination<Types>;
31
+ type Config = DestinationWeb.Config<Types>;
26
32
  type Rule = Mapping$1.Rule<Mapping>;
27
33
  type Rules = Mapping$1.Rules<Rule>;
28
34
  type StandardEventNames = 'PageView' | 'AddPaymentInfo' | 'AddToCart' | 'AddToWishlist' | 'CompleteRegistration' | 'Contact' | 'CustomizeProduct' | 'Donate' | 'FindLocation' | 'InitiateCheckout' | 'Lead' | 'Purchase' | 'Schedule' | 'Search' | 'StartTrial' | 'SubmitApplication' | 'Subscribe' | 'ViewContent' | string;
29
35
 
30
36
  type index$1_Config = Config;
31
37
  type index$1_Destination = Destination;
38
+ type index$1_Env = Env;
32
39
  type index$1_Mapping = Mapping;
33
- type index$1_MetaEnvironment = MetaEnvironment;
34
40
  type index$1_Rule = Rule;
35
41
  type index$1_Rules = Rules;
36
42
  type index$1_Settings = Settings;
37
43
  type index$1_StandardEventNames = StandardEventNames;
44
+ type index$1_Types = Types;
38
45
  declare namespace index$1 {
39
- export type { index$1_Config as Config, index$1_Destination as Destination, index$1_Mapping as Mapping, index$1_MetaEnvironment as MetaEnvironment, index$1_Rule as Rule, index$1_Rules as Rules, index$1_Settings as Settings, index$1_StandardEventNames as StandardEventNames };
46
+ export type { index$1_Config as Config, index$1_Destination as Destination, index$1_Env as Env, index$1_Mapping as Mapping, index$1_Rule as Rule, index$1_Rules as Rules, index$1_Settings as Settings, index$1_StandardEventNames as StandardEventNames, index$1_Types as Types };
47
+ }
48
+
49
+ declare const init: Env | undefined;
50
+ declare const push: Env;
51
+
52
+ declare const env_init: typeof init;
53
+ declare const env_push: typeof push;
54
+ declare namespace env {
55
+ export { env_init as init, env_push as push };
40
56
  }
41
57
 
42
58
  declare function Purchase$1(): unknown[];
@@ -74,10 +90,11 @@ declare namespace mapping {
74
90
  export { mapping_AddToCart as AddToCart, mapping_InitiateCheckout as InitiateCheckout, mapping_Purchase as Purchase, mapping_ViewContent as ViewContent, mapping_config as config };
75
91
  }
76
92
 
93
+ declare const index_env: typeof env;
77
94
  declare const index_events: typeof events;
78
95
  declare const index_mapping: typeof mapping;
79
96
  declare namespace index {
80
- export { index_events as events, index_mapping as mapping };
97
+ export { index_env as env, index_events as events, index_mapping as mapping };
81
98
  }
82
99
 
83
100
  declare const destinationMeta: Destination;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Mapping as Mapping$1 } from '@walkeros/core';
1
+ import { Destination as Destination$1, Mapping as Mapping$1 } from '@walkeros/core';
2
2
  import { DestinationWeb } from '@walkeros/web-core';
3
3
 
4
4
  declare global {
@@ -7,15 +7,6 @@ declare global {
7
7
  fbq?: facebook.Pixel.Event;
8
8
  }
9
9
  }
10
- interface MetaEnvironment {
11
- window: {
12
- fbq: facebook.Pixel.Event;
13
- _fbq?: facebook.Pixel.Event;
14
- };
15
- document: Document;
16
- }
17
- type Destination = DestinationWeb.Destination<Settings, Mapping>;
18
- type Config = DestinationWeb.Config<Settings, Mapping>;
19
10
  interface Settings {
20
11
  pixelId?: string;
21
12
  }
@@ -23,20 +14,45 @@ interface Mapping {
23
14
  track?: StandardEventNames;
24
15
  trackCustom?: string;
25
16
  }
17
+ interface Env extends DestinationWeb.Env {
18
+ window: {
19
+ fbq: facebook.Pixel.Event;
20
+ _fbq?: facebook.Pixel.Event;
21
+ };
22
+ document: {
23
+ createElement: (tagName: string) => Element;
24
+ head: {
25
+ appendChild: (node: unknown) => void;
26
+ };
27
+ };
28
+ }
29
+ type Types = Destination$1.Types<Settings, Mapping, Env>;
30
+ type Destination = DestinationWeb.Destination<Types>;
31
+ type Config = DestinationWeb.Config<Types>;
26
32
  type Rule = Mapping$1.Rule<Mapping>;
27
33
  type Rules = Mapping$1.Rules<Rule>;
28
34
  type StandardEventNames = 'PageView' | 'AddPaymentInfo' | 'AddToCart' | 'AddToWishlist' | 'CompleteRegistration' | 'Contact' | 'CustomizeProduct' | 'Donate' | 'FindLocation' | 'InitiateCheckout' | 'Lead' | 'Purchase' | 'Schedule' | 'Search' | 'StartTrial' | 'SubmitApplication' | 'Subscribe' | 'ViewContent' | string;
29
35
 
30
36
  type index$1_Config = Config;
31
37
  type index$1_Destination = Destination;
38
+ type index$1_Env = Env;
32
39
  type index$1_Mapping = Mapping;
33
- type index$1_MetaEnvironment = MetaEnvironment;
34
40
  type index$1_Rule = Rule;
35
41
  type index$1_Rules = Rules;
36
42
  type index$1_Settings = Settings;
37
43
  type index$1_StandardEventNames = StandardEventNames;
44
+ type index$1_Types = Types;
38
45
  declare namespace index$1 {
39
- export type { index$1_Config as Config, index$1_Destination as Destination, index$1_Mapping as Mapping, index$1_MetaEnvironment as MetaEnvironment, index$1_Rule as Rule, index$1_Rules as Rules, index$1_Settings as Settings, index$1_StandardEventNames as StandardEventNames };
46
+ export type { index$1_Config as Config, index$1_Destination as Destination, index$1_Env as Env, index$1_Mapping as Mapping, index$1_Rule as Rule, index$1_Rules as Rules, index$1_Settings as Settings, index$1_StandardEventNames as StandardEventNames, index$1_Types as Types };
47
+ }
48
+
49
+ declare const init: Env | undefined;
50
+ declare const push: Env;
51
+
52
+ declare const env_init: typeof init;
53
+ declare const env_push: typeof push;
54
+ declare namespace env {
55
+ export { env_init as init, env_push as push };
40
56
  }
41
57
 
42
58
  declare function Purchase$1(): unknown[];
@@ -74,10 +90,11 @@ declare namespace mapping {
74
90
  export { mapping_AddToCart as AddToCart, mapping_InitiateCheckout as InitiateCheckout, mapping_Purchase as Purchase, mapping_ViewContent as ViewContent, mapping_config as config };
75
91
  }
76
92
 
93
+ declare const index_env: typeof env;
77
94
  declare const index_events: typeof events;
78
95
  declare const index_mapping: typeof mapping;
79
96
  declare namespace index {
80
- export { index_events as events, index_mapping as mapping };
97
+ export { index_env as env, index_events as events, index_mapping as mapping };
81
98
  }
82
99
 
83
100
  declare const destinationMeta: Destination;
package/dist/index.es5.js CHANGED
@@ -1 +1 @@
1
- "use strict";function _array_like_to_array(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}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 _define_property(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}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 r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,a=[],i=!0,c=!1;try{for(r=r.call(e);!(i=(n=r.next()).done)&&(a.push(n.value),!t||a.length!==t);i=!0);}catch(e){c=!0,o=e}finally{try{i||null==r.return||r.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 r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),n.forEach(function(t){_define_property(e,t,r[t])})}return e}function ownKeys(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function _object_spread_props(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):ownKeys(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}),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 r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(r):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?_array_like_to_array(e,t):void 0}}var Destination=function(){var e,t,r=function(e){return"object"==(void 0===e?"undefined":_type_of(e))&&null!==e&&!function(e){return Array.isArray(e)}(e)&&"[object Object]"===Object.prototype.toString.call(e)},n=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.timestamp||(new Date).setHours(0,13,37,0),r=e.group||"gr0up",n=e.count||1,o=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};r=_object_spread({},m,r);var n=Object.entries(t).reduce(function(t,n){var o=_sliced_to_array(n,2),a=o[0],i=o[1],c=e[a];return r.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)):(r.extend||a in e)&&(t[a]=i),t},{});return r.shallow?_object_spread({},e,n):(Object.assign(e,n),e)}({name:"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:[{entity:"child",data:{is:"subordinated"},nested:[],context:{element:["child",0]}}],consent:{functional:!0},id:"".concat(t,"-").concat(r,"-").concat(n),trigger:"test",entity:"entity",action:"action",timestamp:t,timing:3.14,group:r,count:n,version:{source:v,tagging:1},source:{type:"web",id:"https://localhost:80",previous_id:"http://remotehost:9001"}},e,{merge:!1});if(e.name){var a,i=_sliced_to_array(null!==(a=e.name.split(" "))&&void 0!==a?a:[],2),c=i[0],u=i[1];c&&u&&(o.entity=c,o.action=u)}return o},o=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"entity action",t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=t.timestamp||(new Date).setHours(0,13,37,0),o={data:{id:"ers",name:"Everyday Ruck Snack",color:"black",size:"l",price:420}},a={data:{id:"cc",name:"Cool Cap",size:"one size",price:42}};return n(_object_spread_props(_object_spread({},{"cart view":{data:{currency:"EUR",value:2*o.data.price},context:{shopping:["cart",0]},globals:{pagegroup:"shop"},nested:[{entity:"product",data:_object_spread_props(_object_spread({},o.data),{quantity:2}),context:{shopping:["cart",0]},nested:[]}],trigger:"load"},"checkout view":{data:{step:"payment",currency:"EUR",value:o.data.price+a.data.price},context:{shopping:["checkout",0]},globals:{pagegroup:"shop"},nested:[_object_spread_props(_object_spread({entity:"product"},o),{context:{shopping:["checkout",0]},nested:[]}),_object_spread_props(_object_spread({entity:"product"},a),{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:[_object_spread_props(_object_spread({entity:"product"},o),{context:{shopping:["complete",0]},nested:[]}),_object_spread_props(_object_spread({entity:"product"},a),{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.elbwalker.com/",search:"?foo=bar",hash:"#hash",id:"/docs/"},globals:{pagegroup:"docs"},trigger:"load"},"product add":_object_spread_props(_object_spread({},o),{context:{shopping:["intent",0]},globals:{pagegroup:"shop"},nested:[],trigger:"click"}),"product view":_object_spread_props(_object_spread({},o),{context:{shopping:["detail",0]},globals:{pagegroup:"shop"},nested:[],trigger:"load"}),"product visible":{data:_object_spread_props(_object_spread({},o.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:r,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),{name:e}))},a=function(e){var t={window:globalThis.window,document:globalThis.document};return e?_object_spread({},t,e):t},i=function(){var e=o("order complete");return["track","Purchase",{value:e.data.total,currency:"EUR",contents:e.nested.filter(function(e){return"product"===e.entity}).map(function(e){return{id:e.data.id,quantity:1}}),content_type:"product",num_items:2},{eventID:e.id}]},c=function(){var e=o("product add");return["track","AddToCart",{currency:"EUR",value:e.data.price,contents:[{id:e.data.id,quantity:1}],content_type:"product"},{eventID:e.id}]},u=function(){var e=o("cart view");return["track","InitiateCheckout",{currency:"EUR",value:e.data.value,contents:e.nested.filter(function(e){return"product"===e.entity}).map(function(e){return{id:e.data.id,quantity:e.data.quantity}}),num_items:e.nested.filter(function(e){return"product"===e.entity}).length},{eventID:e.id}]},s=function(){var e=o("product view");return["track","ViewContent",{currency:"EUR",value:e.data.price,contents:[{id:e.data.id,quantity:1}],content_type:"product"},{eventID:e.id}]},d=Object.defineProperty,p=Object.getOwnPropertyDescriptor,l=Object.getOwnPropertyNames,y=Object.prototype.hasOwnProperty,_=function(e,t){for(var r in t)d(e,r,{get:t[r],enumerable:!0})},f={};_(f,{DestinationMeta:function(){return h},default:function(){return E},destinationMeta:function(){return C},examples:function(){return w}});var b=Object.getOwnPropertyNames,g=(e={"package.json":function(e,t){t.exports={name:"@walkeros/core",description:"Core types and platform-agnostic utilities for walkerOS",version:"0.1.2",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 t||(0,e[b(e)[0]])((t={exports:{}}).exports,t),t.exports}),m={merge:!0,shallow:!0,extend:!0},v=g().version,h={},w={};_(w,{events:function(){return j},mapping:function(){return k}});var j={};_(j,{AddToCart:function(){return c},InitiateCheckout:function(){return u},Purchase:function(){return i},ViewContent:function(){return s}});var k={};_(k,{AddToCart:function(){return S},InitiateCheckout:function(){return q},Purchase:function(){return x},ViewContent:function(){return A},config:function(){return P}});var O,x={name:"Purchase",data:{map:{value:"data.total",currency:{value:"EUR"},contents:{loop:["nested",{condition:function(e){return r(e)&&"product"===e.entity},map:{id:"data.id",quantity:{key:"data.quantity",value:1}}}]},content_type:{value:"product"},num_items:{fn:function(e){return e.nested.filter(function(e){return"product"===e.entity}).length}}}}},S={name:"AddToCart",data:{map:{value:"data.price",currency:{value:"EUR"},contents:{set:[{map:{id:"data.id",quantity:{key:"data.quantity",value:1}}}]},content_type:{value:"product"}}}},q={name:"InitiateCheckout",data:{map:{value:"data.value",currency:{value:"EUR"},contents:{loop:["nested",{condition:function(e){return r(e)&&"product"===e.entity},map:{id:"data.id",quantity:{key:"data.quantity",value:1}}}]},num_items:{fn:function(e){return e.nested.filter(function(e){return"product"===e.entity}).length}}}}},A={name:"ViewContent",data:{map:{value:"data.price",currency:{value:"EUR"},content_type:{value:"product"},contents:{set:[{map:{id:"data.id",quantity:{key:"data.quantity",value:1}}}]}}}},P={order:{complete:x},product:{view:A,add:S},cart:{view:q}},C={type:"meta-pixel",config:{},init:function(e){var t=e.config,r=e.env,n=t.settings,o=void 0===n?{}:n,i=t.loadScript,c=o.pixelId;return i&&function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"https://connect.facebook.net/en_US/fbevents.js",r=a(e).document,n=r.createElement("script");n.src=t,n.async=!0,r.head.appendChild(n)}(r),!!c&&(function(e){var t=a(e).window;if(!t.fbq){var r=function(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];r.callMethod?r.callMethod.apply(r,t):r.queue.push(t)};t.fbq=r,t._fbq||(t._fbq=r),r.push=r,r.loaded=!0,r.version="2.0",r.queue=[]}}(r),(0,a(r).window.fbq)("init",c),t)},push:function(e,t){t.config;var n=t.mapping,o=void 0===n?{}:n,i=t.data,c=t.env,u=o.settings||{},s=u.track,d=u.trackCustom,p=a(c).window.fbq;"page view"!==e.name||o.settings||(e.name="PageView");var l=s||d||e.name;p(d?"trackCustom":"track",String(l),r(i)?i:{},{eventID:e.id})}},E=C;return O=f,function(e,t,r,n){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;y.call(e,o)||o===r||d(e,o,{get:function(){return t[o]},enumerable:!(n=p(t,o))||n.enumerable})},s=l(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}(d({},"__esModule",{value:!0}),O)}();
1
+ "use strict";function _array_like_to_array(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function _array_with_holes(t){if(Array.isArray(t))return t}function _array_without_holes(t){if(Array.isArray(t))return _array_like_to_array(t)}function _define_property(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function _iterable_to_array(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}function _iterable_to_array_limit(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var r,o,a=[],i=!0,c=!1;try{for(n=n.call(t);!(i=(r=n.next()).done)&&(a.push(r.value),!e||a.length!==e);i=!0);}catch(t){c=!0,o=t}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(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(t){return Object.getOwnPropertyDescriptor(n,t).enumerable}))),r.forEach(function(e){_define_property(t,e,n[e])})}return t}function ownKeys(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,r)}return n}function _object_spread_props(t,e){return e=null!=e?e:{},Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(e)):ownKeys(Object(e)).forEach(function(n){Object.defineProperty(t,n,Object.getOwnPropertyDescriptor(e,n))}),t}function _sliced_to_array(t,e){return _array_with_holes(t)||_iterable_to_array_limit(t,e)||_unsupported_iterable_to_array(t,e)||_non_iterable_rest()}function _to_consumable_array(t){return _array_without_holes(t)||_iterable_to_array(t)||_unsupported_iterable_to_array(t)||_non_iterable_spread()}function _type_of(t){return t&&"undefined"!=typeof Symbol&&t.constructor===Symbol?"symbol":typeof t}function _unsupported_iterable_to_array(t,e){if(t){if("string"==typeof t)return _array_like_to_array(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.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(t,e):void 0}}var Destination=function(){var t=function(t){return"object"==(void 0===t?"undefined":_type_of(t))&&null!==t&&!function(t){return Array.isArray(t)}(t)&&"[object Object]"===Object.prototype.toString.call(t)},e=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=t.timestamp||(new Date).setHours(0,13,37,0),n=t.group||"gr0up",r=t.count||1,o=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};n=_object_spread({},_,n);var r=Object.entries(e).reduce(function(e,r){var o=_sliced_to_array(r,2),a=o[0],i=o[1],c=t[a];return n.merge&&Array.isArray(c)&&Array.isArray(i)?e[a]=i.reduce(function(t,e){return t.includes(e)?t:_to_consumable_array(t).concat([e])},_to_consumable_array(c)):(n.extend||a in t)&&(e[a]=i),e},{});return n.shallow?_object_spread({},t,r):(Object.assign(t,r),t)}({name:"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:[{entity:"child",data:{is:"subordinated"},nested:[],context:{element:["child",0]}}],consent:{functional:!0},id:"".concat(e,"-").concat(n,"-").concat(r),trigger:"test",entity:"entity",action:"action",timestamp:e,timing:3.14,group:n,count:r,version:{source:"0.2.0",tagging:1},source:{type:"web",id:"https://localhost:80",previous_id:"http://remotehost:9001"}},t,{merge:!1});if(t.name){var a,i=_sliced_to_array(null!==(a=t.name.split(" "))&&void 0!==a?a:[],2),c=i[0],u=i[1];c&&u&&(o.entity=c,o.action=u)}return o},n=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"entity action",n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=n.timestamp||(new Date).setHours(0,13,37,0),o={data:{id:"ers",name:"Everyday Ruck Snack",color:"black",size:"l",price:420}},a={data:{id:"cc",name:"Cool Cap",size:"one size",price:42}};return e(_object_spread_props(_object_spread({},{"cart view":{data:{currency:"EUR",value:2*o.data.price},context:{shopping:["cart",0]},globals:{pagegroup:"shop"},nested:[{entity:"product",data:_object_spread_props(_object_spread({},o.data),{quantity:2}),context:{shopping:["cart",0]},nested:[]}],trigger:"load"},"checkout view":{data:{step:"payment",currency:"EUR",value:o.data.price+a.data.price},context:{shopping:["checkout",0]},globals:{pagegroup:"shop"},nested:[_object_spread_props(_object_spread({entity:"product"},o),{context:{shopping:["checkout",0]},nested:[]}),_object_spread_props(_object_spread({entity:"product"},a),{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:[_object_spread_props(_object_spread({entity:"product"},o),{context:{shopping:["complete",0]},nested:[]}),_object_spread_props(_object_spread({entity:"product"},a),{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.elbwalker.com/",search:"?foo=bar",hash:"#hash",id:"/docs/"},globals:{pagegroup:"docs"},trigger:"load"},"product add":_object_spread_props(_object_spread({},o),{context:{shopping:["intent",0]},globals:{pagegroup:"shop"},nested:[],trigger:"click"}),"product view":_object_spread_props(_object_spread({},o),{context:{shopping:["detail",0]},globals:{pagegroup:"shop"},nested:[],trigger:"load"}),"product visible":{data:_object_spread_props(_object_spread({},o.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:r,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"}}}[t],n),{name:t}))},r=function(t){return _object_spread({window:"undefined"!=typeof window?window:globalThis.window,document:"undefined"!=typeof document?document:globalThis.document},t)},o=function(){var t=n("order complete");return["track","Purchase",{value:t.data.total,currency:"EUR",contents:t.nested.filter(function(t){return"product"===t.entity}).map(function(t){return{id:t.data.id,quantity:1}}),content_type:"product",num_items:2},{eventID:t.id}]},a=function(){var t=n("product add");return["track","AddToCart",{currency:"EUR",value:t.data.price,contents:[{id:t.data.id,quantity:1}],content_type:"product"},{eventID:t.id}]},i=function(){var t=n("cart view");return["track","InitiateCheckout",{currency:"EUR",value:t.data.value,contents:t.nested.filter(function(t){return"product"===t.entity}).map(function(t){return{id:t.data.id,quantity:t.data.quantity}}),num_items:t.nested.filter(function(t){return"product"===t.entity}).length},{eventID:t.id}]},c=function(){var t=n("product view");return["track","ViewContent",{currency:"EUR",value:t.data.price,contents:[{id:t.data.id,quantity:1}],content_type:"product"},{eventID:t.id}]},u=Object.defineProperty,s=Object.getOwnPropertyDescriptor,d=Object.getOwnPropertyNames,p=Object.prototype.hasOwnProperty,l=function(t,e){for(var n in e)u(t,n,{get:e[n],enumerable:!0})},y={};l(y,{DestinationMeta:function(){return f},default:function(){return E},destinationMeta:function(){return C},examples:function(){return b}});var _={merge:!0,shallow:!0,extend:!0},f={},b={};l(b,{env:function(){return g},events:function(){return w},mapping:function(){return j}});var g={};l(g,{init:function(){return v},push:function(){return h}});var m=function(){},v={window:{fbq:void 0,_fbq:void 0},document:{createElement:function(){return{src:"",async:!1,setAttribute:function(){},removeAttribute:function(){}}},head:{appendChild:function(){}}}},h={window:{fbq:Object.assign(m,{callMethod:m,queue:[],push:m,loaded:!0,version:"2.0"}),_fbq:Object.assign(m,{callMethod:m,queue:[],push:m,loaded:!0,version:"2.0"})},document:{createElement:function(){return{src:"",async:!1,setAttribute:function(){},removeAttribute:function(){}}},head:{appendChild:function(){}}}},w={};l(w,{AddToCart:function(){return a},InitiateCheckout:function(){return i},Purchase:function(){return o},ViewContent:function(){return c}});var j={};l(j,{AddToCart:function(){return q},InitiateCheckout:function(){return x},Purchase:function(){return k},ViewContent:function(){return S},config:function(){return A}});var O,k={name:"Purchase",data:{map:{value:"data.total",currency:{value:"EUR"},contents:{loop:["nested",{condition:function(e){return t(e)&&"product"===e.entity},map:{id:"data.id",quantity:{key:"data.quantity",value:1}}}]},content_type:{value:"product"},num_items:{fn:function(t){return t.nested.filter(function(t){return"product"===t.entity}).length}}}}},q={name:"AddToCart",data:{map:{value:"data.price",currency:{value:"EUR"},contents:{set:[{map:{id:"data.id",quantity:{key:"data.quantity",value:1}}}]},content_type:{value:"product"}}}},x={name:"InitiateCheckout",data:{map:{value:"data.value",currency:{value:"EUR"},contents:{loop:["nested",{condition:function(e){return t(e)&&"product"===e.entity},map:{id:"data.id",quantity:{key:"data.quantity",value:1}}}]},num_items:{fn:function(t){return t.nested.filter(function(t){return"product"===t.entity}).length}}}}},S={name:"ViewContent",data:{map:{value:"data.price",currency:{value:"EUR"},content_type:{value:"product"},contents:{set:[{map:{id:"data.id",quantity:{key:"data.quantity",value:1}}}]}}}},A={order:{complete:k},product:{view:S,add:q},cart:{view:x}},C={type:"meta-pixel",config:{},init:function(t){var e=t.config,n=t.env,o=e.settings,a=void 0===o?{}:o,i=e.loadScript,c=a.pixelId;return i&&function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"https://connect.facebook.net/en_US/fbevents.js",n=r(t).document,o=n.createElement("script");o.src=e,o.async=!0,n.head.appendChild(o)}(n),!!c&&(function(t){var e=r(t).window;if(!e.fbq){var n=function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];n.callMethod?n.callMethod.apply(n,e):n.queue.push(e)};e.fbq=n,e._fbq||(e._fbq=n),n.push=n,n.loaded=!0,n.version="2.0",n.queue=[]}}(n),(0,r(n).window.fbq)("init",c),e)},push:function(e,n){n.config;var o=n.mapping,a=void 0===o?{}:o,i=n.data,c=n.env,u=a.settings||{},s=u.track,d=u.trackCustom,p=r(c).window.fbq;"page view"!==e.name||a.settings||(e.name="PageView");var l=s||d||e.name;p(d?"trackCustom":"track",String(l),t(i)?i:{},{eventID:e.id})}},E=C;return O=y,function(t,e,n,r){if(e&&"object"===(void 0===e?"undefined":_type_of(e))||"function"==typeof e){var o=!0,a=!1,i=void 0;try{for(var c,l=function(){var o=c.value;p.call(t,o)||o===n||u(t,o,{get:function(){return e[o]},enumerable:!(r=s(e,o))||r.enumerable})},y=d(e)[Symbol.iterator]();!(o=(c=y.next()).done);o=!0)l()}catch(t){a=!0,i=t}finally{try{o||null==y.return||y.return()}finally{if(a)throw i}}}return t}(u({},"__esModule",{value:!0}),O)}();
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var e,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,a=Object.getOwnPropertyNames,o=Object.prototype.hasOwnProperty,r=(e,n)=>{for(var a in n)t(e,a,{get:n[a],enumerable:!0})},i={};r(i,{DestinationMeta:()=>b,default:()=>R,destinationMeta:()=>D,examples:()=>w}),module.exports=(e=i,((e,r,i,s)=>{if(r&&"object"==typeof r||"function"==typeof r)for(let c of a(r))o.call(e,c)||c===i||t(e,c,{get:()=>r[c],enumerable:!(s=n(r,c))||s.enumerable});return e})(t({},"__esModule",{value:!0}),e));var s,c,d=require("@walkeros/web-core");var u=Object.getOwnPropertyNames,p=(s={"package.json"(e,t){t.exports={name:"@walkeros/core",description:"Core types and platform-agnostic utilities for walkerOS",version:"0.1.2",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 c||(0,s[u(s)[0]])((c={exports:{}}).exports,c),c.exports}),l={merge:!0,shallow:!0,extend:!0};function g(e){return"object"==typeof e&&null!==e&&!function(e){return Array.isArray(e)}(e)&&"[object Object]"===Object.prototype.toString.call(e)}var{version:m}=p();function y(e={}){var t;const n=e.timestamp||(new Date).setHours(0,13,37,0),a=e.group||"gr0up",o=e.count||1,r=function(e,t={},n={}){n={...l,...n};const a=Object.entries(t).reduce((t,[a,o])=>{const r=e[a];return n.merge&&Array.isArray(r)&&Array.isArray(o)?t[a]=o.reduce((e,t)=>e.includes(t)?e:[...e,t],[...r]):(n.extend||a in e)&&(t[a]=o),t},{});return n.shallow?{...e,...a}:(Object.assign(e,a),e)}({name:"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:[{entity:"child",data:{is:"subordinated"},nested:[],context:{element:["child",0]}}],consent:{functional:!0},id:`${n}-${a}-${o}`,trigger:"test",entity:"entity",action:"action",timestamp:n,timing:3.14,group:a,count:o,version:{source:m,tagging:1},source:{type:"web",id:"https://localhost:80",previous_id:"http://remotehost:9001"}},e,{merge:!1});if(e.name){const[n,a]=null!=(t=e.name.split(" "))?t:[];n&&a&&(r.entity=n,r.action=a)}return r}function h(e="entity action",t={}){const n=t.timestamp||(new Date).setHours(0,13,37,0),a={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}};return y({...{"cart view":{data:{currency:"EUR",value:2*a.data.price},context:{shopping:["cart",0]},globals:{pagegroup:"shop"},nested:[{entity:"product",data:{...a.data,quantity:2},context:{shopping:["cart",0]},nested:[]}],trigger:"load"},"checkout view":{data:{step:"payment",currency:"EUR",value:a.data.price+o.data.price},context:{shopping:["checkout",0]},globals:{pagegroup:"shop"},nested:[{entity:"product",...a,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",...a,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.elbwalker.com/",search:"?foo=bar",hash:"#hash",id:"/docs/"},globals:{pagegroup:"docs"},trigger:"load"},"product add":{...a,context:{shopping:["intent",0]},globals:{pagegroup:"shop"},nested:[],trigger:"click"},"product view":{...a,context:{shopping:["detail",0]},globals:{pagegroup:"shop"},nested:[],trigger:"load"},"product visible":{data:{...a.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:n,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,name:e})}var v=require("@walkeros/web-core"),b={},w={};r(w,{events:()=>f,mapping:()=>C});var f={};function k(){const e=h("order complete");return["track","Purchase",{value:e.data.total,currency:"EUR",contents:e.nested.filter(e=>"product"===e.entity).map(e=>({id:e.data.id,quantity:1})),content_type:"product",num_items:2},{eventID:e.id}]}function x(){const e=h("product add");return["track","AddToCart",{currency:"EUR",value:e.data.price,contents:[{id:e.data.id,quantity:1}],content_type:"product"},{eventID:e.id}]}function q(){const e=h("cart view");return["track","InitiateCheckout",{currency:"EUR",value:e.data.value,contents:e.nested.filter(e=>"product"===e.entity).map(e=>({id:e.data.id,quantity:e.data.quantity})),num_items:e.nested.filter(e=>"product"===e.entity).length},{eventID:e.id}]}function O(){const e=h("product view");return["track","ViewContent",{currency:"EUR",value:e.data.price,contents:[{id:e.data.id,quantity:1}],content_type:"product"},{eventID:e.id}]}r(f,{AddToCart:()=>x,InitiateCheckout:()=>q,Purchase:()=>k,ViewContent:()=>O});var C={};r(C,{AddToCart:()=>j,InitiateCheckout:()=>_,Purchase:()=>E,ViewContent:()=>S,config:()=>A});var E={name:"Purchase",data:{map:{value:"data.total",currency:{value:"EUR"},contents:{loop:["nested",{condition:e=>g(e)&&"product"===e.entity,map:{id:"data.id",quantity:{key:"data.quantity",value:1}}}]},content_type:{value:"product"},num_items:{fn:e=>e.nested.filter(e=>"product"===e.entity).length}}}},j={name:"AddToCart",data:{map:{value:"data.price",currency:{value:"EUR"},contents:{set:[{map:{id:"data.id",quantity:{key:"data.quantity",value:1}}}]},content_type:{value:"product"}}}},_={name:"InitiateCheckout",data:{map:{value:"data.value",currency:{value:"EUR"},contents:{loop:["nested",{condition:e=>g(e)&&"product"===e.entity,map:{id:"data.id",quantity:{key:"data.quantity",value:1}}}]},num_items:{fn:e=>e.nested.filter(e=>"product"===e.entity).length}}}},S={name:"ViewContent",data:{map:{value:"data.price",currency:{value:"EUR"},content_type:{value:"product"},contents:{set:[{map:{id:"data.id",quantity:{key:"data.quantity",value:1}}}]}}}},A={order:{complete:E},product:{view:S,add:j},cart:{view:_}},D={type:"meta-pixel",config:{},init({config:e,env:t}){const{settings:n={},loadScript:a}=e,{pixelId:o}=n;if(a&&function(e,t="https://connect.facebook.net/en_US/fbevents.js"){const{document:n}=(0,d.getEnvironment)(e),a=n.createElement("script");a.src=t,a.async=!0,n.head.appendChild(a)}(t),!o)return!1;!function(e){const{window:t}=(0,d.getEnvironment)(e),n=t;if(n.fbq)return;const a=function(...e){a.callMethod?a.callMethod.apply(a,e):a.queue.push(e)};n.fbq=a,n._fbq||(n._fbq=a),a.push=a,a.loaded=!0,a.version="2.0",a.queue=[]}(t);const{window:r}=(0,v.getEnvironment)(t);return(0,r.fbq)("init",o),e},push(e,{config:t,mapping:n={},data:a,env:o}){const{track:r,trackCustom:i}=n.settings||{},{window:s}=(0,v.getEnvironment)(o),c=s.fbq;"page view"!==e.name||n.settings||(e.name="PageView");const d=r||i||e.name;c(i?"trackCustom":"track",String(d),g(a)?a:{},{eventID:e.id})}},R=D;//# sourceMappingURL=index.js.map
1
+ "use strict";var e,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,a=Object.getOwnPropertyNames,o=Object.prototype.hasOwnProperty,r=(e,n)=>{for(var a in n)t(e,a,{get:n[a],enumerable:!0})},i={};r(i,{DestinationMeta:()=>g,default:()=>U,destinationMeta:()=>R,examples:()=>m}),module.exports=(e=i,((e,r,i,c)=>{if(r&&"object"==typeof r||"function"==typeof r)for(let s of a(r))o.call(e,s)||s===i||t(e,s,{get:()=>r[s],enumerable:!(c=n(r,s))||c.enumerable});return e})(t({},"__esModule",{value:!0}),e));var c=require("@walkeros/web-core");var s={merge:!0,shallow:!0,extend:!0};function d(e){return"object"==typeof e&&null!==e&&!function(e){return Array.isArray(e)}(e)&&"[object Object]"===Object.prototype.toString.call(e)}function u(e={}){var t;const n=e.timestamp||(new Date).setHours(0,13,37,0),a=e.group||"gr0up",o=e.count||1,r=function(e,t={},n={}){n={...s,...n};const a=Object.entries(t).reduce((t,[a,o])=>{const r=e[a];return n.merge&&Array.isArray(r)&&Array.isArray(o)?t[a]=o.reduce((e,t)=>e.includes(t)?e:[...e,t],[...r]):(n.extend||a in e)&&(t[a]=o),t},{});return n.shallow?{...e,...a}:(Object.assign(e,a),e)}({name:"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:[{entity:"child",data:{is:"subordinated"},nested:[],context:{element:["child",0]}}],consent:{functional:!0},id:`${n}-${a}-${o}`,trigger:"test",entity:"entity",action:"action",timestamp:n,timing:3.14,group:a,count:o,version:{source:"0.2.0",tagging:1},source:{type:"web",id:"https://localhost:80",previous_id:"http://remotehost:9001"}},e,{merge:!1});if(e.name){const[n,a]=null!=(t=e.name.split(" "))?t:[];n&&a&&(r.entity=n,r.action=a)}return r}function p(e="entity action",t={}){const n=t.timestamp||(new Date).setHours(0,13,37,0),a={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}};return u({...{"cart view":{data:{currency:"EUR",value:2*a.data.price},context:{shopping:["cart",0]},globals:{pagegroup:"shop"},nested:[{entity:"product",data:{...a.data,quantity:2},context:{shopping:["cart",0]},nested:[]}],trigger:"load"},"checkout view":{data:{step:"payment",currency:"EUR",value:a.data.price+o.data.price},context:{shopping:["checkout",0]},globals:{pagegroup:"shop"},nested:[{entity:"product",...a,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",...a,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.elbwalker.com/",search:"?foo=bar",hash:"#hash",id:"/docs/"},globals:{pagegroup:"docs"},trigger:"load"},"product add":{...a,context:{shopping:["intent",0]},globals:{pagegroup:"shop"},nested:[],trigger:"click"},"product view":{...a,context:{shopping:["detail",0]},globals:{pagegroup:"shop"},nested:[],trigger:"load"},"product visible":{data:{...a.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:n,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,name:e})}var l=require("@walkeros/web-core"),g={},m={};r(m,{env:()=>y,events:()=>f,mapping:()=>E});var y={};r(y,{init:()=>h,push:()=>b});var v=()=>{},h={window:{fbq:void 0,_fbq:void 0},document:{createElement:()=>({src:"",async:!1,setAttribute:()=>{},removeAttribute:()=>{}}),head:{appendChild:()=>{}}}},b={window:{fbq:Object.assign(v,{callMethod:v,queue:[],push:v,loaded:!0,version:"2.0"}),_fbq:Object.assign(v,{callMethod:v,queue:[],push:v,loaded:!0,version:"2.0"})},document:{createElement:()=>({src:"",async:!1,setAttribute:()=>{},removeAttribute:()=>{}}),head:{appendChild:()=>{}}}},f={};function w(){const e=p("order complete");return["track","Purchase",{value:e.data.total,currency:"EUR",contents:e.nested.filter(e=>"product"===e.entity).map(e=>({id:e.data.id,quantity:1})),content_type:"product",num_items:2},{eventID:e.id}]}function k(){const e=p("product add");return["track","AddToCart",{currency:"EUR",value:e.data.price,contents:[{id:e.data.id,quantity:1}],content_type:"product"},{eventID:e.id}]}function q(){const e=p("cart view");return["track","InitiateCheckout",{currency:"EUR",value:e.data.value,contents:e.nested.filter(e=>"product"===e.entity).map(e=>({id:e.data.id,quantity:e.data.quantity})),num_items:e.nested.filter(e=>"product"===e.entity).length},{eventID:e.id}]}function x(){const e=p("product view");return["track","ViewContent",{currency:"EUR",value:e.data.price,contents:[{id:e.data.id,quantity:1}],content_type:"product"},{eventID:e.id}]}r(f,{AddToCart:()=>k,InitiateCheckout:()=>q,Purchase:()=>w,ViewContent:()=>x});var E={};r(E,{AddToCart:()=>_,InitiateCheckout:()=>A,Purchase:()=>C,ViewContent:()=>O,config:()=>j});var C={name:"Purchase",data:{map:{value:"data.total",currency:{value:"EUR"},contents:{loop:["nested",{condition:e=>d(e)&&"product"===e.entity,map:{id:"data.id",quantity:{key:"data.quantity",value:1}}}]},content_type:{value:"product"},num_items:{fn:e=>e.nested.filter(e=>"product"===e.entity).length}}}},_={name:"AddToCart",data:{map:{value:"data.price",currency:{value:"EUR"},contents:{set:[{map:{id:"data.id",quantity:{key:"data.quantity",value:1}}}]},content_type:{value:"product"}}}},A={name:"InitiateCheckout",data:{map:{value:"data.value",currency:{value:"EUR"},contents:{loop:["nested",{condition:e=>d(e)&&"product"===e.entity,map:{id:"data.id",quantity:{key:"data.quantity",value:1}}}]},num_items:{fn:e=>e.nested.filter(e=>"product"===e.entity).length}}}},O={name:"ViewContent",data:{map:{value:"data.price",currency:{value:"EUR"},content_type:{value:"product"},contents:{set:[{map:{id:"data.id",quantity:{key:"data.quantity",value:1}}}]}}}},j={order:{complete:C},product:{view:O,add:_},cart:{view:A}},R={type:"meta-pixel",config:{},init({config:e,env:t}){const{settings:n={},loadScript:a}=e,{pixelId:o}=n;if(a&&function(e,t="https://connect.facebook.net/en_US/fbevents.js"){const{document:n}=(0,c.getEnv)(e),a=n.createElement("script");a.src=t,a.async=!0,n.head.appendChild(a)}(t),!o)return!1;!function(e){const{window:t}=(0,c.getEnv)(e),n=t;if(n.fbq)return;const a=function(...e){a.callMethod?a.callMethod.apply(a,e):a.queue.push(e)};n.fbq=a,n._fbq||(n._fbq=a),a.push=a,a.loaded=!0,a.version="2.0",a.queue=[]}(t);const{window:r}=(0,l.getEnv)(t);return(0,r.fbq)("init",o),e},push(e,{config:t,mapping:n={},data:a,env:o}){const{track:r,trackCustom:i}=n.settings||{},{window:c}=(0,l.getEnv)(o),s=c.fbq;"page view"!==e.name||n.settings||(e.name="PageView");const u=r||i||e.name;s(i?"trackCustom":"track",String(u),d(a)?a:{},{eventID:e.id})}},U=R;//# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/setup.ts","../src/types/index.ts","../src/examples/index.ts","../src/examples/events.ts","../src/examples/mapping.ts"],"sourcesContent":["import type { Settings, Destination } from './types';\nimport { addScript, setup } from './setup';\nimport { isObject } from '@walkeros/core';\nimport { getEnvironment } from '@walkeros/web-core';\n\n// Types\nexport * as DestinationMeta from './types';\n\n// Examples\nexport * as examples from './examples';\n\nexport const destinationMeta: Destination = {\n type: 'meta-pixel',\n\n config: {},\n\n init({ config, env }) {\n const { settings = {} as Partial<Settings>, loadScript } = config;\n const { pixelId } = settings;\n\n // Load Meta Pixel script if required (fbevents.js)\n if (loadScript) addScript(env);\n\n // Required pixel id\n if (!pixelId) return false;\n\n // fbq function setup\n setup(env);\n\n const { window } = getEnvironment(env);\n const fbq = window.fbq as facebook.Pixel.Event;\n fbq('init', pixelId);\n\n return config;\n },\n\n push(event, { config, mapping = {}, data, env }) {\n const { track, trackCustom } = mapping.settings || {};\n const { window } = getEnvironment(env);\n const fbq = window.fbq as facebook.Pixel.Event;\n\n // page view\n if (event.name === 'page view' && !mapping.settings) {\n // Define a custom mapping\n event.name = 'PageView';\n }\n\n const eventName = track || trackCustom || event.name;\n\n fbq(\n trackCustom ? 'trackCustom' : 'track',\n String(eventName),\n isObject(data) ? data : {},\n { eventID: event.id },\n );\n },\n};\n\nexport default destinationMeta;\n","import type { DestinationWeb } from '@walkeros/web-core';\nimport { getEnvironment } from '@walkeros/web-core';\n\nexport function addScript(\n env?: DestinationWeb.Environment,\n src = 'https://connect.facebook.net/en_US/fbevents.js',\n) {\n const { document } = getEnvironment(env);\n const script = document.createElement('script');\n script.src = src;\n script.async = true;\n document.head.appendChild(script);\n}\n\ninterface FBQFunction {\n (...args: unknown[]): void;\n callMethod?: (this: FBQFunction, ...args: unknown[]) => void;\n queue: unknown[];\n push: FBQFunction;\n loaded: boolean;\n version: string;\n}\n\nexport function setup(env?: DestinationWeb.Environment) {\n const { window } = getEnvironment(env);\n const w = window as unknown as {\n fbq?: FBQFunction;\n _fbq?: FBQFunction;\n };\n if (w.fbq as unknown) return;\n\n const n = function (...args: unknown[]): void {\n n.callMethod ? n.callMethod.apply(n, args) : n.queue.push(args);\n } as FBQFunction;\n\n w.fbq = n;\n if (!w._fbq) w._fbq = n;\n n.push = n;\n n.loaded = true;\n n.version = '2.0';\n n.queue = [];\n}\n","import type { Mapping as WalkerOSMapping } from '@walkeros/core';\nimport type { DestinationWeb } from '@walkeros/web-core';\n\ndeclare global {\n interface Window {\n _fbq?: facebook.Pixel.Event;\n fbq?: facebook.Pixel.Event;\n }\n}\n\n// Meta-specific environment that includes fbq\nexport interface MetaEnvironment {\n window: {\n fbq: facebook.Pixel.Event;\n _fbq?: facebook.Pixel.Event;\n };\n document: Document;\n}\n\nexport type Destination = DestinationWeb.Destination<Settings, Mapping>;\nexport type Config = DestinationWeb.Config<Settings, Mapping>;\n\n// Destination-specific settings (internal usage)\nexport interface Settings {\n pixelId?: string; // Required pixel id\n}\n\n// Single event transformation rule\nexport interface Mapping {\n track?: StandardEventNames; // Name of a standard event to track\n trackCustom?: string; // Name of a custom event to track\n}\n\nexport type Rule = WalkerOSMapping.Rule<Mapping>;\nexport type Rules = WalkerOSMapping.Rules<Rule>;\n\nexport type StandardEventNames =\n | 'PageView'\n | 'AddPaymentInfo'\n | 'AddToCart'\n | 'AddToWishlist'\n | 'CompleteRegistration'\n | 'Contact'\n | 'CustomizeProduct'\n | 'Donate'\n | 'FindLocation'\n | 'InitiateCheckout'\n | 'Lead'\n | 'Purchase'\n | 'Schedule'\n | 'Search'\n | 'StartTrial'\n | 'SubmitApplication'\n | 'Subscribe'\n | 'ViewContent'\n | string;\n","export * as events from './events';\nexport * as mapping from './mapping';\n","import { getEvent } from '@walkeros/core';\n\nexport function Purchase(): unknown[] {\n const event = getEvent('order complete');\n\n return [\n 'track',\n 'Purchase',\n {\n value: event.data.total,\n currency: 'EUR',\n contents: event.nested\n .filter((item) => item.entity === 'product')\n .map((item) => ({ id: item.data.id, quantity: 1 })),\n content_type: 'product',\n num_items: 2,\n },\n { eventID: event.id },\n ];\n}\n\nexport function AddToCart(): unknown[] {\n const event = getEvent('product add');\n\n return [\n 'track',\n 'AddToCart',\n {\n currency: 'EUR',\n value: event.data.price,\n contents: [{ id: event.data.id, quantity: 1 }],\n content_type: 'product',\n },\n { eventID: event.id },\n ];\n}\n\nexport function InitiateCheckout(): unknown[] {\n const event = getEvent('cart view');\n\n return [\n 'track',\n 'InitiateCheckout',\n {\n currency: 'EUR',\n value: event.data.value,\n contents: event.nested\n .filter((entity) => entity.entity === 'product')\n .map((entity) => ({\n id: entity.data.id,\n quantity: entity.data.quantity,\n })),\n num_items: event.nested.filter((item) => item.entity === 'product')\n .length,\n },\n { eventID: event.id },\n ];\n}\n\nexport function ViewContent(): unknown[] {\n const event = getEvent('product view');\n\n return [\n 'track',\n 'ViewContent',\n {\n currency: 'EUR',\n value: event.data.price,\n contents: [{ id: event.data.id, quantity: 1 }],\n content_type: 'product',\n },\n { eventID: event.id },\n ];\n}\n","import type { Mapping, WalkerOS } from '@walkeros/core';\nimport type { DestinationMeta } from '..';\nimport { isObject } from '@walkeros/core';\n\nexport const Purchase: DestinationMeta.Rule = {\n name: 'Purchase',\n data: {\n map: {\n value: 'data.total',\n currency: { value: 'EUR' },\n contents: {\n loop: [\n 'nested',\n {\n condition: (entity) =>\n isObject(entity) && entity.entity === 'product',\n map: {\n id: 'data.id',\n quantity: { key: 'data.quantity', value: 1 },\n },\n },\n ],\n },\n content_type: { value: 'product' },\n num_items: {\n fn: (event) =>\n (event as WalkerOS.Event).nested.filter(\n (item) => item.entity === 'product',\n ).length,\n },\n },\n },\n};\n\nexport const AddToCart: DestinationMeta.Rule = {\n name: 'AddToCart',\n data: {\n map: {\n value: 'data.price',\n currency: { value: 'EUR' },\n contents: {\n set: [\n {\n map: {\n id: 'data.id',\n quantity: { key: 'data.quantity', value: 1 },\n },\n },\n ],\n },\n content_type: { value: 'product' },\n },\n },\n};\n\nexport const InitiateCheckout: DestinationMeta.Rule = {\n name: 'InitiateCheckout',\n data: {\n map: {\n value: 'data.value',\n currency: { value: 'EUR' },\n contents: {\n loop: [\n 'nested',\n {\n condition: (entity) =>\n isObject(entity) && entity.entity === 'product',\n map: {\n id: 'data.id',\n quantity: { key: 'data.quantity', value: 1 },\n },\n },\n ],\n },\n num_items: {\n fn: (event) =>\n (event as WalkerOS.Event).nested.filter(\n (item) => item.entity === 'product',\n ).length,\n },\n },\n },\n};\n\nexport const ViewContent: DestinationMeta.Rule = {\n name: 'ViewContent',\n data: {\n map: {\n value: 'data.price',\n currency: { value: 'EUR' },\n content_type: { value: 'product' },\n contents: {\n set: [\n {\n map: {\n id: 'data.id',\n quantity: { key: 'data.quantity', value: 1 },\n },\n },\n ],\n },\n },\n },\n};\n\nexport const config = {\n order: { complete: Purchase },\n product: { view: ViewContent, add: AddToCart },\n cart: { view: InitiateCheckout },\n} satisfies DestinationMeta.Rules;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,sBAA+B;AAExB,SAAS,UACd,KACA,MAAM,kDACN;AACA,QAAM,EAAE,UAAAA,UAAS,QAAI,gCAAe,GAAG;AACvC,QAAM,SAASA,UAAS,cAAc,QAAQ;AAC9C,SAAO,MAAM;AACb,SAAO,QAAQ;AACf,EAAAA,UAAS,KAAK,YAAY,MAAM;AAClC;AAWO,SAAS,MAAM,KAAkC;AACtD,QAAM,EAAE,OAAO,QAAI,gCAAe,GAAG;AACrC,QAAMC,KAAI;AAIV,MAAIA,GAAE,IAAgB;AAEtB,QAAMC,KAAI,YAAa,MAAuB;AAC5C,IAAAA,GAAE,aAAaA,GA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A,YAC7C;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAEO,IAAM,SAAS;AAAA,EACpB,OAAO,EAAE,UAAUH,UAAS;AAAA,EAC5B,SAAS,EAAE,MAAMG,cAAa,KAAKF,WAAU;AAAA,EAC7C,MAAM,EAAE,MAAMC,kBAAiB;AACjC;;;ALlGO,IAAM,kBAA+B;AAAA,EAC1C,MAAM;AAAA,EAEN,QAAQ,CAAC;AAAA,EAET,KAAK,EAAE,QAAAE,SAAQ,IAAI,GAAG;AACpB,UAAM,EAAE,WAAW,CAAC,GAAwB,WAAW,IAAIA;AAC3D,UAAM,EAAE,QAAQ,IAAI;AAGpB,QAAI,WAAY,WAAU,GAAG;AAG7B,QAAI,CAAC,QAAS,QAAO;AAGrB,UAAM,GAAG;AAET,UAAM,EAAE,OAAO,QAAI,iCAAe,GAAG;AACrC,UAAM,MAAM,OAAO;AACnB,QAAI,QAAQ,OAAO;AAEnB,WAAOA;AAAA,EACT;AAAA,EAEA,KAAK,OAAO,EAAE,QAAAA,SAAQ,UAAU,CAAC,GAAG,MAAM,IAAI,GAAG;AAC/C,UAAM,EAAE,OAAO,YAAY,IAAI,QAAQ,YAAY,CAAC;AACpD,UAAM,EAAE,OAAO,QAAI,iCAAe,GAAG;AACrC,UAAM,MAAM,OAAO;AAGnB,QAAI,MAAM,SAAS,eAAe,CAAC,QAAQ,UAAU;AAEnD,YAAM,OAAO;AAAA,IACf;AAEA,UAAM,YAAY,SAAS,eAAe,MAAM;AAEhD;AAAA,MACE,cAAc,gBAAgB;AAAA,MAC9B,OAAO,SAAS;AAAA,MAChB,EAAS,IAAI,IAAI,OAAO,CAAC;AAAA,MACzB,EAAE,SAAS,MAAM,GAAG;AAAA,IACtB;AAAA,EACF;AACF;AAEA,IAAO,gBAAQ;","names":["document","w","n","import_web_core","AddToCart","InitiateCheckout","Purchase","ViewContent","Purchase","AddToCart","InitiateCheckout","ViewContent","config"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/setup.ts","../src/types/index.ts","../src/examples/index.ts","../src/examples/env.ts","../src/examples/events.ts","../src/examples/mapping.ts"],"sourcesContent":["import type { Settings, Destination } from './types';\nimport { addScript, setup } from './setup';\nimport { isObject } from '@walkeros/core';\nimport { getEnv } from '@walkeros/web-core';\n\n// Types\nexport * as DestinationMeta from './types';\n\n// Examples\nexport * as examples from './examples';\n\nexport const destinationMeta: Destination = {\n type: 'meta-pixel',\n\n config: {},\n\n init({ config, env }) {\n const { settings = {} as Partial<Settings>, loadScript } = config;\n const { pixelId } = settings;\n\n // Load Meta Pixel script if required (fbevents.js)\n if (loadScript) addScript(env);\n\n // Required pixel id\n if (!pixelId) return false;\n\n // fbq function setup\n setup(env);\n\n const { window } = getEnv(env);\n const fbq = window.fbq as facebook.Pixel.Event;\n fbq('init', pixelId);\n\n return config;\n },\n\n push(event, { config, mapping = {}, data, env }) {\n const { track, trackCustom } = mapping.settings || {};\n const { window } = getEnv(env);\n const fbq = window.fbq as facebook.Pixel.Event;\n\n // page view\n if (event.name === 'page view' && !mapping.settings) {\n // Define a custom mapping\n event.name = 'PageView';\n }\n\n const eventName = track || trackCustom || event.name;\n\n fbq(\n trackCustom ? 'trackCustom' : 'track',\n String(eventName),\n isObject(data) ? data : {},\n { eventID: event.id },\n );\n },\n};\n\nexport default destinationMeta;\n","import type { DestinationWeb } from '@walkeros/web-core';\nimport { getEnv } from '@walkeros/web-core';\n\nexport function addScript(\n env?: DestinationWeb.Env,\n src = 'https://connect.facebook.net/en_US/fbevents.js',\n) {\n const { document } = getEnv(env);\n const script = (document as Document).createElement('script');\n script.src = src;\n script.async = true;\n (document as Document).head.appendChild(script);\n}\n\ninterface FBQFunction {\n (...args: unknown[]): void;\n callMethod?: (this: FBQFunction, ...args: unknown[]) => void;\n queue: unknown[];\n push: FBQFunction;\n loaded: boolean;\n version: string;\n}\n\nexport function setup(env?: DestinationWeb.Env) {\n const { window } = getEnv(env);\n const w = window as unknown as {\n fbq?: FBQFunction;\n _fbq?: FBQFunction;\n };\n if (w.fbq as unknown) return;\n\n const n = function (...args: unknown[]): void {\n n.callMethod ? n.callMethod.apply(n, args) : n.queue.push(args);\n } as FBQFunction;\n\n w.fbq = n;\n if (!w._fbq) w._fbq = n;\n n.push = n;\n n.loaded = true;\n n.version = '2.0';\n n.queue = [];\n}\n","import type {\n Mapping as WalkerOSMapping,\n Destination as CoreDestination,\n} from '@walkeros/core';\nimport type { DestinationWeb } from '@walkeros/web-core';\n\ndeclare global {\n interface Window {\n _fbq?: facebook.Pixel.Event;\n fbq?: facebook.Pixel.Event;\n }\n}\n\nexport interface Settings {\n pixelId?: string;\n}\n\nexport interface Mapping {\n track?: StandardEventNames;\n trackCustom?: string;\n}\n\nexport interface Env extends DestinationWeb.Env {\n window: {\n fbq: facebook.Pixel.Event;\n _fbq?: facebook.Pixel.Event;\n };\n document: {\n createElement: (tagName: string) => Element;\n head: { appendChild: (node: unknown) => void };\n };\n}\n\nexport type Types = CoreDestination.Types<Settings, Mapping, Env>;\n\nexport type Destination = DestinationWeb.Destination<Types>;\nexport type Config = DestinationWeb.Config<Types>;\n\nexport type Rule = WalkerOSMapping.Rule<Mapping>;\nexport type Rules = WalkerOSMapping.Rules<Rule>;\n\nexport type StandardEventNames =\n | 'PageView'\n | 'AddPaymentInfo'\n | 'AddToCart'\n | 'AddToWishlist'\n | 'CompleteRegistration'\n | 'Contact'\n | 'CustomizeProduct'\n | 'Donate'\n | 'FindLocation'\n | 'InitiateCheckout'\n | 'Lead'\n | 'Purchase'\n | 'Schedule'\n | 'Search'\n | 'StartTrial'\n | 'SubmitApplication'\n | 'Subscribe'\n | 'ViewContent'\n | string;\n","export * as env from './env';\nexport * as events from './events';\nexport * as mapping from './mapping';\n","import type { Env } from '../types';\n\n/**\n * Example environment configurations for Meta Pixel destination\n *\n * These environments provide standardized mock structures for testing\n * and development without requiring external dependencies.\n */\n\n// Simple no-op function for mocking\nconst noop = () => {};\n\nexport const init: Env | undefined = {\n // Environment before initialization (fbq not loaded yet)\n window: {\n fbq: undefined as unknown as Env['window']['fbq'],\n _fbq: undefined,\n },\n document: {\n createElement: () =>\n ({\n src: '',\n async: false,\n setAttribute: () => {},\n removeAttribute: () => {},\n }) as unknown as Element,\n head: { appendChild: () => {} },\n },\n};\n\nexport const push: Env = {\n // Standard mock environment for testing\n window: {\n fbq: Object.assign(noop, {\n // Add Meta Pixel specific properties\n callMethod: noop,\n queue: [] as unknown[],\n push: noop,\n loaded: true,\n version: '2.0',\n }) as unknown as Env['window']['fbq'],\n _fbq: Object.assign(noop, {\n callMethod: noop,\n queue: [] as unknown[],\n push: noop,\n loaded: true,\n version: '2.0',\n }) as unknown as Env['window']['_fbq'],\n },\n document: {\n createElement: () =>\n ({\n src: '',\n async: false,\n setAttribute: () => {},\n removeAttribute: () => {},\n }) as unknown as Element,\n head: { appendChild: () => {} },\n },\n};\n\n// Future: error scenarios (v2)\n// export const error: Env = { ... };\n","import { getEvent } from '@walkeros/core';\n\nexport function Purchase(): unknown[] {\n const event = getEvent('order complete');\n\n return [\n 'track',\n 'Purchase',\n {\n value: event.data.total,\n currency: 'EUR',\n contents: event.nested\n .filter((item) => item.entity === 'product')\n .map((item) => ({ id: item.data.id, quantity: 1 })),\n content_type: 'product',\n num_items: 2,\n },\n { eventID: event.id },\n ];\n}\n\nexport function AddToCart(): unknown[] {\n const event = getEvent('product add');\n\n return [\n 'track',\n 'AddToCart',\n {\n currency: 'EUR',\n value: event.data.price,\n contents: [{ id: event.data.id, quantity: 1 }],\n content_type: 'product',\n },\n { eventID: event.id },\n ];\n}\n\nexport function InitiateCheckout(): unknown[] {\n const event = getEvent('cart view');\n\n return [\n 'track',\n 'InitiateCheckout',\n {\n currency: 'EUR',\n value: event.data.value,\n contents: event.nested\n .filter((entity) => entity.entity === 'product')\n .map((entity) => ({\n id: entity.data.id,\n quantity: entity.data.quantity,\n })),\n num_items: event.nested.filter((item) => item.entity === 'product')\n .length,\n },\n { eventID: event.id },\n ];\n}\n\nexport function ViewContent(): unknown[] {\n const event = getEvent('product view');\n\n return [\n 'track',\n 'ViewContent',\n {\n currency: 'EUR',\n value: event.data.price,\n contents: [{ id: event.data.id, quantity: 1 }],\n content_type: 'product',\n },\n { eventID: event.id },\n ];\n}\n","import type { Mapping, WalkerOS } from '@walkeros/core';\nimport type { DestinationMeta } from '..';\nimport { isObject } from '@walkeros/core';\n\nexport const Purchase: DestinationMeta.Rule = {\n name: 'Purchase',\n data: {\n map: {\n value: 'data.total',\n currency: { value: 'EUR' },\n contents: {\n loop: [\n 'nested',\n {\n condition: (entity) =>\n isObject(entity) && entity.entity === 'product',\n map: {\n id: 'data.id',\n quantity: { key: 'data.quantity', value: 1 },\n },\n },\n ],\n },\n content_type: { value: 'product' },\n num_items: {\n fn: (event) =>\n (event as WalkerOS.Event).nested.filter(\n (item) => item.entity === 'product',\n ).length,\n },\n },\n },\n};\n\nexport const AddToCart: DestinationMeta.Rule = {\n name: 'AddToCart',\n data: {\n map: {\n value: 'data.price',\n currency: { value: 'EUR' },\n contents: {\n set: [\n {\n map: {\n id: 'data.id',\n quantity: { key: 'data.quantity', value: 1 },\n },\n },\n ],\n },\n content_type: { value: 'product' },\n },\n },\n};\n\nexport const InitiateCheckout: DestinationMeta.Rule = {\n name: 'InitiateCheckout',\n data: {\n map: {\n value: 'data.value',\n currency: { value: 'EUR' },\n contents: {\n loop: [\n 'nested',\n {\n condition: (entity) =>\n isObject(entity) && entity.entity === 'product',\n map: {\n id: 'data.id',\n quantity: { key: 'data.quantity', value: 1 },\n },\n },\n ],\n },\n num_items: {\n fn: (event) =>\n (event as WalkerOS.Event).nested.filter(\n (item) => item.entity === 'product',\n ).length,\n },\n },\n },\n};\n\nexport const ViewContent: DestinationMeta.Rule = {\n name: 'ViewContent',\n data: {\n map: {\n value: 'data.price',\n currency: { value: 'EUR' },\n content_type: { value: 'product' },\n contents: {\n set: [\n {\n map: {\n id: 'data.id',\n quantity: { key: 'data.quantity', value: 1 },\n },\n },\n ],\n },\n },\n },\n};\n\nexport const config = {\n order: { complete: Purchase },\n product: { view: ViewContent, add: AddToCart },\n cart: { view: InitiateCheckout },\n} satisfies DestinationMeta.Rules;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,sBAAuB;AAEhB,SAAS,UACd,KACA,MAAM,kDACN;AACA,QAAM,EAAE,UAAAA,UAAS,QAAI,wBAAO,GAAG;AAC/B,QAAM,SAAUA,UAAsB,cAAc,QAAQ;AAC5D,SAAO,MAAM;AACb,SAAO,QAAQ;AACf,EAACA,UAAsB,KAAK,YAAY,MAAM;AAChD;AAWO,SAAS,MAAM,KAA0B;AAC9C,QAAM,EAAE,OAAO,QAAI,wBAAO,GAAG;AAC7B,QAAM,IAAI;AAIV,MAAI,EAAE,IAAgB;AAEtB,QAAM,IAAI,YAAa,MAAuB;AAC5C,MAAE,aAAa,EAAE,WAAW,MAAM,GAAG,IAAI,IAAI,EAAE,MAAM,KAAK,IAAI;AAAA,EAChE;AAEA,IAAE,MAAM;AACR,MAAI,CAAC,EAAE,KAAM,GAAE,OAAO;AACtB,IAAE,OAAO;AACT,IAAE,SAAS;AACX,IAAE,UAAU;AACZ,IAAE,QAAQ,CAAC;AACb;A;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ADtCA,IAAAC,mBAAuB;;;AEHvB;;;ACAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAAA;AAAA;AAAA;AAAA;AAUA,IAAM,OAAO,MAAM;AAAC;AAEb,IAAM,OAAwB;AAAA;AAAA,EAEnC,QAAQ;AAAA,IACN,KAAK;AAAA,IACL,MAAM;AAAA,EACR;AAAA,EACA,UAAU;AAAA,IACR,eAAe,OACZ;AAAA,MACC,KAAK;AAAA,MACL,OAAO;AAAA,MACP,cAAc,MAAM;AAAA,MAAC;AAAA,MACrB,iBAAiB,MAAM;AAAA,MAAC;AAAA,IAC1B;AAAA,IACF,MAAM,EAA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AgB;AAAA,MAC9B,OAAO,SAAS;AAAA,MAChB,EAAS,IAAI,IAAI,OAAO,CAAC;AAAA,MACzB,EAAE,SAAS,MAAM,GAAG;AAAA,IACtB;AAAA,EACF;AACF;AAEA,IAAO,gBAAQ;","names":["document","import_web_core","AddToCart","InitiateCheckout","Purchase","ViewContent","Purchase","AddToCart","InitiateCheckout","ViewContent","config"]}
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- var e,t,n=Object.defineProperty,a=(e,t)=>{for(var a in t)n(e,a,{get:t[a],enumerable:!0})};import{getEnvironment as o}from"@walkeros/web-core";var r=Object.getOwnPropertyNames,i=(e={"package.json"(e,t){t.exports={name:"@walkeros/core",description:"Core types and platform-agnostic utilities for walkerOS",version:"0.1.2",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 t||(0,e[r(e)[0]])((t={exports:{}}).exports,t),t.exports}),s={merge:!0,shallow:!0,extend:!0};function c(e){return"object"==typeof e&&null!==e&&!function(e){return Array.isArray(e)}(e)&&"[object Object]"===Object.prototype.toString.call(e)}var{version:d}=i();function p(e={}){var t;const n=e.timestamp||(new Date).setHours(0,13,37,0),a=e.group||"gr0up",o=e.count||1,r=function(e,t={},n={}){n={...s,...n};const a=Object.entries(t).reduce((t,[a,o])=>{const r=e[a];return n.merge&&Array.isArray(r)&&Array.isArray(o)?t[a]=o.reduce((e,t)=>e.includes(t)?e:[...e,t],[...r]):(n.extend||a in e)&&(t[a]=o),t},{});return n.shallow?{...e,...a}:(Object.assign(e,a),e)}({name:"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:[{entity:"child",data:{is:"subordinated"},nested:[],context:{element:["child",0]}}],consent:{functional:!0},id:`${n}-${a}-${o}`,trigger:"test",entity:"entity",action:"action",timestamp:n,timing:3.14,group:a,count:o,version:{source:d,tagging:1},source:{type:"web",id:"https://localhost:80",previous_id:"http://remotehost:9001"}},e,{merge:!1});if(e.name){const[n,a]=null!=(t=e.name.split(" "))?t:[];n&&a&&(r.entity=n,r.action=a)}return r}function u(e="entity action",t={}){const n=t.timestamp||(new Date).setHours(0,13,37,0),a={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}};return p({...{"cart view":{data:{currency:"EUR",value:2*a.data.price},context:{shopping:["cart",0]},globals:{pagegroup:"shop"},nested:[{entity:"product",data:{...a.data,quantity:2},context:{shopping:["cart",0]},nested:[]}],trigger:"load"},"checkout view":{data:{step:"payment",currency:"EUR",value:a.data.price+o.data.price},context:{shopping:["checkout",0]},globals:{pagegroup:"shop"},nested:[{entity:"product",...a,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",...a,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.elbwalker.com/",search:"?foo=bar",hash:"#hash",id:"/docs/"},globals:{pagegroup:"docs"},trigger:"load"},"product add":{...a,context:{shopping:["intent",0]},globals:{pagegroup:"shop"},nested:[],trigger:"click"},"product view":{...a,context:{shopping:["detail",0]},globals:{pagegroup:"shop"},nested:[],trigger:"load"},"product visible":{data:{...a.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:n,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,name:e})}import{getEnvironment as l}from"@walkeros/web-core";var g={},m={};a(m,{events:()=>y,mapping:()=>f});var y={};function h(){const e=u("order complete");return["track","Purchase",{value:e.data.total,currency:"EUR",contents:e.nested.filter(e=>"product"===e.entity).map(e=>({id:e.data.id,quantity:1})),content_type:"product",num_items:2},{eventID:e.id}]}function v(){const e=u("product add");return["track","AddToCart",{currency:"EUR",value:e.data.price,contents:[{id:e.data.id,quantity:1}],content_type:"product"},{eventID:e.id}]}function b(){const e=u("cart view");return["track","InitiateCheckout",{currency:"EUR",value:e.data.value,contents:e.nested.filter(e=>"product"===e.entity).map(e=>({id:e.data.id,quantity:e.data.quantity})),num_items:e.nested.filter(e=>"product"===e.entity).length},{eventID:e.id}]}function w(){const e=u("product view");return["track","ViewContent",{currency:"EUR",value:e.data.price,contents:[{id:e.data.id,quantity:1}],content_type:"product"},{eventID:e.id}]}a(y,{AddToCart:()=>v,InitiateCheckout:()=>b,Purchase:()=>h,ViewContent:()=>w});var f={};a(f,{AddToCart:()=>x,InitiateCheckout:()=>q,Purchase:()=>k,ViewContent:()=>C,config:()=>S});var k={name:"Purchase",data:{map:{value:"data.total",currency:{value:"EUR"},contents:{loop:["nested",{condition:e=>c(e)&&"product"===e.entity,map:{id:"data.id",quantity:{key:"data.quantity",value:1}}}]},content_type:{value:"product"},num_items:{fn:e=>e.nested.filter(e=>"product"===e.entity).length}}}},x={name:"AddToCart",data:{map:{value:"data.price",currency:{value:"EUR"},contents:{set:[{map:{id:"data.id",quantity:{key:"data.quantity",value:1}}}]},content_type:{value:"product"}}}},q={name:"InitiateCheckout",data:{map:{value:"data.value",currency:{value:"EUR"},contents:{loop:["nested",{condition:e=>c(e)&&"product"===e.entity,map:{id:"data.id",quantity:{key:"data.quantity",value:1}}}]},num_items:{fn:e=>e.nested.filter(e=>"product"===e.entity).length}}}},C={name:"ViewContent",data:{map:{value:"data.price",currency:{value:"EUR"},content_type:{value:"product"},contents:{set:[{map:{id:"data.id",quantity:{key:"data.quantity",value:1}}}]}}}},S={order:{complete:k},product:{view:C,add:x},cart:{view:q}},E={type:"meta-pixel",config:{},init({config:e,env:t}){const{settings:n={},loadScript:a}=e,{pixelId:r}=n;if(a&&function(e,t="https://connect.facebook.net/en_US/fbevents.js"){const{document:n}=o(e),a=n.createElement("script");a.src=t,a.async=!0,n.head.appendChild(a)}(t),!r)return!1;!function(e){const{window:t}=o(e),n=t;if(n.fbq)return;const a=function(...e){a.callMethod?a.callMethod.apply(a,e):a.queue.push(e)};n.fbq=a,n._fbq||(n._fbq=a),a.push=a,a.loaded=!0,a.version="2.0",a.queue=[]}(t);const{window:i}=l(t);return(0,i.fbq)("init",r),e},push(e,{config:t,mapping:n={},data:a,env:o}){const{track:r,trackCustom:i}=n.settings||{},{window:s}=l(o),d=s.fbq;"page view"!==e.name||n.settings||(e.name="PageView");const p=r||i||e.name;d(i?"trackCustom":"track",String(p),c(a)?a:{},{eventID:e.id})}},_=E;export{g as DestinationMeta,_ as default,E as destinationMeta,m as examples};//# sourceMappingURL=index.mjs.map
1
+ var t=Object.defineProperty,e=(e,n)=>{for(var a in n)t(e,a,{get:n[a],enumerable:!0})};import{getEnv as n}from"@walkeros/web-core";var a={merge:!0,shallow:!0,extend:!0};function o(t){return"object"==typeof t&&null!==t&&!function(t){return Array.isArray(t)}(t)&&"[object Object]"===Object.prototype.toString.call(t)}function i(t={}){var e;const n=t.timestamp||(new Date).setHours(0,13,37,0),o=t.group||"gr0up",i=t.count||1,r=function(t,e={},n={}){n={...a,...n};const o=Object.entries(e).reduce((e,[a,o])=>{const i=t[a];return n.merge&&Array.isArray(i)&&Array.isArray(o)?e[a]=o.reduce((t,e)=>t.includes(e)?t:[...t,e],[...i]):(n.extend||a in t)&&(e[a]=o),e},{});return n.shallow?{...t,...o}:(Object.assign(t,o),t)}({name:"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:[{entity:"child",data:{is:"subordinated"},nested:[],context:{element:["child",0]}}],consent:{functional:!0},id:`${n}-${o}-${i}`,trigger:"test",entity:"entity",action:"action",timestamp:n,timing:3.14,group:o,count:i,version:{source:"0.2.0",tagging:1},source:{type:"web",id:"https://localhost:80",previous_id:"http://remotehost:9001"}},t,{merge:!1});if(t.name){const[n,a]=null!=(e=t.name.split(" "))?e:[];n&&a&&(r.entity=n,r.action=a)}return r}function r(t="entity action",e={}){const n=e.timestamp||(new Date).setHours(0,13,37,0),a={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}};return i({...{"cart view":{data:{currency:"EUR",value:2*a.data.price},context:{shopping:["cart",0]},globals:{pagegroup:"shop"},nested:[{entity:"product",data:{...a.data,quantity:2},context:{shopping:["cart",0]},nested:[]}],trigger:"load"},"checkout view":{data:{step:"payment",currency:"EUR",value:a.data.price+o.data.price},context:{shopping:["checkout",0]},globals:{pagegroup:"shop"},nested:[{entity:"product",...a,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",...a,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.elbwalker.com/",search:"?foo=bar",hash:"#hash",id:"/docs/"},globals:{pagegroup:"docs"},trigger:"load"},"product add":{...a,context:{shopping:["intent",0]},globals:{pagegroup:"shop"},nested:[],trigger:"click"},"product view":{...a,context:{shopping:["detail",0]},globals:{pagegroup:"shop"},nested:[],trigger:"load"},"product visible":{data:{...a.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:n,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"}}}[t],...e,name:t})}import{getEnv as c}from"@walkeros/web-core";var s={},d={};e(d,{env:()=>u,events:()=>m,mapping:()=>f});var u={};e(u,{init:()=>l,push:()=>g});var p=()=>{},l={window:{fbq:void 0,_fbq:void 0},document:{createElement:()=>({src:"",async:!1,setAttribute:()=>{},removeAttribute:()=>{}}),head:{appendChild:()=>{}}}},g={window:{fbq:Object.assign(p,{callMethod:p,queue:[],push:p,loaded:!0,version:"2.0"}),_fbq:Object.assign(p,{callMethod:p,queue:[],push:p,loaded:!0,version:"2.0"})},document:{createElement:()=>({src:"",async:!1,setAttribute:()=>{},removeAttribute:()=>{}}),head:{appendChild:()=>{}}}},m={};function y(){const t=r("order complete");return["track","Purchase",{value:t.data.total,currency:"EUR",contents:t.nested.filter(t=>"product"===t.entity).map(t=>({id:t.data.id,quantity:1})),content_type:"product",num_items:2},{eventID:t.id}]}function h(){const t=r("product add");return["track","AddToCart",{currency:"EUR",value:t.data.price,contents:[{id:t.data.id,quantity:1}],content_type:"product"},{eventID:t.id}]}function v(){const t=r("cart view");return["track","InitiateCheckout",{currency:"EUR",value:t.data.value,contents:t.nested.filter(t=>"product"===t.entity).map(t=>({id:t.data.id,quantity:t.data.quantity})),num_items:t.nested.filter(t=>"product"===t.entity).length},{eventID:t.id}]}function b(){const t=r("product view");return["track","ViewContent",{currency:"EUR",value:t.data.price,contents:[{id:t.data.id,quantity:1}],content_type:"product"},{eventID:t.id}]}e(m,{AddToCart:()=>h,InitiateCheckout:()=>v,Purchase:()=>y,ViewContent:()=>b});var f={};e(f,{AddToCart:()=>k,InitiateCheckout:()=>q,Purchase:()=>w,ViewContent:()=>x,config:()=>C});var w={name:"Purchase",data:{map:{value:"data.total",currency:{value:"EUR"},contents:{loop:["nested",{condition:t=>o(t)&&"product"===t.entity,map:{id:"data.id",quantity:{key:"data.quantity",value:1}}}]},content_type:{value:"product"},num_items:{fn:t=>t.nested.filter(t=>"product"===t.entity).length}}}},k={name:"AddToCart",data:{map:{value:"data.price",currency:{value:"EUR"},contents:{set:[{map:{id:"data.id",quantity:{key:"data.quantity",value:1}}}]},content_type:{value:"product"}}}},q={name:"InitiateCheckout",data:{map:{value:"data.value",currency:{value:"EUR"},contents:{loop:["nested",{condition:t=>o(t)&&"product"===t.entity,map:{id:"data.id",quantity:{key:"data.quantity",value:1}}}]},num_items:{fn:t=>t.nested.filter(t=>"product"===t.entity).length}}}},x={name:"ViewContent",data:{map:{value:"data.price",currency:{value:"EUR"},content_type:{value:"product"},contents:{set:[{map:{id:"data.id",quantity:{key:"data.quantity",value:1}}}]}}}},C={order:{complete:w},product:{view:x,add:k},cart:{view:q}},E={type:"meta-pixel",config:{},init({config:t,env:e}){const{settings:a={},loadScript:o}=t,{pixelId:i}=a;if(o&&function(t,e="https://connect.facebook.net/en_US/fbevents.js"){const{document:a}=n(t),o=a.createElement("script");o.src=e,o.async=!0,a.head.appendChild(o)}(e),!i)return!1;!function(t){const{window:e}=n(t),a=e;if(a.fbq)return;const o=function(...t){o.callMethod?o.callMethod.apply(o,t):o.queue.push(t)};a.fbq=o,a._fbq||(a._fbq=o),o.push=o,o.loaded=!0,o.version="2.0",o.queue=[]}(e);const{window:r}=c(e);return(0,r.fbq)("init",i),t},push(t,{config:e,mapping:n={},data:a,env:i}){const{track:r,trackCustom:s}=n.settings||{},{window:d}=c(i),u=d.fbq;"page view"!==t.name||n.settings||(t.name="PageView");const p=r||s||t.name;u(s?"trackCustom":"track",String(p),o(a)?a:{},{eventID:t.id})}},_=E;export{s as DestinationMeta,_ as default,E as destinationMeta,d as examples};//# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/setup.ts","../src/index.ts","../src/types/index.ts","../src/examples/index.ts","../src/examples/events.ts","../src/examples/mapping.ts"],"sourcesContent":["import type { DestinationWeb } from '@walkeros/web-core';\nimport { getEnvironment } from '@walkeros/web-core';\n\nexport function addScript(\n env?: DestinationWeb.Environment,\n src = 'https://connect.facebook.net/en_US/fbevents.js',\n) {\n const { document } = getEnvironment(env);\n const script = document.createElement('script');\n script.src = src;\n script.async = true;\n document.head.appendChild(script);\n}\n\ninterface FBQFunction {\n (...args: unknown[]): void;\n callMethod?: (this: FBQFunction, ...args: unknown[]) => void;\n queue: unknown[];\n push: FBQFunction;\n loaded: boolean;\n version: string;\n}\n\nexport function setup(env?: DestinationWeb.Environment) {\n const { window } = getEnvironment(env);\n const w = window as unknown as {\n fbq?: FBQFunction;\n _fbq?: FBQFunction;\n };\n if (w.fbq as unknown) return;\n\n const n = function (...args: unknown[]): void {\n n.callMethod ? n.callMethod.apply(n, args) : n.queue.push(args);\n } as FBQFunction;\n\n w.fbq = n;\n if (!w._fbq) w._fbq = n;\n n.push = n;\n n.loaded = true;\n n.version = '2.0';\n n.queue = [];\n}\n","import type { Settings, Destination } from './types';\nimport { addScript, setup } from './setup';\nimport { isObject } from '@walkeros/core';\nimport { getEnvironment } from '@walkeros/web-core';\n\n// Types\nexport * as DestinationMeta from './types';\n\n// Examples\nexport * as examples from './examples';\n\nexport const destinationMeta: Destination = {\n type: 'meta-pixel',\n\n config: {},\n\n init({ config, env }) {\n const { settings = {} as Partial<Settings>, loadScript } = config;\n const { pixelId } = settings;\n\n // Load Meta Pixel script if required (fbevents.js)\n if (loadScript) addScript(env);\n\n // Required pixel id\n if (!pixelId) return false;\n\n // fbq function setup\n setup(env);\n\n const { window } = getEnvironment(env);\n const fbq = window.fbq as facebook.Pixel.Event;\n fbq('init', pixelId);\n\n return config;\n },\n\n push(event, { config, mapping = {}, data, env }) {\n const { track, trackCustom } = mapping.settings || {};\n const { window } = getEnvironment(env);\n const fbq = window.fbq as facebook.Pixel.Event;\n\n // page view\n if (event.name === 'page view' && !mapping.settings) {\n // Define a custom mapping\n event.name = 'PageView';\n }\n\n const eventName = track || trackCustom || event.name;\n\n fbq(\n trackCustom ? 'trackCustom' : 'track',\n String(eventName),\n isObject(data) ? data : {},\n { eventID: event.id },\n );\n },\n};\n\nexport default destinationMeta;\n","import type { Mapping as WalkerOSMapping } from '@walkeros/core';\nimport type { DestinationWeb } from '@walkeros/web-core';\n\ndeclare global {\n interface Window {\n _fbq?: facebook.Pixel.Event;\n fbq?: facebook.Pixel.Event;\n }\n}\n\n// Meta-specific environment that includes fbq\nexport interface MetaEnvironment {\n window: {\n fbq: facebook.Pixel.Event;\n _fbq?: facebook.Pixel.Event;\n };\n document: Document;\n}\n\nexport type Destination = DestinationWeb.Destination<Settings, Mapping>;\nexport type Config = DestinationWeb.Config<Settings, Mapping>;\n\n// Destination-specific settings (internal usage)\nexport interface Settings {\n pixelId?: string; // Required pixel id\n}\n\n// Single event transformation rule\nexport interface Mapping {\n track?: StandardEventNames; // Name of a standard event to track\n trackCustom?: string; // Name of a custom event to track\n}\n\nexport type Rule = WalkerOSMapping.Rule<Mapping>;\nexport type Rules = WalkerOSMapping.Rules<Rule>;\n\nexport type StandardEventNames =\n | 'PageView'\n | 'AddPaymentInfo'\n | 'AddToCart'\n | 'AddToWishlist'\n | 'CompleteRegistration'\n | 'Contact'\n | 'CustomizeProduct'\n | 'Donate'\n | 'FindLocation'\n | 'InitiateCheckout'\n | 'Lead'\n | 'Purchase'\n | 'Schedule'\n | 'Search'\n | 'StartTrial'\n | 'SubmitApplication'\n | 'Subscribe'\n | 'ViewContent'\n | string;\n","export * as events from './events';\nexport * as mapping from './mapping';\n","import { getEvent } from '@walkeros/core';\n\nexport function Purchase(): unknown[] {\n const event = getEvent('order complete');\n\n return [\n 'track',\n 'Purchase',\n {\n value: event.data.total,\n currency: 'EUR',\n contents: event.nested\n .filter((item) => item.entity === 'product')\n .map((item) => ({ id: item.data.id, quantity: 1 })),\n content_type: 'product',\n num_items: 2,\n },\n { eventID: event.id },\n ];\n}\n\nexport function AddToCart(): unknown[] {\n const event = getEvent('product add');\n\n return [\n 'track',\n 'AddToCart',\n {\n currency: 'EUR',\n value: event.data.price,\n contents: [{ id: event.data.id, quantity: 1 }],\n content_type: 'product',\n },\n { eventID: event.id },\n ];\n}\n\nexport function InitiateCheckout(): unknown[] {\n const event = getEvent('cart view');\n\n return [\n 'track',\n 'InitiateCheckout',\n {\n currency: 'EUR',\n value: event.data.value,\n contents: event.nested\n .filter((entity) => entity.entity === 'product')\n .map((entity) => ({\n id: entity.data.id,\n quantity: entity.data.quantity,\n })),\n num_items: event.nested.filter((item) => item.entity === 'product')\n .length,\n },\n { eventID: event.id },\n ];\n}\n\nexport function ViewContent(): unknown[] {\n const event = getEvent('product view');\n\n return [\n 'track',\n 'ViewContent',\n {\n currency: 'EUR',\n value: event.data.price,\n contents: [{ id: event.data.id, quantity: 1 }],\n content_type: 'product',\n },\n { eventID: event.id },\n ];\n}\n","import type { Mapping, WalkerOS } from '@walkeros/core';\nimport type { DestinationMeta } from '..';\nimport { isObject } from '@walkeros/core';\n\nexport const Purchase: DestinationMeta.Rule = {\n name: 'Purchase',\n data: {\n map: {\n value: 'data.total',\n currency: { value: 'EUR' },\n contents: {\n loop: [\n 'nested',\n {\n condition: (entity) =>\n isObject(entity) && entity.entity === 'product',\n map: {\n id: 'data.id',\n quantity: { key: 'data.quantity', value: 1 },\n },\n },\n ],\n },\n content_type: { value: 'product' },\n num_items: {\n fn: (event) =>\n (event as WalkerOS.Event).nested.filter(\n (item) => item.entity === 'product',\n ).length,\n },\n },\n },\n};\n\nexport const AddToCart: DestinationMeta.Rule = {\n name: 'AddToCart',\n data: {\n map: {\n value: 'data.price',\n currency: { value: 'EUR' },\n contents: {\n set: [\n {\n map: {\n id: 'data.id',\n quantity: { key: 'data.quantity', value: 1 },\n },\n },\n ],\n },\n content_type: { value: 'product' },\n },\n },\n};\n\nexport const InitiateCheckout: DestinationMeta.Rule = {\n name: 'InitiateCheckout',\n data: {\n map: {\n value: 'data.value',\n currency: { value: 'EUR' },\n contents: {\n loop: [\n 'nested',\n {\n condition: (entity) =>\n isObject(entity) && entity.entity === 'product',\n map: {\n id: 'data.id',\n quantity: { key: 'data.quantity', value: 1 },\n },\n },\n ],\n },\n num_items: {\n fn: (event) =>\n (event as WalkerOS.Event).nested.filter(\n (item) => item.entity === 'product',\n ).length,\n },\n },\n },\n};\n\nexport const ViewContent: DestinationMeta.Rule = {\n name: 'ViewContent',\n data: {\n map: {\n value: 'data.price',\n currency: { value: 'EUR' },\n content_type: { value: 'product' },\n contents: {\n set: [\n {\n map: {\n id: 'data.id',\n quantity: { key: 'data.quantity', value: 1 },\n },\n },\n ],\n },\n },\n },\n};\n\nexport const config = {\n order: { complete: Purchase },\n product: { view: ViewContent, add: AddToCart },\n cart: { view: InitiateCheckout },\n} satisfies DestinationMeta.Rules;\n"],"mappings":";;;;;;;AACA,SAAS,sBAAsB;AAExB,SAAS,UACd,KACA,MAAM,kDACN;AACA,QAAM,EAAE,UAAAA,UAAS,IAAI,eAAe,GAAG;AACvC,QAAM,SAASA,UAAS,cAAc,QAAQ;AAC9C,SAAO,MAAM;AACb,SAAO,QAAQ;AACf,EAAAA,UAAS,KAAK,YAAY,MAAM;AAClC;AAWO,SAAS,MAAM,KAAkC;AACtD,QAAM,EAAE,OAAO,IAAI,eAAe,GAAG;AACrC,QAAMC,KAAI;AAIV,MAAIA,GAAE,IAAgB;AAEtB,QAAMC,KAAI,YAAa,MAAuB;AAC5C,IAAAA,GAAE,aAAaA,GAAE,WAAW,MAAMA,IAAG,IAAI,IAAIA,GAAE,MAAM,KAAK,IAAI;AAAA,EAChE;AAEA,EAAAD,GAAE,MAAMC;AACR,MAAI,CAACD,GAAE,KAAM,CAAAA,GAAE,OAAOC;AACtB,EAAAA,GAAE,OAAOA;AACT,EAAAA,GAAE,SAAS;AACX,EAAAA,GAAE,UAAU;AACZ,EAAAA,GAAE,QAAQ,CAAC;AACb;A;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACtCA,SAAS,kBAAAC,uBAAsB;;;ACH/B;;;ACAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,SAAS,WAAsB;AACpC,QAAM,QAAQ,EAAS,gBAAgB;AAEvC,SAAO;AAAA,IACL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AM,GAAG;AAET,UAAM,EAAE,OAAO,IAAIC,gBAAe,GAAG;AACrC,UAAM,MAAM,OAAO;AACnB,QAAI,QAAQ,OAAO;AAEnB,WAAOD;AAAA,EACT;AAAA,EAEA,KAAK,OAAO,EAAE,QAAAA,SAAQ,UAAU,CAAC,GAAG,MAAM,IAAI,GAAG;AAC/C,UAAM,EAAE,OAAO,YAAY,IAAI,QAAQ,YAAY,CAAC;AACpD,UAAM,EAAE,OAAO,IAAIC,gBAAe,GAAG;AACrC,UAAM,MAAM,OAAO;AAGnB,QAAI,MAAM,SAAS,eAAe,CAAC,QAAQ,UAAU;AAEnD,YAAM,OAAO;AAAA,IACf;AAEA,UAAM,YAAY,SAAS,eAAe,MAAM;AAEhD;AAAA,MACE,cAAc,gBAAgB;AAAA,MAC9B,OAAO,SAAS;AAAA,MAChB,EAAS,IAAI,IAAI,OAAO,CAAC;AAAA,MACzB,EAAE,SAAS,MAAM,GAAG;AAAA,IACtB;AAAA,EACF;AACF;AAEA,IAAO,gBAAQ;","names":["document","w","n","getEnvironment","AddToCart","InitiateCheckout","Purchase","ViewContent","Purchase","AddToCart","InitiateCheckout","ViewContent","config","getEnvironment"]}
1
+ {"version":3,"sources":["../src/setup.ts","../src/index.ts","../src/types/index.ts","../src/examples/index.ts","../src/examples/env.ts","../src/examples/events.ts","../src/examples/mapping.ts"],"sourcesContent":["import type { DestinationWeb } from '@walkeros/web-core';\nimport { getEnv } from '@walkeros/web-core';\n\nexport function addScript(\n env?: DestinationWeb.Env,\n src = 'https://connect.facebook.net/en_US/fbevents.js',\n) {\n const { document } = getEnv(env);\n const script = (document as Document).createElement('script');\n script.src = src;\n script.async = true;\n (document as Document).head.appendChild(script);\n}\n\ninterface FBQFunction {\n (...args: unknown[]): void;\n callMethod?: (this: FBQFunction, ...args: unknown[]) => void;\n queue: unknown[];\n push: FBQFunction;\n loaded: boolean;\n version: string;\n}\n\nexport function setup(env?: DestinationWeb.Env) {\n const { window } = getEnv(env);\n const w = window as unknown as {\n fbq?: FBQFunction;\n _fbq?: FBQFunction;\n };\n if (w.fbq as unknown) return;\n\n const n = function (...args: unknown[]): void {\n n.callMethod ? n.callMethod.apply(n, args) : n.queue.push(args);\n } as FBQFunction;\n\n w.fbq = n;\n if (!w._fbq) w._fbq = n;\n n.push = n;\n n.loaded = true;\n n.version = '2.0';\n n.queue = [];\n}\n","import type { Settings, Destination } from './types';\nimport { addScript, setup } from './setup';\nimport { isObject } from '@walkeros/core';\nimport { getEnv } from '@walkeros/web-core';\n\n// Types\nexport * as DestinationMeta from './types';\n\n// Examples\nexport * as examples from './examples';\n\nexport const destinationMeta: Destination = {\n type: 'meta-pixel',\n\n config: {},\n\n init({ config, env }) {\n const { settings = {} as Partial<Settings>, loadScript } = config;\n const { pixelId } = settings;\n\n // Load Meta Pixel script if required (fbevents.js)\n if (loadScript) addScript(env);\n\n // Required pixel id\n if (!pixelId) return false;\n\n // fbq function setup\n setup(env);\n\n const { window } = getEnv(env);\n const fbq = window.fbq as facebook.Pixel.Event;\n fbq('init', pixelId);\n\n return config;\n },\n\n push(event, { config, mapping = {}, data, env }) {\n const { track, trackCustom } = mapping.settings || {};\n const { window } = getEnv(env);\n const fbq = window.fbq as facebook.Pixel.Event;\n\n // page view\n if (event.name === 'page view' && !mapping.settings) {\n // Define a custom mapping\n event.name = 'PageView';\n }\n\n const eventName = track || trackCustom || event.name;\n\n fbq(\n trackCustom ? 'trackCustom' : 'track',\n String(eventName),\n isObject(data) ? data : {},\n { eventID: event.id },\n );\n },\n};\n\nexport default destinationMeta;\n","import type {\n Mapping as WalkerOSMapping,\n Destination as CoreDestination,\n} from '@walkeros/core';\nimport type { DestinationWeb } from '@walkeros/web-core';\n\ndeclare global {\n interface Window {\n _fbq?: facebook.Pixel.Event;\n fbq?: facebook.Pixel.Event;\n }\n}\n\nexport interface Settings {\n pixelId?: string;\n}\n\nexport interface Mapping {\n track?: StandardEventNames;\n trackCustom?: string;\n}\n\nexport interface Env extends DestinationWeb.Env {\n window: {\n fbq: facebook.Pixel.Event;\n _fbq?: facebook.Pixel.Event;\n };\n document: {\n createElement: (tagName: string) => Element;\n head: { appendChild: (node: unknown) => void };\n };\n}\n\nexport type Types = CoreDestination.Types<Settings, Mapping, Env>;\n\nexport type Destination = DestinationWeb.Destination<Types>;\nexport type Config = DestinationWeb.Config<Types>;\n\nexport type Rule = WalkerOSMapping.Rule<Mapping>;\nexport type Rules = WalkerOSMapping.Rules<Rule>;\n\nexport type StandardEventNames =\n | 'PageView'\n | 'AddPaymentInfo'\n | 'AddToCart'\n | 'AddToWishlist'\n | 'CompleteRegistration'\n | 'Contact'\n | 'CustomizeProduct'\n | 'Donate'\n | 'FindLocation'\n | 'InitiateCheckout'\n | 'Lead'\n | 'Purchase'\n | 'Schedule'\n | 'Search'\n | 'StartTrial'\n | 'SubmitApplication'\n | 'Subscribe'\n | 'ViewContent'\n | string;\n","export * as env from './env';\nexport * as events from './events';\nexport * as mapping from './mapping';\n","import type { Env } from '../types';\n\n/**\n * Example environment configurations for Meta Pixel destination\n *\n * These environments provide standardized mock structures for testing\n * and development without requiring external dependencies.\n */\n\n// Simple no-op function for mocking\nconst noop = () => {};\n\nexport const init: Env | undefined = {\n // Environment before initialization (fbq not loaded yet)\n window: {\n fbq: undefined as unknown as Env['window']['fbq'],\n _fbq: undefined,\n },\n document: {\n createElement: () =>\n ({\n src: '',\n async: false,\n setAttribute: () => {},\n removeAttribute: () => {},\n }) as unknown as Element,\n head: { appendChild: () => {} },\n },\n};\n\nexport const push: Env = {\n // Standard mock environment for testing\n window: {\n fbq: Object.assign(noop, {\n // Add Meta Pixel specific properties\n callMethod: noop,\n queue: [] as unknown[],\n push: noop,\n loaded: true,\n version: '2.0',\n }) as unknown as Env['window']['fbq'],\n _fbq: Object.assign(noop, {\n callMethod: noop,\n queue: [] as unknown[],\n push: noop,\n loaded: true,\n version: '2.0',\n }) as unknown as Env['window']['_fbq'],\n },\n document: {\n createElement: () =>\n ({\n src: '',\n async: false,\n setAttribute: () => {},\n removeAttribute: () => {},\n }) as unknown as Element,\n head: { appendChild: () => {} },\n },\n};\n\n// Future: error scenarios (v2)\n// export const error: Env = { ... };\n","import { getEvent } from '@walkeros/core';\n\nexport function Purchase(): unknown[] {\n const event = getEvent('order complete');\n\n return [\n 'track',\n 'Purchase',\n {\n value: event.data.total,\n currency: 'EUR',\n contents: event.nested\n .filter((item) => item.entity === 'product')\n .map((item) => ({ id: item.data.id, quantity: 1 })),\n content_type: 'product',\n num_items: 2,\n },\n { eventID: event.id },\n ];\n}\n\nexport function AddToCart(): unknown[] {\n const event = getEvent('product add');\n\n return [\n 'track',\n 'AddToCart',\n {\n currency: 'EUR',\n value: event.data.price,\n contents: [{ id: event.data.id, quantity: 1 }],\n content_type: 'product',\n },\n { eventID: event.id },\n ];\n}\n\nexport function InitiateCheckout(): unknown[] {\n const event = getEvent('cart view');\n\n return [\n 'track',\n 'InitiateCheckout',\n {\n currency: 'EUR',\n value: event.data.value,\n contents: event.nested\n .filter((entity) => entity.entity === 'product')\n .map((entity) => ({\n id: entity.data.id,\n quantity: entity.data.quantity,\n })),\n num_items: event.nested.filter((item) => item.entity === 'product')\n .length,\n },\n { eventID: event.id },\n ];\n}\n\nexport function ViewContent(): unknown[] {\n const event = getEvent('product view');\n\n return [\n 'track',\n 'ViewContent',\n {\n currency: 'EUR',\n value: event.data.price,\n contents: [{ id: event.data.id, quantity: 1 }],\n content_type: 'product',\n },\n { eventID: event.id },\n ];\n}\n","import type { Mapping, WalkerOS } from '@walkeros/core';\nimport type { DestinationMeta } from '..';\nimport { isObject } from '@walkeros/core';\n\nexport const Purchase: DestinationMeta.Rule = {\n name: 'Purchase',\n data: {\n map: {\n value: 'data.total',\n currency: { value: 'EUR' },\n contents: {\n loop: [\n 'nested',\n {\n condition: (entity) =>\n isObject(entity) && entity.entity === 'product',\n map: {\n id: 'data.id',\n quantity: { key: 'data.quantity', value: 1 },\n },\n },\n ],\n },\n content_type: { value: 'product' },\n num_items: {\n fn: (event) =>\n (event as WalkerOS.Event).nested.filter(\n (item) => item.entity === 'product',\n ).length,\n },\n },\n },\n};\n\nexport const AddToCart: DestinationMeta.Rule = {\n name: 'AddToCart',\n data: {\n map: {\n value: 'data.price',\n currency: { value: 'EUR' },\n contents: {\n set: [\n {\n map: {\n id: 'data.id',\n quantity: { key: 'data.quantity', value: 1 },\n },\n },\n ],\n },\n content_type: { value: 'product' },\n },\n },\n};\n\nexport const InitiateCheckout: DestinationMeta.Rule = {\n name: 'InitiateCheckout',\n data: {\n map: {\n value: 'data.value',\n currency: { value: 'EUR' },\n contents: {\n loop: [\n 'nested',\n {\n condition: (entity) =>\n isObject(entity) && entity.entity === 'product',\n map: {\n id: 'data.id',\n quantity: { key: 'data.quantity', value: 1 },\n },\n },\n ],\n },\n num_items: {\n fn: (event) =>\n (event as WalkerOS.Event).nested.filter(\n (item) => item.entity === 'product',\n ).length,\n },\n },\n },\n};\n\nexport const ViewContent: DestinationMeta.Rule = {\n name: 'ViewContent',\n data: {\n map: {\n value: 'data.price',\n currency: { value: 'EUR' },\n content_type: { value: 'product' },\n contents: {\n set: [\n {\n map: {\n id: 'data.id',\n quantity: { key: 'data.quantity', value: 1 },\n },\n },\n ],\n },\n },\n },\n};\n\nexport const config = {\n order: { complete: Purchase },\n product: { view: ViewContent, add: AddToCart },\n cart: { view: InitiateCheckout },\n} satisfies DestinationMeta.Rules;\n"],"mappings":";;;;;;;AACA,SAAS,cAAc;AAEhB,SAAS,UACd,KACA,MAAM,kDACN;AACA,QAAM,EAAE,UAAAA,UAAS,IAAI,OAAO,GAAG;AAC/B,QAAM,SAAUA,UAAsB,cAAc,QAAQ;AAC5D,SAAO,MAAM;AACb,SAAO,QAAQ;AACf,EAACA,UAAsB,KAAK,YAAY,MAAM;AAChD;AAWO,SAAS,MAAM,KAA0B;AAC9C,QAAM,EAAE,OAAO,IAAI,OAAO,GAAG;AAC7B,QAAM,IAAI;AAIV,MAAI,EAAE,IAAgB;AAEtB,QAAM,IAAI,YAAa,M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AC;AAAA,EAET,KAAK,EAAE,QAAAE,SAAQ,IAAI,GAAG;AACpB,UAAM,EAAE,WAAW,CAAC,GAAwB,WAAW,IAAIA;AAC3D,UAAM,EAAE,QAAQ,IAAI;AAGpB,QAAI,WAAY,WAAU,GAAG;AAG7B,QAAI,CAAC,QAAS,QAAO;AAGrB,UAAM,GAAG;AAET,UAAM,EAAE,OAAO,IAAIC,QAAO,GAAG;AAC7B,UAAM,MAAM,OAAO;AACnB,QAAI,QAAQ,OAAO;AAEnB,WAAOD;AAAA,EACT;AAAA,EAEA,KAAK,OAAO,EAAE,QAAAA,SAAQ,UAAU,CAAC,GAAG,MAAM,IAAI,GAAG;AAC/C,UAAM,EAAE,OAAO,YAAY,IAAI,QAAQ,YAAY,CAAC;AACpD,UAAM,EAAE,OAAO,IAAIC,QAAO,GAAG;AAC7B,UAAM,MAAM,OAAO;AAGnB,QAAI,MAAM,SAAS,eAAe,CAAC,QAAQ,UAAU;AAEnD,YAAM,OAAO;AAAA,IACf;AAEA,UAAM,YAAY,SAAS,eAAe,MAAM;AAEhD;AAAA,MACE,cAAc,gBAAgB;AAAA,MAC9B,OAAO,SAAS;AAAA,MAChB,EAAS,IAAI,IAAI,OAAO,CAAC;AAAA,MACzB,EAAE,SAAS,MAAM,GAAG;AAAA,IACtB;AAAA,EACF;AACF;AAEA,IAAO,gBAAQ;","names":["document","getEnv","AddToCart","InitiateCheckout","Purchase","ViewContent","Purchase","AddToCart","InitiateCheckout","ViewContent","config","getEnv"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@walkeros/web-destination-meta",
3
3
  "description": "Meta pixel web destination for walkerOS",
4
- "version": "0.1.2",
4
+ "version": "0.2.0",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.mjs",
@@ -30,7 +30,7 @@
30
30
  "update": "npx npm-check-updates -u && npm update"
31
31
  },
32
32
  "dependencies": {
33
- "@walkeros/web-core": "0.1.2"
33
+ "@walkeros/web-core": "0.2.0"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@types/facebook-pixel": "^0.0.31"