Attribute: when - evolv-ai/metrics GitHub Wiki
The when
attribute provides a mechanism to activate a metric or set of metrics conditionally. The when
clause must be satisfied bofore the current metric or any of its decendants are applied.
It supports the following value types:
- string: Is used as regex to apply to a value of
type
string - number: Is used for an exact match on a value of
type
number - boolean: Is used for an exact match on a value of
type
boolean - object: Is used to provide a match on a value of
type
number with following options:- {"operator": "<", "value": 10}: matches on values less than 10
- {"operator": "<=", "value": 10}: matches on values less than or equal to 10
- {"operator": ">", "value": 10}: matches on values greater than 10
- {"operator": ">=", "value": 10}: matches on values greater or equal to 10
The when
attribute can appear in metrics nested in apply
or map
arrays.
Example
In apply
{
"source": "expression",
"key": "window.location.pathname",
"action": "event",
"apply": [
{
"when": "^(/product)$",
"tag": "page-load.product"
},
{
"when": "^(/purchase)$",
"tag": "page-load.purchase"
}
]
}
In map
{
"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"}
]
}
For numeric
{
"source": "dom"
"key": "form select.amount",
"type": "number",
"on": "change",
"extract": {
"attribute": "value",
"parse": "[0-9,]+.?$"
},
"apply": [
{"tag": "request.amount", "action": "bind" },
{"tag": "below-ten.requested", "action": "event", "when" : {"operator": "<", "value": 10000}},
{"tag": "above-ten.requested", "action": "event", "when" : {"operator": ">=", "value": 10000}}
]
}