Skip to main content
Ask your AI

Code Destination

A destination does not need a package. Pass an object with a push function as code, and the collector calls it for every event, like any other destination. Use it to run a few lines of your own code on events.

Where this fits

Code is a destination in the walkerOS flow:

Runs your own push function on each event, without a package.

Integrated​

import { startFlow } from '@walkeros/collector';

const { elb } = await startFlow({
  destinations: {
    console: {
      code: {
        type: 'console',
        config: {},
        push: (event) => {
          console.log('Event:', event.name, event.data);
        },
      },
    },
  },
});

Bundled​

In a flow.json, write the function as a $code: string:

"destinations": {
  "console": {
    "code": {
      "type": "console",
      "push": "$code:(event) => { console.log('Event:', event.name, event.data); }"
    }
  }
}

The rules for code in a flow file are in Inline code.

Set consent, mapping and the other destination options in config beside code, as for any destination. In integrated mode the object can implement the whole destination interface. batch needs a pushBatch function. Without one, walkeros validate and the bundle fail with "config.batch has no effect: the inline code has no pushBatch" (code BATCH_WITHOUT_PUSH_BATCH in walkeros validate --json), and in integrated mode the collector logs one ERROR line at registration and sends each event to push. A flow file's code takes type, init, push, pushBatch, on and destroy; any other key is an error.

A push that cannot send throws, and a push that returns normally counts as delivered. See Reporting failures.

💡 Need implementation support?
elbwalker offers hands-on support: setup review, measurement planning, destination mapping, and live troubleshooting. Book a 2-hour session (€399)