Event Mapping
Event mapping is a core feature of walkerOS that allows you to transform events before they reach destinations. The mapping system provides flexible configuration options to handle different destination requirements while maintaining a consistent event structure.
Overview
The mapping system consists of two main functions:
getMappingEvent
: Returns the matching event mapping configuration for entity-action eventsgetMappingValue
: Processes values from events using flexible mapping configurations
Mapping configurations are defined per destination and allow you to:
- Transform event names
- Extract and reshape event data
- Apply conditional logic
- Handle consent requirements
- Validate data before sending
Event Mapping with getMappingEvent
getMappingEvent(event: WalkerOS.PartialEvent, mapping?: Mapping.Rules): Promise<Mapping.Result>
This function finds the appropriate mapping configuration for an event based on its entity and action.
Basic Event Mapping
Map specific entity-action combinations to custom event names:
Wildcard Mappings
Use wildcards (*
) to match multiple entities or actions:
Conditional Mappings
Use conditions to apply different mappings based on event properties:
Ignoring Events
Skip processing certain events by setting ignore: true
:
Value Mapping with getMappingValue
getMappingValue(value: unknown, mapping: Mapping.Data, options?: Mapping.Options): Promise<WalkerOS.Property | undefined>
This function transforms values using various mapping strategies.
String Key Mapping
Use a string to extract a value by its property path:
Array Access
Access array elements using dot notation:
Static Values
Return static values using the value
property:
Custom Functions
Transform values using custom functions:
Object Mapping
Create new objects by mapping properties:
Array Processing with Loop
Process arrays and transform each item:
Validation
Validate values and return undefined if validation fails:
Consent-Based Mapping
Only return values when required consent is granted:
Destination Integration
Mapping configurations are typically defined in destination configs:
const destination = {
type: 'gtag',
init: () => ({
/* init config */
}),
push: (event, { data }) => {
// Use mapped data
gtag('event', event.event, data);
},
config: {
mapping: {
// Event mappings
product: {
view: {
name: 'view_item',
data: {
map: {
item_id: 'data.id',
item_name: 'data.name',
value: 'data.price',
currency: { value: 'USD' },
},
},
},
},
},
// Global data mapping
data: {
map: {
page_title: 'context.title',
page_location: 'context.url',
},
},
},
};
Best Practices
- Use specific mappings over wildcards when possible for better performance
- Leverage conditions to handle different event scenarios
- Validate critical data before sending to destinations
- Respect consent requirements by using consent-based mappings
- Keep transformations simple - complex logic should be in custom functions
- Test mappings thoroughly with different event scenarios