Skip to main content

Using JavaScript

Walker.js uses the elbLayer to handle all events. You can also trigger custom events manually using JavaScript:

import { elb } from '@elbwalker/walker.js';
elb('entity action', data, trigger, context, nested, custom);

Both entity and action are required and combined in one string separated by space. The optional data object holds all properties of an entity. Trigger is optional and expected to be a string.

Examples

// Virtual page view of an overlay popup
elb('page view', { id: '/overlay/login', name: 'Log In' }, 'visible');

// Add to cart
elb('product add', { name: 'Everyday Ruck Snack' });

// Random event
elb('application confirm');

// Use data and context from elements in DOM
const elem = document.getElementById('entity'); // the 'form' entity element
elb('form send', elem); // Get data and context from DOM
elb('form send', { data: 'static' }, 'code', elem); // Only get context from DOM

The full elb-function interface requires the event and accepts additional parameters for data, trigger, context, and nested

elb(
'entity action', // event
{ foo: 'bar' }, // data
'custom', // trigger
{ test: ['a', 0] }, // context
[
// nested
{
type: 'child',
data: { iam: 'nested' },
},
],
{ any: 'thing' }, // custom
);
warning

When working directly with the elbLayer make sure to initialize it properly by writing the following line before making use of the push method:
window.elbLayer = window.elbLayer || [];

info

If you need professional support with your walkerOS implementation, check out our services.