Skip to content

Commit 46835af

Browse files
eventConfig and batching
1 parent 54a3fe3 commit 46835af

File tree

2 files changed

+96
-87
lines changed

2 files changed

+96
-87
lines changed

website/docs/destinations/event_mapping.mdx

Lines changed: 86 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -16,75 +16,81 @@ export const event = getEvent('order complete');
1616
push: (event, config, mapping, options) => {
1717
return config.fn(options.data);
1818
},
19+
pushBatch: (batched, config, options) => {
20+
return config.fn(batched);
21+
}
1922
}}
2023
>
2124

22-
Mapping is used to translate walkerOS events into a required format of another
23-
tool. The mapping also defines how to process events like renaming, bundling, or
24-
ignoring them. It's also checking for consent or validating a value.
25+
Mapping is used to configure and translate walkerOS events for destinations. It
26+
defines if and how to process events, by renaming, structuring, bundling, or
27+
ignoring them. It's also checking for consent and validate values.
28+
29+
## Config
2530

26-
There are common event rules for destinations like `name` to rename an event
27-
(e.g. `product add` to `add_to_cart`) or `ignore` to not process an event at
28-
all. There are settings, that are individual for each destination (e.g. a GA4
29-
destination might require a `measurement_id` while a Meta destination requires a
30-
`pixel_id`).
31+
Besides a general destination configuration, a mapping config is set for a
32+
specific event. Therefore it is defined as
33+
`{ [entity]: { [action]: EventConfig }}`.
3134

3235
A `*` can be used to match all entities or actions and set up common rules. Each
3336
destination requires specific settings which can be configured in the `custom`
3437
section of the mapping.
3538

3639
```ts
37-
import type { Mapping } from '@elbwalker/types';
38-
39-
// @TODO UPDATE
40-
41-
const mapping: Mapping.Config = {
42-
entity: { action: {} }, // Basic structure
43-
page: {
44-
view: { name: 'pageview' }, // Rename the event name
45-
click: { data: { language: 'globals.language' } }, // Custom settings
46-
'*': { ignore: true }, // Ignore all other page events
47-
},
48-
order: { complete: { consent: { marketing: true } } }, // Require marketing consent
49-
'*': { visible: { batch: 2000 } }, // Bundle all visible events every 2 seconds
50-
};
40+
{
41+
// Config
42+
[entity]: {
43+
[action]: {
44+
// EventConfig
45+
name: "event name",
46+
data: {
47+
// ValueConfig
48+
}
49+
}
50+
}
51+
}
5152
```
5253

53-
<DestinationPush event={event} height={'666px'}>
54+
<DestinationPush event={event} height={'666px'} eventConfig={false}>
5455
{`{
55-
data: {
56-
map: {
57-
id: 'data.id',
58-
event: { fn: (e) => e.event.replace(" ", "_") },
59-
pageGroup: 'globals.pagegroup',
60-
products: {
61-
loop: ['nested', 'data.name']
62-
},
63-
user_id: {
64-
consent: { marketing: true },
65-
key: "user.id",
66-
value: "anonymous",
67-
},
68-
vip: {
69-
condition: (e) => e.data.total > 500,
70-
value: true,
71-
},
72-
journeyShopping: {
73-
key: 'context.shopping.0',
74-
validate: (value) => typeof value == "string",
75-
},
76-
timings: {
77-
set: ['timestamp', 'timing']
56+
order: {
57+
complete: {
58+
name: "purchase",
59+
data: {
60+
map: {
61+
event: "event",
62+
id: 'data.id',
63+
pageGroup: 'globals.pagegroup',
64+
quantity: { fn: (e) => e.nested.length },
65+
products: {
66+
loop: ['nested', 'data.name']
67+
},
68+
user_id: {
69+
consent: { marketing: true },
70+
key: "user.id",
71+
value: "anonymous",
72+
},
73+
vip: {
74+
condition: (e) => e.data.total > 500,
75+
value: true,
76+
},
77+
journeyShopping: {
78+
key: 'context.shopping.0',
79+
validate: (value) => typeof value == "string",
80+
},
81+
timings: {
82+
set: ['timestamp', 'timing']
83+
}
84+
}
7885
}
7986
},
87+
visible: { batch: 1000, data: "event" },
88+
'*' : { ignore: true }
8089
}
8190
}`}
8291
</DestinationPush>
8392

84-
@TODO evtl noch ein Type Baum um zu zeigen wann Config, EventConfig,
85-
ValueConfig, etc. verwendet wird.
86-
87-
# EventConfig
93+
## EventConfig
8894

8995
The `Destination.Event` mapping for each event supports standardized default
9096
options. The `custom` option can be used to set up custom properties for the
@@ -103,16 +109,13 @@ event and destination's individual settings.
103109
To disable processing of other events, add `{'*': {'*': { ignore: true }}}` to
104110
the mapping.
105111

106-
@TODO nicht nur auf event Ebene, auch auf value Ebene nutzbar.
107-
108-
@TODO It can be an array of multiple mappings. If a a condition isn't met, the
109-
next mapping will be tried. This enables the usage of multiple mappings for the
110-
same event.
112+
The destination event mapping technically uses
113+
the&nbsp;<Link to="/docs/utils/mapping">mapping utils</Link> to create the
114+
desired event structure. And
115+
the&nbsp;<Link to="/docs/utils/helper#getbypath">getByPath</Link> dot notation
116+
to access event properties (e.g. `event.data.total`).
111117

112-
@TODO it uses the&nbsp;<Link to="/docs/utils/mapping">mapping utils</Link> to
113-
create the event structure.
114-
115-
## name
118+
### name
116119

117120
The `name` property is used to rename the event. It overrides the original event
118121
name.
@@ -124,13 +127,34 @@ name.
124127
}`}
125128
</DestinationPush>
126129

127-
## data
130+
Example: A walkerOS `order complete` usually becomes a `purchase` event in GA4
131+
or an `order` event in Piwik PRO.
132+
133+
### data
134+
135+
### ignore
136+
137+
The `ignore` property is used to ignore the event.
138+
139+
### consent
140+
141+
The `consent` property is used to require a specific state to process the event.
142+
143+
### custom
144+
145+
The `custom` property is used to set up custom properties for the event and
146+
destination's individual settings.
147+
148+
### batch
149+
150+
The `batch` property is used to bundle the events before calling `pushBatch` if
151+
available.
152+
153+
## ValueConfig
128154

129155
The `data` property is used to transform the event data. It is used to create
130156
the required data structure for the destination.
131157

132-
@TODO add note: it uses byPath syntax. In short.
133-
134158
It can create any structure of data. With support for recursive data structures.
135159

136160
### key
@@ -280,24 +304,6 @@ resolved the value, it will be validated with the `validate` function.
280304
}`}
281305
</DestinationPush>
282306

283-
## ignore
284-
285-
The `ignore` property is used to ignore the event.
286-
287-
## consent
288-
289-
The `consent` property is used to require a specific state to process the event.
290-
291-
## custom
292-
293-
The `custom` property is used to set up custom properties for the event and
294-
destination's individual settings.
295-
296-
## batch
297-
298-
The `batch` property is used to bundle the events before calling `pushBatch` if
299-
available.
300-
301307
## Execution order
302308

303309
If the `data` property is an array, the mappings will be executed in the order

website/src/components/templates/destination.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import React, {
66
useMemo,
77
useState,
88
} from 'react';
9-
import { createEvent, isString } from '@elbwalker/utils';
9+
import { createEvent } from '@elbwalker/utils';
1010
import MappingConfig from '../organisms/mapping';
11-
import { formatValue, parseInput } from '../molecules/codeBox';
11+
import { formatValue } from '../molecules/codeBox';
1212
interface DestinationContextValue {
1313
customConfig: WalkerOS.AnyObject;
1414
setConfig: (config: WalkerOS.AnyObject) => void;
@@ -106,6 +106,7 @@ interface DestinationPushProps {
106106
labelLeft?: string;
107107
labelMiddle?: string;
108108
labelRight?: string;
109+
eventConfig?: boolean;
109110
}
110111

111112
export const DestinationPush: React.FC<DestinationPushProps> = ({
@@ -116,6 +117,7 @@ export const DestinationPush: React.FC<DestinationPushProps> = ({
116117
labelLeft,
117118
labelMiddle = 'Event Config',
118119
labelRight,
120+
eventConfig = true,
119121
}) => {
120122
const { customConfig, destination, fnName } = useDestinationContext();
121123
const middleValue = children ?? mapping;
@@ -130,9 +132,11 @@ export const DestinationPush: React.FC<DestinationPushProps> = ({
130132
try {
131133
const event = createEvent(left);
132134
const [entity, action] = event.event.split(' ');
133-
const finalMapping = {
134-
[entity]: { [action]: middle },
135-
};
135+
const finalMapping = eventConfig
136+
? {
137+
[entity]: { [action]: middle },
138+
}
139+
: middle;
136140

137141
destinationPush(
138142
{ hooks: {}, consent: event.consent } as never, // Fake instance
@@ -141,7 +145,7 @@ export const DestinationPush: React.FC<DestinationPushProps> = ({
141145
config: {
142146
custom: options,
143147
fn: log,
144-
mapping: finalMapping,
148+
mapping: finalMapping as Mapping.Config,
145149
},
146150
},
147151
event,
@@ -179,7 +183,6 @@ import {
179183
tryCatch,
180184
useHooks,
181185
} from '@elbwalker/utils';
182-
import { EventMapping } from '@elbwalker/types/src/mapping';
183186

184187
function resolveMappingData(
185188
event: WalkerOS.Event,

0 commit comments

Comments
 (0)