Skip to content

Commit bb3a3fd

Browse files
dataLayer docs
1 parent d4c2c80 commit bb3a3fd

File tree

5 files changed

+231
-3
lines changed

5 files changed

+231
-3
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"label": "dataLayer (coming soon)",
2+
"label": "dataLayer",
33
"position": 3
44
}
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
---
2+
title: Configuration
3+
sidebar_position: 2
4+
description: How to configure walkerOS node source.
5+
---
6+
7+
import Link from '@docusaurus/Link';
8+
9+
There are a few configuration options when creating a dataLayer source instance:
10+
11+
```ts
12+
import { sourceDataLayer } from '@elbwalker/source-datalayer';
13+
14+
sourceDataLayer({
15+
elb: elb, // The elb function to use (required)
16+
filter: (event) => {
17+
// Filter out internal GTM events
18+
return event.event.startsWith('gtm.');
19+
},
20+
mapping: {
21+
'consent update': {
22+
name: 'walker consent',
23+
custom: {
24+
command: {
25+
map: {
26+
marketing: 'ad_storage',
27+
analytics: 'analytics_storage',
28+
},
29+
},
30+
},
31+
},
32+
},
33+
name: 'dataLayer', // The name of the dataLayer variable
34+
prefix: 'dataLayer', // Used to prefix the event name
35+
});
36+
```
37+
38+
| Option | Type | Description |
39+
| ------- | -------- | ----------------------------------------------------------------------------------------------------------- |
40+
| elb\* | function | The function to push the events to |
41+
| filter | function | A check to filter specific events |
42+
| mapping | object | The&nbsp;<Link to="/docs/destinations/event_mapping#eventconfig">mapping configuration</Link> of the events |
43+
| name | string | Name of the dataLayer array (default: `dataLayer`) |
44+
| prefix | string | Prefix for the event name to match entity action format (default: `dataLayer`) |
45+
46+
Properties with a `*` are required.
47+
48+
Usually, the event name is the actual `event` property of the dataLayer event.
49+
If&nbsp;<Link to="https://developers.google.com/tag-platform/gtagjs/reference">gtag
50+
commands</Link> are used, the event name differs. In those cases the `command`
51+
and `parameters` are treated like entity and action.
52+
53+
```ts
54+
gtag('set', 'campaign', { term: 'running+shoes' }); // "set campaign" event name
55+
```
56+
57+
:::tip
58+
59+
Use `console.log` for the `elb` function to inspect events.
60+
61+
:::
62+
63+
### Commands
64+
65+
The `custom.command` property is used to map the event to a walkerOS command and
66+
call `elb(name, data)` with the two parameters `name` and `data`.
67+
68+
```ts
69+
sourceDataLayer({
70+
elb,
71+
mapping: {
72+
'consent update': {
73+
name: 'walker consent',
74+
custom: {
75+
command: {
76+
map: {
77+
marketing: 'ad_storage',
78+
analytics: 'analytics_storage',
79+
},
80+
},
81+
},
82+
},
83+
},
84+
});
85+
86+
gtag('consent', 'update', {
87+
ad_user_data: 'denied',
88+
ad_personalization: 'denied',
89+
ad_storage: 'denied',
90+
analytics_storage: 'granted',
91+
wait_for_update: 500,
92+
});
93+
94+
expect(elb).toHaveBeenCalledWith('walker consent', {
95+
marketing: false,
96+
analytics: true,
97+
});
98+
```
99+
100+
### Infinite loops
101+
102+
The internal `processing` flag is used to prevent infinite loops. While the
103+
dataLayer source listens for new dataLayer.push events and forwards them to a
104+
walker.js instance, another dataLayer related destination might push that event
105+
to the dataLayer again (like GA4). Therefore, while processing an event, newly
106+
pushed events are ignored and stored in the `skipped` array.
107+
108+
As a additional rule the `filter` function can be used to ignore events that
109+
might have been pushed by a walker.js destination.
110+
111+
## Examples
112+
113+
### purchase
114+
115+
@TODO use codeBox with the push and the expected result.
116+
117+
```ts
118+
sourceDataLayer({
119+
elb,
120+
mapping: {
121+
purchase: {
122+
name: 'order complete',
123+
data: {
124+
map: {
125+
data: {
126+
map: {
127+
id: 'transaction_id',
128+
currency: 'currency',
129+
shipping: 'shipping',
130+
taxes: 'tax',
131+
total: 'value',
132+
coupon: 'coupon',
133+
},
134+
},
135+
nested: {
136+
loop: [
137+
'items',
138+
{
139+
map: {
140+
data: {
141+
map: {
142+
id: 'item_id',
143+
name: 'item_name',
144+
price: 'price',
145+
},
146+
},
147+
},
148+
},
149+
],
150+
},
151+
},
152+
},
153+
},
154+
},
155+
});
156+
```
157+
158+
:::info
159+
160+
If you need professional support with your walkerOS implementation, check out
161+
our&nbsp;<Link to="/services">services</Link>.
162+
163+
:::
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: Consent Mode
3+
sidebar_position: 3
4+
description: Use the Google Consent Mode to set the consent states.
5+
---
6+
7+
import Link from '@docusaurus/Link';
8+
9+
TODO
Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,26 @@
11
---
2-
title: dataLayer (coming soon)
3-
description: Installation of walkerOS dataLayer source.
2+
title: dataLayer
3+
description: Use the dataLayer as a source for walkerOS.
44
---
5+
6+
import Link from '@docusaurus/Link';
7+
import DocCardList from '@theme/DocCardList';
8+
import PackageLink from '/src/components/docs/package-link';
9+
10+
<PackageLink
11+
github="packages/sources/datalayer/"
12+
npm="@elbwalker/source-datalayer"
13+
/>
14+
15+
Many websites use the `dataLayer` to track events. The dataLayer source can be
16+
used work with this data. Existing and new dataLayer pushes can be processed and
17+
mapped to walkerOS events.
18+
19+
Use the source to integrate single events, migrate a whole existing setup to
20+
walkerOS or to only use the Google Consent Mode configuration.
21+
22+
The dataLayer source intercepts all dataLayer.pushes. Every event is cloned and
23+
processed in a tryCatch-block to guarantee a stable default behavior and
24+
preventing data mutation.
25+
26+
<DocCardList />
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: Installation
3+
sidebar_position: 1
4+
description: Installation of walkerOS dataLayer source.
5+
---
6+
7+
import Link from '@docusaurus/Link';
8+
import PackageLink from '/src/components/docs/package-link';
9+
10+
<PackageLink
11+
github="packages/sources/datalayer/"
12+
npm="@elbwalker/source-datalayer"
13+
/>
14+
15+
Install walkerOS dataLayer source via NPM:
16+
17+
```bash
18+
npm install @elbwalker/source-datalayer
19+
```
20+
21+
Use the `sourceDataLayer` function to create a new source instance which returns
22+
the `instance` itself.
23+
24+
```ts
25+
import { sourceDataLayer } from '@elbwalker/source-datalayer';
26+
const dataLayerSource = sourceDataLayer({ elb: window.elb });
27+
```
28+
29+
:::info
30+
31+
If you need professional support with your walkerOS implementation, check out
32+
our&nbsp;<Link to="/services">services</Link>.
33+
34+
:::

0 commit comments

Comments
 (0)