An expression is a formula that can be created for both customers and events and serve as a derived attribute. It can combine multiple attributes and can be used for further specification of customers or events. Expressions for events work as event attributes while expressions for customers work as customer attributes.
Watch this short introductory video about this feature:
Creating an expression
To create a new expression, go to
Data & Assets >
Data manager >
New definition >
Expression. You will see the following editor:
First, you need to select if you intend to derive the expression for a customer or event attribute. The same logic applies as with aggregates and running aggregates. After that, you can type the formula into the field, or you can use the buttons to add attributes and functions and then edit them.
Expressions consist of four main parts: attributes, functions, operators and strings.
Attributes are customer or event attributes, aggregates or running aggregates that were either defined previously or are created directly from the expression builder. These provide the values to the formula
Functions take the values from attributes and return a value based on the input. The following functions are available:
|abs(A)||Returns the absolute value of A.|
|concat(A,B)||Concatenate two strings together.|
|exp(A)||Returns an exponential ‘e^A’ where ‘e’ is Euler’s number.|
|max(A,B)||Compares the two values and returns the bigger one. This function takes only two attributes. If more attributes are to be compared, one can use multiple functions inside, e.g. Max( Max(A,B),Max(C,D)).|
|min(A,B)||Compares the two values and returns the smaller one. This function takes only two attributes. If more attributes are to be compared, one can use multiple functions inside, e.g. Min( Min(A,B),Min(C,D)).|
|ifnull(A,B)||Checks value of attribute A. If it is set, ifnull returns A. If A is not set, the returned value is B.|
|floor(A)||Removes the decimal part of value A.|
|ceil(A)||Rounds the A value upwards.|
|lower(A)||Returns the lower bound of dimension A.|
|upper(A)||Returns the upper bound of dimension A.|
|round(A)||Rounds the A value mathematically to the nearest integer.|
|ln(A)||Returns an integer object from number or string A.|
|now()||Returns the actual timestamp.|
|length()||Counts the number of values in a list, or characters in a string.|
|sqrt(A)||Returns the square root of the A value.|
|power(A,B)||Returns the power of the given value with A as the base and B as the exponent.|
Operators are basic mathematical functions for adding, retracting, etc. the other components of the expression. You need to type these manually using your keyboard.
Strings: To add text to your expression, wrap your text in quotation marks like this: "My text". Use
\ for escaping the rule, such as: "My "interesting" text" (thus the quotation marks will be included in your text).
Once you create an expression, it will be displayed as an attribute of that particular event or customer attribute that you defined it for. In this example, we defined our expression for the event
session_start, so it will be displayed as its attribute anytime when working with filters, reports, etc.
If you don't see your expression in the list, make sure you are working with the correct event / attribute and within the same initiative.
Expressions are used when further specifying events or customers e.g. in segmentations, reports, funnels, etc. They can be used similarly as other attributes to be compared to a constant value or other attributes. Some of the uses are as follows:
Setting a simple value to which multiple attributes are compared. When a need arises to change the compared value, you can change only the expression to affect all of the conditions instead of changing them one by one
Attributing revenue to some actions. To evaluate the effectiveness of a newsletter, web layer or another campaign, it is good to count only purchases that occur within a specific time after the action. For that, you would define an expression for purchase event and setting it to timestamp minus running aggregate of last banner timestamp and then compare it to the desired value as is shown below.
Floor last cart_update timestamp
Get the timestamp of the last event
cart_update, stripping the decimal numbers.
Updated 10 months ago