Configuration
There are a few configuration options when creating a dataLayer source instance:
import { sourceDataLayer } from '@elbwalker/source-datalayer';
sourceDataLayer({
elb: elb, // The elb function to use (required)
filter: (event) => {
// Filter out internal GTM events
return event.event.startsWith('gtm.');
},
mapping: {
'consent update': {
name: 'walker consent',
custom: {
command: {
map: {
marketing: 'ad_storage',
analytics: 'analytics_storage',
},
},
},
},
},
name: 'dataLayer', // The name of the dataLayer variable
prefix: 'dataLayer', // Used to prefix the event name
});
Option | Type | Description |
---|---|---|
elb* | function | The function to push the events to |
filter | function | A check to filter specific events |
mapping | object | The mapping configuration of the events |
name | string | Name of the dataLayer array (default: dataLayer ) |
prefix | string | Prefix for the event name to match entity action format (default: dataLayer ) |
Properties with a *
are required.
Usually, the event name is the actual event
property of the dataLayer event.
If gtag
commands are used, the event name differs. In those cases the command
and parameters
are treated like entity and action.
gtag('set', 'campaign', { term: 'running+shoes' });
// Will become "set campaign" as event name
Use console.log
for the elb
function to inspect events.
Commands
The custom.command
mapping property is used to map the event to a walkerOS
command and call elb(name, data)
with the two parameters name
and data
.
Infinite loops
The internal processing
flag is used to prevent infinite loops. While the
dataLayer source listens for new dataLayer.push events and forwards them to a
walker.js instance, another dataLayer related destination might push that event
to the dataLayer again (like GA4). Therefore, while processing an event, newly
pushed events are ignored and stored in the skipped
array.
As a additional rule the filter
function can be used to ignore events that
might have been pushed by a walker.js destination.
Examples
add_to_cart
purchase
If you need professional support with your walkerOS implementation, check out our services.