All Collections
Data Transformation
Metrics
Working with rule-based metrics
Working with rule-based metrics
Peter Lundberg avatar
Written by Peter Lundberg
Updated over a week ago

Rules

Rules-based Custom Metrics can consist of one or more rules. Rules can be for a specific data source ('Adwords', 'Facebook', ...) or for all data sources.

Conditions ('WHEN ...')

Here's where to define when a rule should be applied, for instance, if it should be applied for the data source 'my data source' when record dates match Saturdays and Sundays.

WHEN
{Data Source} exactly matches 'my data source'
AND
{Day of week} exactly matches 'Saturday' OR exactly matches 'Sunday'

For more details on conditions, see below.

Result Value ('THEN IS ...')

When conditions have been met (matching) the result needs to be defined. The result is determined as the 'value of' an existing metric, the 'sum of' several existing metrics, a dimension converted 'to number', or a specified 'numeric value'. This value can be modified in further steps, by adding, subtracting, multiplying, or dividing it with the value from another metric or a specified number. It can also be modified by looking up another value from a list or google sheet.

For more details on result values, see below.

Data sources

A rules-based metric can have different rules for different data sources. When a data source group ('Adwords', 'Facebook', ...) has been selected, rules can be added to data sources belonging to that data source group, either using conditions or for all those data sources. It is also possible to add rules for all data source groups using conditions.

Examples

If you, for instance, want to create a metric that varies the definition of Conversions depending on the data source that could be expressed as:

For Adwords data, set the value to Adwords All conv.
For Facebook Ads data, set the value to Website Conversions.
For Google Analytics data, set the value to Goal 1 + Goal 6

This is done by adding rules in the Rule editor. One can also add multiple conditions and do other transformations on the selected values. The order of the rules can be important as the first match is used. Other examples of rule-based metrics are:

  • Billed cost
    if Campaign contains "_A1_" then Cost * 1.1,
    if Campaign contains "_A2_" then Cost * 1.2,
    otherwise Cost

  • AppsFlyer installs if Event name is "install" use Count

  • Revenue ex tax
    if Market contains "US" then Revenue * 0.8,
    if Market contains "UK" then Revenue * 0.75,
    ...

  • Calculated Revenue
    if Campaign contains "|c7" then Total Conversions * 1.07,
    if Campaign contains "|c20" then Total Conversions * 1.2,
    ...


Conditions reference (operators)

exactly matches

does not exactly match

Is the specified dimension value exactly the specified value?

contains

contains (ignore case)

does not contain

does not contain (ignore case)

Does the specified dimension value contain the specified value?

starts with

starts with (ignore case)

ends with

Does the specified dimension value start or end with the specified value?

split by

matches regex

does not match regex

Can the specified dimension value be split by the specified delimiter or does it match the specified regular expression?

is empty

is not empty

Is the specified dimension value empty?

>

<

Is the specified dimension value bigger or smaller than the specified value?

Dimensions 'Data source' and 'Data source type' only support these operators:

  • exactly matches

  • does not exactly match

  • is not empty

Result value reference

Initial value

value of

Set the value to the value of a specified metric.

sum of

Set the value to the sum of multiple specified metric values.

to number

Convert a numeric dimension to a number

numeric value

Set the value to a specified numeric value.

Additional steps

plus

minus

multiplied by

divided by

number

value from

Modify the initial value with a specified number or metric value using the specified operator.

lookup

comma-separated values

google sheet

Look up the initial value in the match column of the specified table, if any, and return the value from the result column.


Read more about Formulas and Rules in How are custom metrics calculated?

Did this answer your question?