Skip to content

Commit 93a3a26

Browse files
block code
1 parent d99bc83 commit 93a3a26

File tree

1 file changed

+57
-3
lines changed

1 file changed

+57
-3
lines changed

packages/connectors/datalayer/src/mapping.ts

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ export function objToEvent(
2222
let event = `${config.prefix} ${obj.event.replace(/ /g, '_')}`;
2323
delete obj.event;
2424

25-
const source = { type: 'dataLayer' } as WalkerOS.Source;
25+
let globals: WalkerOS.Properties = {};
26+
let custom: WalkerOS.Properties = {};
27+
let user: WalkerOS.User = {};
28+
let consent: WalkerOS.Consent = {};
29+
let version = {} as WalkerOS.Version;
30+
let source = { type: 'dataLayer' } as WalkerOS.Source;
2631

2732
let props = {} as WalkerOS.Properties;
2833
let data = obj as WalkerOS.Properties;
@@ -47,12 +52,61 @@ export function objToEvent(
4752

4853
if (mapping.data)
4954
data = Object.entries(mapping.data).reduce((acc, [key, value]) => {
50-
acc[key] = getMappingValue(obj, value);
55+
if (value) acc[key] = getMappingValue(obj, value);
5156
return acc;
5257
}, {} as WalkerOS.Properties);
58+
59+
if (mapping.globals)
60+
globals = Object.entries(mapping.globals).reduce((acc, [key, value]) => {
61+
if (value) acc[key] = getMappingValue(obj, value);
62+
return acc;
63+
}, {} as WalkerOS.Properties);
64+
65+
if (mapping.custom)
66+
custom = Object.entries(mapping.custom).reduce((acc, [key, value]) => {
67+
if (value) acc[key] = getMappingValue(obj, value);
68+
return acc;
69+
}, {} as WalkerOS.Properties);
70+
71+
if (mapping.user)
72+
user = Object.entries(mapping.user).reduce((acc, [key, value]) => {
73+
if (value) acc[key] = getMappingValue(obj, value);
74+
return acc;
75+
}, {} as WalkerOS.Properties);
76+
77+
if (mapping.consent)
78+
consent = Object.entries(mapping.consent).reduce((acc, [key, value]) => {
79+
if (value) acc[key] = !!getMappingValue(obj, value);
80+
return acc;
81+
}, {} as WalkerOS.Consent);
82+
83+
if (mapping.version) {
84+
version = Object.entries(mapping.version).reduce((acc, [key, value]) => {
85+
if (value) acc[key] = getMappingValue(obj, value);
86+
return acc;
87+
}, {} as WalkerOS.Version);
88+
}
89+
90+
if (mapping.source) {
91+
source = Object.entries(mapping.source).reduce((acc, [key, value]) => {
92+
if (value) acc[key] = getMappingValue(obj, value);
93+
return acc;
94+
}, {} as WalkerOS.Source);
95+
}
5396
}
5497

55-
return { ...props, event, id, data, source };
98+
return {
99+
...props,
100+
event,
101+
globals,
102+
custom,
103+
user,
104+
consent,
105+
id,
106+
data,
107+
version,
108+
source,
109+
};
56110
}
57111

58112
// https://developers.google.com/tag-platform/gtagjs/reference

0 commit comments

Comments
 (0)