|
| 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 <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 <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 <Link to="/services">services</Link>. |
| 162 | + |
| 163 | +::: |
0 commit comments