Mapping
The Config
stores all individual Event
configurations for each entity-action
event. The getMappingEvent
function
returns the matching Event
config while
the getMappingValue
is used to resolve
the Value
settings for a specific property to return an actual value. The
custom
property is used by
each destination individually.
interface Config<CustomEvent> {
[entity: string]: { [action: string]: Event<CustomEvent> };
}
interface Event<CustomEvent = unknown> {
batch?: number; // Bundle events for batch processing (in ms)
consent?: WalkerOS.Consent; // Required consent states process the event
custom?: CustomEvent; // Arbitrary but protected configurations for custom event config
ignore?: boolean; // Choose to no process an event when set to true
name?: string; // Use a custom event name
}
const mapping: Config = {
entity: {
action: {
batch: 2000,
consent: { marketing: true },
custom: { language: 'globals.language' },
ignore: false,
name: 'entity_action',
},
},
};
getMappingEvent
getMappingEvent(event: string, mapping?: Mapping.Config<unknown>): EventMapping
returns the matching eventMapping
configuration and the used mappingKey
for
the given entity-action event name. If no mapping is found, it will return an
empty object. An explicit key is favored over an asterisk *
key.
interface EventMapping {
eventMapping?: Event;
mappingKey?: string;
}
const mapping: Config = {
entity: {
action: {
name: 'entity_action',
},
'*': {
name: 'other',
},
'*': {
'*': {
name: 'irrelevant',
},
},
},
};
getMappingEvent('entity action', mapping);
// { eventMapping: { name: 'entity_action' }, mappingKey: 'entity action' }
getMappingEvent('entity something', mapping);
// { eventMapping: { name: 'other' }, mappingKey: 'entity *' }
getMappingValue
getMappingValue(event: WalkerOS.Event, mapping: Mapping.Value, options?: Mapping.Options): WalkerOS.Property | undefined
primarily used by destinations to access values from the original event. This
offers flexibility to configure
individual tagging setups
to standard fields of the destination.
export type Value = ValueType | Array<ValueType>;
export type ValueType = string | ValueConfig;
export interface ValueConfig {
condition?: Condition;
consent?: WalkerOS.Consent;
fn?: Fn;
key?: string;
validate?: Validate;
value?: WalkerOS.PropertyType;
}
First the condition
is checked to determine if the ValueConfig
should be
used. Second, the consent
state gets checked if an instance
is provided. If
no required consent is given, no value will be returned. If a fn
is provided,
it will be called to define the value, otherwise the key
or initial string
value will be used. The current value will be check using the validate
function and set to undefined
if it fails. Finally, the value
will be cast
to match the WalkerOS.Property
. An empty ValueType
will return undefined
.
If you need professional support with your walkerOS implementation, check out our services.