Configuration
The configuration of a destination is set up in config
. Call
elb('walker destination', { push: console.log }, config);
to add the
destination to a source. All properties are optional.
Example
{
id: "demo",
custom: { foo: "bar" },
consent: { demo: true },
init: false,
loadScript: false,
mapping: {
// Read more in the mapping section
page: {
view: { name: "pageview" },
},
"*": {
visible: { batch: 2000 },
},
},
policy: {
'data.gclid': { consent: { marketing: true } },
},
queue: true,
verbose: false,
onError: (error) => console.error("demo error", error),
onLog: (message) => console.log("demo log", message),
on: {
// Source-related on-events
consent: [{ marketing: console.log }],
ready: [console.log],
run: [console.log],
session: [console.log],
},
};
Overview of all properties
Property | Value | Description |
---|---|---|
id | string | A unique key for the destination |
consent | object | Required consent states to init and push events |
custom | unkown | Used for a destination's individual settings |
init | boolean | If the destination has been initialized by calling the init method |
loadScript | boolean | If an additional script should be loaded |
mapping | object | Configuration how to transform events (see Mapping) |
policy | boolean | Enriches, validates, and redacts properties from the event (see MappingValue) |
queue | boolean | Disable processing of previously pushed events |
verbose | boolean | Enable verbose logging |
onError | function | Custom error handler |
onLog | function | Custom log handler |
on | On.Config | Rules for on-functions that are triggered on specific events |
Methods
A source communicates with a destination through methods. Its also the
source's job to check for proper consent, calling the init
method or batching
events. The only required method is push
to send events to the destination.
push
The push
method gets called to send events to the destination, along with the
config
and eventually mapping
.
// push function
const push = (event, config, mapping) => {
config.custom.count++;
event.data.count = config.custom.count;
console.log('demo push', { event, config, mapping });
};
// elb("page view");
// Output with the mapping above
// demo log bar
// demo push { event: { data: { count: 1 }, event: 'pageview' }, config: { ... }, mapping: { ... } }
init
init
is optional and gets called before pushing events. It's used to
eventually load additional scripts or set up the environment. To interrupt
further processing, the method must return false
.
The walker.js checks the config.init
value to see if a destination has been
initialized, or not. This way you can add a destination that has already been
initialized.
// Optional init function
const init = (config) => {
if (config.verbose) config.onLog(config.custom.foo);
config.custom.count = 0;
};
pushBatch
The pushBatch
method is optional and gets called if the event mapping
is
configured with a batch
number to bundle multiple events before sending them
to the destination.
const pushBatch = (batch, config, instance) => {
console.log('demo pushBatch', { batch, config });
};
The batch
is an object with the key
of the used mapping, the events
array
and the mapping
object itself.
// Configuring a destinations mapping with
const mapping = {
'*': {
visible: { batch: 2000 },
},
};
// Calling a matching event two times
elb('product visible');
elb('promotion visible');
// The destinations pushBatch receives the following batch after 2 seconds
batch = {
key: '* visible',
events: [{ event: 'product visible' }, { event: 'promotion visible' }],
mapping: { batch: 2000 },
};
on
The on
method is used to set up rules for on-functions that are triggered by
the source (individually for walker.js and node).
const on = {
consent: [{ marketing: console.log }],
ready: [console.log],
run: [console.log],
session: [console.log], // walker.js only
};
Once a source triggers an event, the destinations on
method gets called.
Replace the console.log
with your custom function.
Node destinations in walkerOS offer a flexible and efficient way to handle your server-side event data. Whether you're sending data to a cloud-based data warehouse like BigQuery or to a custom API, node destinations make it easy to configure, initialize, and push your events securely. |
Functions
init
Before pushing events to a destination, the node source checks for an available
init
function and calls it. This asynchronous function returns either false
if an error occurs, preventing any events from being processed, or a complete
destination config
that will be used for pushing events.
push
The node source calls await destination.push([{ event, mapping }], config);
to
send events to destinations. This function is executed after checking for proper
consent settings. Events are processed in parallel, and function supports
batching of multiple events. The mapping parameter is optional and allows for
custom event configurations.
If you need professional support with your walkerOS implementation, check out our services.