| name | walkeros-understanding-mapping |
| description | Use when transforming walkerOS events in the flow (source→collector or collector→destination), configuring data/map/loop/set/condition/policy, or using $code: syntax in JSON configs. |
Understanding walkerOS Mapping
Overview
Mapping transforms data at multiple points in the walkerOS flow:
- Source → Collector: Transform raw input (HTTP requests, dataLayer pushes)
into walkerOS events
- Collector → Destination: Transform walkerOS events into vendor-specific
formats
Core principle: Mapping is the universal transformation layer. Same
strategies work everywhere in the flow.
Core Functions
See packages/core/src/mapping.ts for
implementation.
| Function | Purpose |
|---|
getMappingEvent(event, rules) | Find mapping rule for an event |
getMappingValue(value, data, options) | Transform a value using mapping config |
processEventMapping(event, config, collector) | Unified processing for sources/destinations |
processEventMapping Flow
1. Apply config.policy (modifies event)
2. Find matching rule via getMappingEvent()
3. Apply rule.policy (modifies event)
4. Transform config.data (global)
5. Check rule.ignore
6. Override event.name if rule.name
7. Transform rule.data (event-specific)
Configuration Hierarchy
Mapping.Config (Top Level)
interface Config {
consent?: Consent;
data?: Value;
policy?: Policy;
mapping?: Rules;
}
Mapping.Rule (Per Event)
interface Rule {
name?: string;
data?: Value;
ignore?: boolean;
policy?: Policy;
condition?: Function;
consent?: Consent;
settings?: unknown;
batch?: number;
}
Mapping.ValueConfig (Value Extraction)
interface ValueConfig {
key?: string;
value?: Primitive;
fn?: Function;
map?: Record;
loop?: [path, config];
set?: Value[];
condition?: Function;
consent?: Consent;
validate?: Function;
}
Event Matching
Match events to transformation rules by entity and action.
const mapping = {
product: {
view: { name: 'view_item' },
add: { name: 'add_to_cart' },
},
foo: {
'*': { name: 'foo_interaction' },
},
'*': {
click: { name: 'generic_click' },
},
};
Conditional Mapping (Array)
Array of rules - first matching condition wins:
order: {
complete: [
{
condition: (event) => event.data?.value > 100,
name: 'high_value_purchase',
},
{ name: 'purchase' },
],
}
JSON with $code:
{
"order": {
"complete": [
{
"condition": "$code:(event) => event.data?.value > 100",
"name": "high_value_purchase"
},
{ "name": "purchase" }
]
}
}
Value Mapping Strategies
Common patterns shown below. For detailed examples of all 12 strategies, see
value-strategies.md.
Essential Patterns
'data.price'
{ key: 'data.currency', value: 'USD' }
{ value: 'USD' }
{ fn: (event) => event.data.price * 100 }
{ map: { item_id: 'data.id', item_name: 'data.name' } }
{ loop: ['nested', { map: { item_id: 'data.id' } }] }
{ loop: ['this', { map: { item_id: 'data.id' } }] }
{ set: ['data.id'] }
[{ key: 'data.sku' }, { key: 'data.id' }, { value: 'unknown' }]
{ key: 'user.email', : { : } }
{ : , : v.() }
Policy (Pre-Processing)
Policy modifies the event BEFORE mapping rules are applied. Use for:
- Adding computed fields
- Normalizing data structure
- Consent-gated field injection
Config-Level Policy
Applied to ALL events:
config: {
policy: {
'user_data.external_id': 'user.id',
'custom_data.server_processed': { value: true },
},
mapping: { }
}
Event-Level Policy
Applied after config policy, only for specific event:
mapping: {
order: {
complete: {
policy: {
'enriched.total_cents': {
fn: (event) => Math.round(event.data.total * 100)
}
},
name: 'purchase',
data: { }
}
}
}
Policy with Consent
{
"policy": {
"user_data.em": {
"key": "user.email",
"consent": { "marketing": true }
}
}
}
Rule Features
Ignore Events
mapping: {
test: { '*': { ignore: true } },
}
Batch Processing
mapping: {
'*': {
'*': {
batch: 5,
}
}
}
Custom Settings
mapping: {
order: {
complete: {
name: 'purchase',
settings: { priority: 'high', retryCount: 3 }
}
}
}
$code: Prefix (JSON Configs)
The $code: prefix enables JavaScript functions in JSON configurations:
{
"fn": "$code:(event) => event.data.price * 100",
"condition": "$code:(event) => event.data?.value > 100",
"validate": "$code:(value) => value > 0"
}
Important: The $code: prefix is processed by the CLI bundler. It converts
JSON strings to actual JavaScript functions during build.
Function Signatures
| Context | Signature |
|---|
fn | (value, mapping, options) => result |
condition (value) | (value, mapping, collector) => boolean |
condition (rule) | (event) => boolean |
validate | (value) => boolean |
loop condition | (item) => boolean |
Quick Reference
Value Extraction Cheatsheet
| Pattern | Result |
|---|
"data.id" | Extract event.data.id |
{ value: "USD" } | Static "USD" |
{ key: "x", value: "y" } | Extract x, fallback to "y" |
{ fn: (e) => ... } | Custom function |
{ map: {...} } | Object transformation |
{ loop: ["nested", {...}] } | Array transformation |
{ loop: ["this", {...}] } | Single-item as array |
{ set: ["a", "b"] } | Create array [valA, valB] |
[m1, m2, m3] | Fallback chain |
{ consent: {...} } | Consent-gated |
{ condition: fn } | Conditional |
{ validate: fn } | Validated |
Rule Features Cheatsheet
| Feature | Purpose |
|---|
name | Override event name |
data | Transform event data |
ignore | Skip event entirely |
policy | Pre-process event |
condition | Match condition (arrays) |
consent | Required consent |
settings | Custom configuration |
batch | Batch size |
Config Features Cheatsheet
| Feature | Purpose |
|---|
consent | Required consent (all events) |
data | Global data transformation |
policy | Global pre-processing |
mapping | Event-specific rules |
Complete Examples
For full destination configuration examples (TypeScript + JSON), see
complete-examples.md.
Where Mapping Lives
| Location | Purpose |
|---|
| Source config | Transform raw input → walkerOS events |
| Destination config | Transform walkerOS events → vendor format |
packages/core/src/mapping.ts | Core mapping functions |
packages/core/src/types/mapping.ts | Type definitions |
packages/cli/examples/flow-complete.json | Comprehensive example (53 features) |
Related Skills
Source Files:
Detailed References:
Examples:
Converted and distributed by TomeVault — claim your Tome and manage your conversions.