@walkeros/web-destination-gtag 0.1.1 → 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 +56 -2
- package/dist/examples/index.d.mts +40 -11
- package/dist/examples/index.d.ts +40 -11
- package/dist/examples/index.js +77 -34
- package/dist/examples/index.mjs +76 -34
- package/dist/index.browser.js +1 -1
- package/dist/index.d.mts +53 -9
- package/dist/index.d.ts +53 -9
- package/dist/index.es5.js +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -2
package/README.md
CHANGED
|
@@ -28,10 +28,10 @@ npm install @walkeros/web-destination-gtag
|
|
|
28
28
|
## Usage
|
|
29
29
|
|
|
30
30
|
```typescript
|
|
31
|
-
import {
|
|
31
|
+
import { startFlow } from '@walkeros/collector';
|
|
32
32
|
import { destinationGtag } from '@walkeros/web-destination-gtag';
|
|
33
33
|
|
|
34
|
-
const { elb } = await
|
|
34
|
+
const { elb } = await startFlow();
|
|
35
35
|
|
|
36
36
|
elb('walker destination', destinationGtag, {
|
|
37
37
|
settings: {
|
|
@@ -66,6 +66,60 @@ For custom event mapping (`mapping.entity.action.settings`):
|
|
|
66
66
|
| `ads` | `AdsMapping` | Google Ads specific event mapping configuration | No | `{ label: 'conversion_label' }` |
|
|
67
67
|
| `gtm` | `GTMMapping` | GTM specific event mapping configuration | No | `{}` |
|
|
68
68
|
|
|
69
|
+
## Consent Mode
|
|
70
|
+
|
|
71
|
+
The gtag destination automatically handles Google Consent Mode v2 with a "deny
|
|
72
|
+
by default" approach. Configure consent mode using the `como` setting:
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
import { destinationGtag } from '@walkeros/web-destination-gtag';
|
|
76
|
+
|
|
77
|
+
const destination = destinationGtag({
|
|
78
|
+
settings: {
|
|
79
|
+
como: true, // Enable with default mapping
|
|
80
|
+
ga4: { measurementId: 'G-XXXXXXXXXX' },
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Configuration Options
|
|
86
|
+
|
|
87
|
+
| Value | Description | Default Mapping |
|
|
88
|
+
| -------- | -------------------- | ------------------------------------------------------------------------------------------------------ |
|
|
89
|
+
| `false` | Disable consent mode | - |
|
|
90
|
+
| `true` | Use default mapping | `marketing` → `ad_storage`, `ad_user_data`, `ad_personalization`<br>`functional` → `analytics_storage` |
|
|
91
|
+
| `object` | Custom mapping | `{ [walkerOSGroup]: gtagParameter \| gtagParameter[] }` |
|
|
92
|
+
|
|
93
|
+
### Custom Mapping
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
const destination = destinationGtag({
|
|
97
|
+
settings: {
|
|
98
|
+
como: {
|
|
99
|
+
marketing: ['ad_storage', 'ad_personalization'],
|
|
100
|
+
analytics: 'analytics_storage',
|
|
101
|
+
},
|
|
102
|
+
ga4: { measurementId: 'G-XXXXXXXXXX' },
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Usage
|
|
108
|
+
|
|
109
|
+
Consent mode automatically activates when you send consent events through
|
|
110
|
+
walkerOS:
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
// Grant consent
|
|
114
|
+
elb('walker consent', { marketing: true, functional: true });
|
|
115
|
+
|
|
116
|
+
// Deny consent
|
|
117
|
+
elb('walker consent', { marketing: false, functional: false });
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
The destination handles all gtag consent calls automatically, ensuring
|
|
121
|
+
compliance with privacy regulations.
|
|
122
|
+
|
|
69
123
|
## Examples
|
|
70
124
|
|
|
71
125
|
### E-commerce Purchase
|
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
import { Mapping as Mapping$1 } from '@walkeros/core';
|
|
2
|
-
|
|
3
|
-
declare function ga4Purchase$1(): unknown[];
|
|
4
|
-
declare function ga4AddToCart$1(): unknown[];
|
|
5
|
-
declare function adsConversion$1(): unknown[];
|
|
6
|
-
declare function gtmEvent(): Record<string, unknown>;
|
|
7
|
-
|
|
8
|
-
declare const events_gtmEvent: typeof gtmEvent;
|
|
9
|
-
declare namespace events {
|
|
10
|
-
export { adsConversion$1 as adsConversion, ga4AddToCart$1 as ga4AddToCart, ga4Purchase$1 as ga4Purchase, events_gtmEvent as gtmEvent };
|
|
11
|
-
}
|
|
2
|
+
import { DestinationWeb } from '@walkeros/web-core';
|
|
12
3
|
|
|
13
4
|
declare global {
|
|
14
5
|
interface Window {
|
|
@@ -16,6 +7,23 @@ declare global {
|
|
|
16
7
|
[key: string]: unknown;
|
|
17
8
|
}
|
|
18
9
|
}
|
|
10
|
+
interface Env extends DestinationWeb.Env {
|
|
11
|
+
window: {
|
|
12
|
+
gtag: Gtag.Gtag;
|
|
13
|
+
dataLayer: unknown[];
|
|
14
|
+
};
|
|
15
|
+
document: {
|
|
16
|
+
createElement: (tagName: string) => {
|
|
17
|
+
src: string;
|
|
18
|
+
async?: boolean;
|
|
19
|
+
setAttribute: (name: string, value: string) => void;
|
|
20
|
+
removeAttribute: (name: string) => void;
|
|
21
|
+
};
|
|
22
|
+
head: {
|
|
23
|
+
appendChild: (node: unknown) => void;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
}
|
|
19
27
|
interface AdsMapping {
|
|
20
28
|
label?: string;
|
|
21
29
|
}
|
|
@@ -32,6 +40,27 @@ interface GTMMapping {
|
|
|
32
40
|
type Rule = Mapping$1.Rule<Mapping>;
|
|
33
41
|
type Include = Array<'all' | 'context' | 'data' | 'event' | 'globals' | 'source' | 'user' | 'version'>;
|
|
34
42
|
|
|
43
|
+
declare const init: Env | undefined;
|
|
44
|
+
declare const push: Env;
|
|
45
|
+
declare const simulation: string[];
|
|
46
|
+
|
|
47
|
+
declare const env_init: typeof init;
|
|
48
|
+
declare const env_push: typeof push;
|
|
49
|
+
declare const env_simulation: typeof simulation;
|
|
50
|
+
declare namespace env {
|
|
51
|
+
export { env_init as init, env_push as push, env_simulation as simulation };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
declare function ga4Purchase$1(): unknown[];
|
|
55
|
+
declare function ga4AddToCart$1(): unknown[];
|
|
56
|
+
declare function adsConversion$1(): unknown[];
|
|
57
|
+
declare function gtmEvent(): Record<string, unknown>;
|
|
58
|
+
|
|
59
|
+
declare const events_gtmEvent: typeof gtmEvent;
|
|
60
|
+
declare namespace events {
|
|
61
|
+
export { adsConversion$1 as adsConversion, ga4AddToCart$1 as ga4AddToCart, ga4Purchase$1 as ga4Purchase, events_gtmEvent as gtmEvent };
|
|
62
|
+
}
|
|
63
|
+
|
|
35
64
|
declare const ga4Purchase: Rule;
|
|
36
65
|
declare const ga4AddToCart: Rule;
|
|
37
66
|
declare const adsConversion: Rule;
|
|
@@ -57,4 +86,4 @@ declare namespace mapping {
|
|
|
57
86
|
export { mapping_adsConversion as adsConversion, mapping_combinedPurchase as combinedPurchase, mapping_config as config, mapping_ga4AddToCart as ga4AddToCart, mapping_ga4Purchase as ga4Purchase, mapping_gtmProductView as gtmProductView };
|
|
58
87
|
}
|
|
59
88
|
|
|
60
|
-
export { events, mapping };
|
|
89
|
+
export { env, events, mapping };
|
package/dist/examples/index.d.ts
CHANGED
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
import { Mapping as Mapping$1 } from '@walkeros/core';
|
|
2
|
-
|
|
3
|
-
declare function ga4Purchase$1(): unknown[];
|
|
4
|
-
declare function ga4AddToCart$1(): unknown[];
|
|
5
|
-
declare function adsConversion$1(): unknown[];
|
|
6
|
-
declare function gtmEvent(): Record<string, unknown>;
|
|
7
|
-
|
|
8
|
-
declare const events_gtmEvent: typeof gtmEvent;
|
|
9
|
-
declare namespace events {
|
|
10
|
-
export { adsConversion$1 as adsConversion, ga4AddToCart$1 as ga4AddToCart, ga4Purchase$1 as ga4Purchase, events_gtmEvent as gtmEvent };
|
|
11
|
-
}
|
|
2
|
+
import { DestinationWeb } from '@walkeros/web-core';
|
|
12
3
|
|
|
13
4
|
declare global {
|
|
14
5
|
interface Window {
|
|
@@ -16,6 +7,23 @@ declare global {
|
|
|
16
7
|
[key: string]: unknown;
|
|
17
8
|
}
|
|
18
9
|
}
|
|
10
|
+
interface Env extends DestinationWeb.Env {
|
|
11
|
+
window: {
|
|
12
|
+
gtag: Gtag.Gtag;
|
|
13
|
+
dataLayer: unknown[];
|
|
14
|
+
};
|
|
15
|
+
document: {
|
|
16
|
+
createElement: (tagName: string) => {
|
|
17
|
+
src: string;
|
|
18
|
+
async?: boolean;
|
|
19
|
+
setAttribute: (name: string, value: string) => void;
|
|
20
|
+
removeAttribute: (name: string) => void;
|
|
21
|
+
};
|
|
22
|
+
head: {
|
|
23
|
+
appendChild: (node: unknown) => void;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
}
|
|
19
27
|
interface AdsMapping {
|
|
20
28
|
label?: string;
|
|
21
29
|
}
|
|
@@ -32,6 +40,27 @@ interface GTMMapping {
|
|
|
32
40
|
type Rule = Mapping$1.Rule<Mapping>;
|
|
33
41
|
type Include = Array<'all' | 'context' | 'data' | 'event' | 'globals' | 'source' | 'user' | 'version'>;
|
|
34
42
|
|
|
43
|
+
declare const init: Env | undefined;
|
|
44
|
+
declare const push: Env;
|
|
45
|
+
declare const simulation: string[];
|
|
46
|
+
|
|
47
|
+
declare const env_init: typeof init;
|
|
48
|
+
declare const env_push: typeof push;
|
|
49
|
+
declare const env_simulation: typeof simulation;
|
|
50
|
+
declare namespace env {
|
|
51
|
+
export { env_init as init, env_push as push, env_simulation as simulation };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
declare function ga4Purchase$1(): unknown[];
|
|
55
|
+
declare function ga4AddToCart$1(): unknown[];
|
|
56
|
+
declare function adsConversion$1(): unknown[];
|
|
57
|
+
declare function gtmEvent(): Record<string, unknown>;
|
|
58
|
+
|
|
59
|
+
declare const events_gtmEvent: typeof gtmEvent;
|
|
60
|
+
declare namespace events {
|
|
61
|
+
export { adsConversion$1 as adsConversion, ga4AddToCart$1 as ga4AddToCart, ga4Purchase$1 as ga4Purchase, events_gtmEvent as gtmEvent };
|
|
62
|
+
}
|
|
63
|
+
|
|
35
64
|
declare const ga4Purchase: Rule;
|
|
36
65
|
declare const ga4AddToCart: Rule;
|
|
37
66
|
declare const adsConversion: Rule;
|
|
@@ -57,4 +86,4 @@ declare namespace mapping {
|
|
|
57
86
|
export { mapping_adsConversion as adsConversion, mapping_combinedPurchase as combinedPurchase, mapping_config as config, mapping_ga4AddToCart as ga4AddToCart, mapping_ga4Purchase as ga4Purchase, mapping_gtmProductView as gtmProductView };
|
|
58
87
|
}
|
|
59
88
|
|
|
60
|
-
export { events, mapping };
|
|
89
|
+
export { env, events, mapping };
|
package/dist/examples/index.js
CHANGED
|
@@ -20,11 +20,62 @@ 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
|
+
simulation: () => simulation
|
|
35
|
+
});
|
|
36
|
+
var noop = () => {
|
|
37
|
+
};
|
|
38
|
+
var init = {
|
|
39
|
+
window: {
|
|
40
|
+
gtag: void 0,
|
|
41
|
+
dataLayer: []
|
|
42
|
+
},
|
|
43
|
+
document: {
|
|
44
|
+
createElement: () => ({
|
|
45
|
+
src: "",
|
|
46
|
+
setAttribute: () => {
|
|
47
|
+
},
|
|
48
|
+
removeAttribute: () => {
|
|
49
|
+
}
|
|
50
|
+
}),
|
|
51
|
+
head: { appendChild: () => {
|
|
52
|
+
} }
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
var push = {
|
|
56
|
+
window: {
|
|
57
|
+
gtag: Object.assign(noop, {
|
|
58
|
+
// Add any gtag-specific properties if needed
|
|
59
|
+
}),
|
|
60
|
+
dataLayer: []
|
|
61
|
+
},
|
|
62
|
+
document: {
|
|
63
|
+
createElement: () => ({
|
|
64
|
+
src: "",
|
|
65
|
+
setAttribute: () => {
|
|
66
|
+
},
|
|
67
|
+
removeAttribute: () => {
|
|
68
|
+
}
|
|
69
|
+
}),
|
|
70
|
+
head: { appendChild: () => {
|
|
71
|
+
} }
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
var simulation = [
|
|
75
|
+
"call:window.gtag"
|
|
76
|
+
// Track gtag function calls
|
|
77
|
+
];
|
|
78
|
+
|
|
28
79
|
// src/examples/events.ts
|
|
29
80
|
var events_exports = {};
|
|
30
81
|
__export(events_exports, {
|
|
@@ -35,47 +86,38 @@ __export(events_exports, {
|
|
|
35
86
|
});
|
|
36
87
|
|
|
37
88
|
// ../../../core/dist/index.mjs
|
|
38
|
-
var
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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;
|
|
89
|
+
var m = { merge: true, shallow: true, extend: true };
|
|
90
|
+
function y(e, t = {}, n = {}) {
|
|
91
|
+
n = { ...m, ...n };
|
|
92
|
+
const r = Object.entries(t).reduce((t2, [r2, o]) => {
|
|
93
|
+
const i = e[r2];
|
|
94
|
+
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
95
|
}, {});
|
|
53
|
-
return
|
|
96
|
+
return n.shallow ? { ...e, ...r } : (Object.assign(e, r), e);
|
|
54
97
|
}
|
|
55
|
-
function
|
|
56
|
-
return Array.isArray(
|
|
98
|
+
function b(e) {
|
|
99
|
+
return Array.isArray(e);
|
|
57
100
|
}
|
|
58
|
-
function
|
|
59
|
-
return "object" == typeof
|
|
101
|
+
function O(e) {
|
|
102
|
+
return "object" == typeof e && null !== e && !b(e) && "[object Object]" === Object.prototype.toString.call(e);
|
|
60
103
|
}
|
|
61
|
-
|
|
62
|
-
function V(e2 = {}) {
|
|
104
|
+
function C(e = {}) {
|
|
63
105
|
var _a;
|
|
64
|
-
const
|
|
65
|
-
if (
|
|
66
|
-
const [
|
|
67
|
-
|
|
106
|
+
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 });
|
|
107
|
+
if (e.name) {
|
|
108
|
+
const [t2, n2] = (_a = e.name.split(" ")) != null ? _a : [];
|
|
109
|
+
t2 && n2 && (o.entity = t2, o.action = n2);
|
|
68
110
|
}
|
|
69
111
|
return o;
|
|
70
112
|
}
|
|
71
|
-
function
|
|
72
|
-
const
|
|
73
|
-
return
|
|
113
|
+
function _(e = "entity action", t = {}) {
|
|
114
|
+
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 } };
|
|
115
|
+
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
116
|
}
|
|
75
117
|
|
|
76
118
|
// src/examples/events.ts
|
|
77
119
|
function ga4Purchase() {
|
|
78
|
-
const event =
|
|
120
|
+
const event = _("order complete");
|
|
79
121
|
return [
|
|
80
122
|
"event",
|
|
81
123
|
"purchase",
|
|
@@ -95,7 +137,7 @@ function ga4Purchase() {
|
|
|
95
137
|
];
|
|
96
138
|
}
|
|
97
139
|
function ga4AddToCart() {
|
|
98
|
-
const event =
|
|
140
|
+
const event = _("product add");
|
|
99
141
|
return [
|
|
100
142
|
"event",
|
|
101
143
|
"add_to_cart",
|
|
@@ -114,7 +156,7 @@ function ga4AddToCart() {
|
|
|
114
156
|
];
|
|
115
157
|
}
|
|
116
158
|
function adsConversion() {
|
|
117
|
-
const event =
|
|
159
|
+
const event = _("order complete");
|
|
118
160
|
return [
|
|
119
161
|
"event",
|
|
120
162
|
"conversion",
|
|
@@ -127,7 +169,7 @@ function adsConversion() {
|
|
|
127
169
|
];
|
|
128
170
|
}
|
|
129
171
|
function gtmEvent() {
|
|
130
|
-
const event =
|
|
172
|
+
const event = _("product view");
|
|
131
173
|
return {
|
|
132
174
|
event: "product_view",
|
|
133
175
|
product_id: event.data.id,
|
|
@@ -166,7 +208,7 @@ var ga4Purchase2 = {
|
|
|
166
208
|
loop: [
|
|
167
209
|
"nested",
|
|
168
210
|
{
|
|
169
|
-
condition: (entity) =>
|
|
211
|
+
condition: (entity) => O(entity) && entity.entity === "product",
|
|
170
212
|
map: {
|
|
171
213
|
item_id: "data.id",
|
|
172
214
|
item_name: "data.name",
|
|
@@ -253,7 +295,7 @@ var combinedPurchase = {
|
|
|
253
295
|
loop: [
|
|
254
296
|
"nested",
|
|
255
297
|
{
|
|
256
|
-
condition: (entity) =>
|
|
298
|
+
condition: (entity) => O(entity) && entity.entity === "product",
|
|
257
299
|
map: {
|
|
258
300
|
item_id: "data.id",
|
|
259
301
|
item_name: "data.name",
|
|
@@ -274,6 +316,7 @@ var config = {
|
|
|
274
316
|
};
|
|
275
317
|
// Annotate the CommonJS export names for ESM import in node:
|
|
276
318
|
0 && (module.exports = {
|
|
319
|
+
env,
|
|
277
320
|
events,
|
|
278
321
|
mapping
|
|
279
322
|
});
|
package/dist/examples/index.mjs
CHANGED
|
@@ -4,6 +4,56 @@ 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
|
+
simulation: () => simulation
|
|
13
|
+
});
|
|
14
|
+
var noop = () => {
|
|
15
|
+
};
|
|
16
|
+
var init = {
|
|
17
|
+
window: {
|
|
18
|
+
gtag: void 0,
|
|
19
|
+
dataLayer: []
|
|
20
|
+
},
|
|
21
|
+
document: {
|
|
22
|
+
createElement: () => ({
|
|
23
|
+
src: "",
|
|
24
|
+
setAttribute: () => {
|
|
25
|
+
},
|
|
26
|
+
removeAttribute: () => {
|
|
27
|
+
}
|
|
28
|
+
}),
|
|
29
|
+
head: { appendChild: () => {
|
|
30
|
+
} }
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var push = {
|
|
34
|
+
window: {
|
|
35
|
+
gtag: Object.assign(noop, {
|
|
36
|
+
// Add any gtag-specific properties if needed
|
|
37
|
+
}),
|
|
38
|
+
dataLayer: []
|
|
39
|
+
},
|
|
40
|
+
document: {
|
|
41
|
+
createElement: () => ({
|
|
42
|
+
src: "",
|
|
43
|
+
setAttribute: () => {
|
|
44
|
+
},
|
|
45
|
+
removeAttribute: () => {
|
|
46
|
+
}
|
|
47
|
+
}),
|
|
48
|
+
head: { appendChild: () => {
|
|
49
|
+
} }
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
var simulation = [
|
|
53
|
+
"call:window.gtag"
|
|
54
|
+
// Track gtag function calls
|
|
55
|
+
];
|
|
56
|
+
|
|
7
57
|
// src/examples/events.ts
|
|
8
58
|
var events_exports = {};
|
|
9
59
|
__export(events_exports, {
|
|
@@ -14,47 +64,38 @@ __export(events_exports, {
|
|
|
14
64
|
});
|
|
15
65
|
|
|
16
66
|
// ../../../core/dist/index.mjs
|
|
17
|
-
var
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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;
|
|
67
|
+
var m = { merge: true, shallow: true, extend: true };
|
|
68
|
+
function y(e, t = {}, n = {}) {
|
|
69
|
+
n = { ...m, ...n };
|
|
70
|
+
const r = Object.entries(t).reduce((t2, [r2, o]) => {
|
|
71
|
+
const i = e[r2];
|
|
72
|
+
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
73
|
}, {});
|
|
32
|
-
return
|
|
74
|
+
return n.shallow ? { ...e, ...r } : (Object.assign(e, r), e);
|
|
33
75
|
}
|
|
34
|
-
function
|
|
35
|
-
return Array.isArray(
|
|
76
|
+
function b(e) {
|
|
77
|
+
return Array.isArray(e);
|
|
36
78
|
}
|
|
37
|
-
function
|
|
38
|
-
return "object" == typeof
|
|
79
|
+
function O(e) {
|
|
80
|
+
return "object" == typeof e && null !== e && !b(e) && "[object Object]" === Object.prototype.toString.call(e);
|
|
39
81
|
}
|
|
40
|
-
|
|
41
|
-
function V(e2 = {}) {
|
|
82
|
+
function C(e = {}) {
|
|
42
83
|
var _a;
|
|
43
|
-
const
|
|
44
|
-
if (
|
|
45
|
-
const [
|
|
46
|
-
|
|
84
|
+
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 });
|
|
85
|
+
if (e.name) {
|
|
86
|
+
const [t2, n2] = (_a = e.name.split(" ")) != null ? _a : [];
|
|
87
|
+
t2 && n2 && (o.entity = t2, o.action = n2);
|
|
47
88
|
}
|
|
48
89
|
return o;
|
|
49
90
|
}
|
|
50
|
-
function
|
|
51
|
-
const
|
|
52
|
-
return
|
|
91
|
+
function _(e = "entity action", t = {}) {
|
|
92
|
+
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 } };
|
|
93
|
+
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
94
|
}
|
|
54
95
|
|
|
55
96
|
// src/examples/events.ts
|
|
56
97
|
function ga4Purchase() {
|
|
57
|
-
const event =
|
|
98
|
+
const event = _("order complete");
|
|
58
99
|
return [
|
|
59
100
|
"event",
|
|
60
101
|
"purchase",
|
|
@@ -74,7 +115,7 @@ function ga4Purchase() {
|
|
|
74
115
|
];
|
|
75
116
|
}
|
|
76
117
|
function ga4AddToCart() {
|
|
77
|
-
const event =
|
|
118
|
+
const event = _("product add");
|
|
78
119
|
return [
|
|
79
120
|
"event",
|
|
80
121
|
"add_to_cart",
|
|
@@ -93,7 +134,7 @@ function ga4AddToCart() {
|
|
|
93
134
|
];
|
|
94
135
|
}
|
|
95
136
|
function adsConversion() {
|
|
96
|
-
const event =
|
|
137
|
+
const event = _("order complete");
|
|
97
138
|
return [
|
|
98
139
|
"event",
|
|
99
140
|
"conversion",
|
|
@@ -106,7 +147,7 @@ function adsConversion() {
|
|
|
106
147
|
];
|
|
107
148
|
}
|
|
108
149
|
function gtmEvent() {
|
|
109
|
-
const event =
|
|
150
|
+
const event = _("product view");
|
|
110
151
|
return {
|
|
111
152
|
event: "product_view",
|
|
112
153
|
product_id: event.data.id,
|
|
@@ -145,7 +186,7 @@ var ga4Purchase2 = {
|
|
|
145
186
|
loop: [
|
|
146
187
|
"nested",
|
|
147
188
|
{
|
|
148
|
-
condition: (entity) =>
|
|
189
|
+
condition: (entity) => O(entity) && entity.entity === "product",
|
|
149
190
|
map: {
|
|
150
191
|
item_id: "data.id",
|
|
151
192
|
item_name: "data.name",
|
|
@@ -232,7 +273,7 @@ var combinedPurchase = {
|
|
|
232
273
|
loop: [
|
|
233
274
|
"nested",
|
|
234
275
|
{
|
|
235
|
-
condition: (entity) =>
|
|
276
|
+
condition: (entity) => O(entity) && entity.entity === "product",
|
|
236
277
|
map: {
|
|
237
278
|
item_id: "data.id",
|
|
238
279
|
item_name: "data.name",
|
|
@@ -252,6 +293,7 @@ var config = {
|
|
|
252
293
|
}
|
|
253
294
|
};
|
|
254
295
|
export {
|
|
296
|
+
env_exports as env,
|
|
255
297
|
events_exports as events,
|
|
256
298
|
mapping_exports as mapping
|
|
257
299
|
};
|