Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b840587

Browse files
committedApr 12, 2025·
example
1 parent 2d53b11 commit b840587

File tree

6 files changed

+130
-94
lines changed

6 files changed

+130
-94
lines changed
 

‎website/docs/getting_started/event-model.mdx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ static, their content can be defined dynamically with different value types.
7070
// All nested entities within the main entity
7171
{ type: 'github', data: { repo: 'walkerOS' } },
7272
],
73-
consent: { functional: true }, // Status of the granted consent state(s)
74-
id: '1647261462000-01b5e2-5', // Timestamp, group & count of the event
73+
consent: { functional: true, marketing: true }, // Status of the granted consent state(s)
74+
id: '1647261462000-01b5e2-2', // Timestamp, group & count of the event
7575
trigger: 'visible', // Name of the trigger that fired
7676
entity: 'promotion', // The entity name involved in the event
7777
action: 'view', // The specific action performed on the entity
@@ -120,20 +120,21 @@ is a `page view`, `session start`, `product visible`, or `order complete`.
120120

121121
<Link to="/docs/sources/walkerjs/tagging#data">Data properties</Link>
122122
describe the entity in **more detail**. Depending on the entity (e.g. _product_,
123-
_order_, _content_) they can vary and provide specific insights relevant to the interaction.
123+
_order_, _content_) they can vary and provide specific insights relevant to the
124+
interaction.
124125

125126
### Context
126127

127-
<Link to="/docs/sources/walkerjs/tagging#context">Context</Link> refers to the **state**
128-
or **environment** in which the event was triggered. It could be as simple as a page
129-
position or as complex as the logical stage in a user journey, like a shopping journey
130-
from inspiration to checkout stage.
128+
<Link to="/docs/sources/walkerjs/tagging#context">Context</Link> refers to the
129+
**state** or **environment** in which the event was triggered. It could be as
130+
simple as a page position or as complex as the logical stage in a user journey,
131+
like a shopping journey from inspiration to checkout stage.
131132

132133
### Globals
133134

134-
<Link to="/docs/sources/walkerjs/tagging#globals">Globals</Link> describe the **overall
135-
state** influencing events or user behavior. These might include the theme used,
136-
page type for web, or cart value.
135+
<Link to="/docs/sources/walkerjs/tagging#globals">Globals</Link> describe the
136+
**overall state** influencing events or user behavior. These might include the
137+
theme used, page type for web, or cart value.
137138

138139
### Custom
139140

@@ -177,9 +178,9 @@ interface User extends Properties {
177178

178179
### Consent
179180

180-
<Link to="/docs/consent_management/overview">Consent</Link> captures the **permissions
181-
granted** by the user, which is crucial for subsequent data processing and helpful
182-
to comply with privacy regulations.
181+
<Link to="/docs/consent_management/overview">Consent</Link> captures the
182+
**permissions granted** by the user, which is crucial for subsequent data
183+
processing and helpful to comply with privacy regulations.
183184

184185
### Source
185186

‎website/src/components/molecules/codeBox.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,7 @@ const CodeBox: React.FC<CodeBoxProps> = ({
156156
: formattedValue.replace(/^return\s+/, '').replace(/[\r\n]+$/, '');
157157

158158
// Clean up the formatted value
159-
finalValue = finalValue
160-
.trim()
161-
.replace(/^\(|\)$/g, ''); // Remove parentheses
159+
finalValue = finalValue.trim().replace(/^\(|\)$/g, ''); // Remove parentheses
162160

163161
// Only remove indentation if it looks like HTML
164162
if (finalValue.match(/<[^>]+>/)) {

‎website/src/components/molecules/preview.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export const Preview: FC<PreviewProps> = ({
6969
initPreview(previewRef.current);
7070
},
7171
200,
72-
false,
72+
true,
7373
),
7474
[initPreview],
7575
);
@@ -148,4 +148,4 @@ export const Preview: FC<PreviewProps> = ({
148148
);
149149
};
150150

151-
export default Preview;
151+
export default Preview;

‎website/src/components/organisms/eventFlow.tsx

Lines changed: 85 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,114 @@
1-
import { FC, useCallback, useEffect, useState } from 'react';
1+
import { FC, useCallback, useEffect, useRef, useState } from 'react';
22
import type { Mapping, WalkerOS } from '@elbwalker/types';
3-
import type { DestinationWeb } from '@elbwalker/walker.js';
4-
import { elb } from '@elbwalker/walker.js';
5-
import CodeBox from '@site/src/components/molecules/codeBox';
3+
import CodeBox, { formatValue } from '@site/src/components/molecules/codeBox';
64
import Preview from '@site/src/components/molecules/preview';
75
import FullScreenMode from '@site/src/components/organisms/fullScreenMode';
8-
import {
9-
resetTypewriter,
10-
TypewriterOptions,
11-
} from '@site/src/components/molecules/typewriterCode';
126
import { parseInput } from '@site/src/components/molecules/codeBox';
137
import '@site/src/css/highlighting.scss';
14-
import { destinationPush } from '@elbwalker/utils';
8+
import {
9+
destinationPush,
10+
debounce,
11+
isString,
12+
tryCatchAsync,
13+
} from '@elbwalker/utils';
1514
import { taggingRegistry } from './tagging';
1615

1716
interface EventFlowProps {
1817
code: string;
18+
mapping?: Mapping.Config;
1919
height?: string;
2020
previewId?: string;
21-
fn?: (event: WalkerOS.Event) => WalkerOS.Event;
22-
typewriter?: TypewriterOptions;
23-
destination: DestinationWeb.Destination;
24-
initialConfig?: WalkerOS.AnyObject;
25-
fnName?: string;
21+
eventFn?: (event: WalkerOS.Event) => WalkerOS.Event;
22+
resultFn?: (output: unknown) => string;
2623
}
2724

2825
export const EventFlow: FC<EventFlowProps> = ({
2926
code,
27+
mapping,
3028
height = '400px',
3129
previewId = 'preview',
32-
fn,
33-
typewriter,
34-
destination,
35-
initialConfig = {},
36-
fnName,
30+
eventFn,
31+
resultFn,
3732
}) => {
3833
const [htmlCode, setHtmlCode] = useState(code.trim());
39-
const [eventCode, setEventCode] = useState<string>('');
40-
const [mappingCode, setMappingCode] = useState<string>('');
41-
const [commandCode, setCommandCode] = useState<string>('');
42-
const [isPaused, setIsPaused] = useState(false);
43-
const [customConfig, setConfig] = useState<WalkerOS.AnyObject>(initialConfig);
44-
const [currentEvent, setCurrentEvent] = useState<WalkerOS.Event | null>(null);
34+
const [eventCode, setEventCode] = useState<string>(undefined);
35+
const [mappingCode, setMappingCode] = useState<string | undefined>(
36+
isString(mapping) ? mapping : formatValue(mapping),
37+
);
38+
const [resultCode, setResultCode] = useState<string>('');
4539

4640
useEffect(() => {
47-
setEventCode('');
48-
setCommandCode('');
41+
setEventCode(undefined);
42+
setResultCode('');
4943
}, [htmlCode]);
5044

45+
const updateHtmlCode = useCallback(debounce(setHtmlCode, 600, true), []);
46+
47+
const updateEventCode = useCallback(
48+
debounce(
49+
(code: string) => {
50+
setEventCode(code);
51+
},
52+
1,
53+
true,
54+
),
55+
[],
56+
);
57+
const updateMappingCode = useCallback(
58+
debounce(
59+
(code: string) => {
60+
setMappingCode(parseInput(code));
61+
},
62+
600,
63+
true,
64+
),
65+
[],
66+
);
67+
68+
const createResult = useRef(
69+
debounce(async (eventStr: string, mappingStr: string) => {
70+
tryCatchAsync(
71+
async () => {
72+
if (!eventStr) return;
73+
74+
const event = parseInput(eventStr);
75+
const mapping = parseInput(mappingStr);
76+
await destinationPush(
77+
{ hooks: {}, consent: event.consent || {} } as never, // Fake instance
78+
{
79+
push: (event, config, mapping, options) => {
80+
const value = options.data || event;
81+
82+
setResultCode(formatValue(resultFn ? resultFn(value) : value));
83+
},
84+
config: {
85+
mapping,
86+
},
87+
},
88+
{ ...event },
89+
);
90+
},
91+
(err) => {
92+
setResultCode(formatValue({ error: String(err) }));
93+
},
94+
)();
95+
}, 600),
96+
).current;
97+
98+
useEffect(() => {
99+
createResult(eventCode, mappingCode);
100+
}, [eventCode, mappingCode]);
101+
51102
useEffect(() => {
52103
taggingRegistry.add(previewId, (event) => {
53104
delete event.context.previewId;
54-
const processedEvent = fn ? fn(event) : event;
55-
setCurrentEvent(processedEvent);
56-
setEventCode(JSON.stringify(processedEvent, null, 2));
105+
updateEventCode(JSON.stringify(eventFn ? eventFn(event) : event));
57106
});
58107

59108
return () => {
60109
taggingRegistry.delete(previewId);
61110
};
62-
}, [previewId, fn]);
111+
}, [previewId]);
63112

64113
const boxClassNames = `flex-1 resize flex flex-col max-h-96 lg:max-h-full`;
65114

@@ -77,11 +126,8 @@ export const EventFlow: FC<EventFlowProps> = ({
77126
showReset={true}
78127
onReset={() => {
79128
setHtmlCode(code.trim());
80-
resetTypewriter();
81-
setIsPaused(false);
82129
}}
83130
className={boxClassNames}
84-
typewriter={typewriter}
85131
/>
86132
</div>
87133

@@ -97,43 +143,25 @@ export const EventFlow: FC<EventFlowProps> = ({
97143
<CodeBox
98144
label="Event"
99145
value={eventCode || 'No event yet.'}
100-
disabled={true}
146+
onChange={setEventCode}
101147
isConsole={true}
102148
className={boxClassNames}
103-
showReset={true}
104-
onReset={() => setEventCode('')}
105149
/>
106150
</div>
107151

108152
<div className="w-1/3 flex-shrink-0 snap-start">
109153
<CodeBox
110154
label="Mapping"
111-
value={`{
112-
"product": {
113-
"view": {
114-
"name": "product.name",
115-
"price": "product.price"
116-
}
117-
}
118-
}`}
119-
onChange={() => {}}
155+
value={formatValue(mappingCode)}
156+
onChange={setMappingCode}
120157
className={boxClassNames}
121158
/>
122159
</div>
123160

124161
<div className="w-1/3 flex-shrink-0 snap-start">
125162
<CodeBox
126-
label="Command"
127-
value={`{
128-
"event": "product view",
129-
"data": {
130-
"name": "Everyday Ruck Snack",
131-
"price": 2.50
132-
},
133-
"context": {
134-
"previewId": "preview"
135-
}
136-
}`}
163+
label="Result"
164+
value={resultCode || 'No result yet.'}
137165
disabled={true}
138166
isConsole={true}
139167
className={boxClassNames}

‎website/src/components/walkerjs.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export const DataCollection = () => {
2222
if (!window.walkerjs) {
2323
const { elb, instance } = createSourceWalkerjs({
2424
run: true,
25+
pageview: false,
2526
session: {},
2627
});
2728

‎website/src/pages/event-flow/index.tsx

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { JSX } from 'react';
22
import Layout from '@theme/Layout';
33
import EventFlow from '@site/src/components/organisms/eventFlow';
4-
import { destinationWebAPI } from '@elbwalker/destination-web-api';
54

65
const exampleCode = `<div
76
data-elb="product"
8-
data-elbaction="load:visible"
7+
data-elbaction="load:view"
98
class="dui-card w-80 bg-base-100 shadow-xl mx-auto"
109
>
1110
<figure class="relative">
@@ -40,29 +39,38 @@ export default function EventFlowPage(): JSX.Element {
4039
<Layout title="Event Flow" description="Test the event flow component">
4140
<EventFlow
4241
code={exampleCode}
42+
mapping={{
43+
product: {
44+
view: {
45+
name: 'view_item',
46+
data: {
47+
map: {
48+
event: 'event',
49+
price: { value: '100' },
50+
},
51+
},
52+
},
53+
add: {
54+
name: 'add_to_cart',
55+
data: {
56+
map: {
57+
event: 'event',
58+
price: { value: '100' },
59+
},
60+
},
61+
},
62+
},
63+
}}
4364
height="640px"
4465
previewId="event-flow"
45-
fn={(event) => {
46-
delete event.globals;
66+
eventFn={(event) => {
4767
delete event.custom;
4868
return event;
4969
}}
50-
destination={destinationWebAPI}
51-
initialConfig={{
52-
custom: {
53-
url: 'https://moin.p.elbwalkerapis.com/lama',
54-
transform: (event) => {
55-
return JSON.stringify({
56-
...event,
57-
...{
58-
projectId: 'RQGM6XJ',
59-
},
60-
});
61-
},
62-
transport: 'xhr',
63-
},
70+
resultFn={(output) => {
71+
return `dataLayer.push(${JSON.stringify(output, null, 2)});`;
6472
}}
6573
/>
6674
</Layout>
6775
);
68-
}
76+
}

0 commit comments

Comments
 (0)
Please sign in to comment.