Attribute: map - evolv-ai/metrics GitHub Wiki

The map is used for a "bind" action. It provides a mechanism to reduce a value to specific set of discreet values. Unlike the apply attribute, map must have a tag attribute set at the same level. It is not used as an inheritance mechanism.

It is represented as an array of objects that allows the value of the attribute to be transformed. Those mappings each have 2 json keys:

  • when - a regex for testing the attribute value against
  • value - the new value to be bound to the attribute when conditional is met

Example

{
    "source": "expression",
    "key": "document.referrer",
    "type": "string",
    "tag": "referrer.searchEngine",
    "map": [
        {"when": "google.com",     "value": "google"},
        {"when": "bing.com",       "value": "bing"},
        {"when": "search.yahoo",   "value": "yahoo"},
        {"when": "yandex.com",     "value": "yandex"},
        {"when": "duckduckgo.com", "value": "duckduckgo"}
    ]
}

notes

In this example, referrer.searchEngine will only be bound if the document.referrer matches one of the 5 when clauses.