Functions and Types
A realtime attribute combines the matching events inside its lookback with one function. The function decides which properties it can read and what the attribute returns.
Functions
| Function | In the app | Returns | Reads |
|---|---|---|---|
count | Count | How many matching events there were — 0 when there were none | No property |
sum | Sum | The total of a number across the matching events | A number |
avg | Average | The average of a number across the matching events that carried it | A number |
min | Smallest | The smallest number, or the earliest time | A number or a timestamp |
max | Largest | The largest number, or the latest time | A number or a timestamp |
last | Latest value | The value carried by the most recent matching event | A string, number, boolean or timestamp |
What each function returns
The type an attribute returns follows from the function and the property, and is shown on its page. It decides which comparisons other features can make with it.
| Function | Number | String | Boolean | Timestamp | List (turned into a number) | Returns |
|---|---|---|---|---|---|---|
| Count | — | — | — | — | — | number |
| Sum | Yes | — | — | — | Yes | number |
| Average | Yes | — | — | — | Yes | number |
| Smallest / Largest | Yes | — | — | Yes | Yes | number, or timestamp for a timestamp |
| Latest value | Yes | Yes | Yes | Yes | Yes | the property’s own type |
When nothing matched inside the lookback, Count is 0 and every other function has no value — not zero. An average with no events to divide by has no value either.
Lists
When the property is a list, choose how to turn it into one number for each event before the function sees it:
| Choice | Gives |
|---|---|
| Number of items | How many items the list holds |
| Sum of an item field | The total of the items, or of one field in each item — for example price in a list of line items |
| Smallest item field | The smallest item, or the smallest value of one field |
| Largest item field | The largest item, or the largest value of one field |
A list of records needs the item field to name which field to read; a list of plain numbers does not. Records and JSON values themselves cannot be read — choose a single property inside them instead.
Properties the schema does not describe
The event source’s schema is a guide, not a gate. Events often carry properties the schema has not caught up with, so you can type a property the schema does not list. When you do, choose its type — string, number, boolean or timestamp. The type is recorded on the attribute, and the editor shows the choice only where the schema is silent:
- a property the schema does not list yet;
- the item field of a list, which the schema does not describe. Number of items needs no type: it is always a number.
Where the schema does describe the property, its type is used and nothing needs choosing.
Events whose value is not of the chosen type are not counted. If you choose number and an event sends "12.50" as text, that event is skipped. Check the property’s spelling and type against a real event before you rely on the value.
Negative values
Numbers below zero are left out by default. An event whose value is negative — or, for Total, Smallest or Largest of a list, a list with any item below zero — is skipped as if it had no value; the event’s other attributes are still updated. This stops one stray -1 (a placeholder, a refund sent with the wrong sign) from becoming the smallest value for as long as it stays in the lookback.
When values below zero are real data — a balance, a refund amount, a temperature — tick Accept negative values on the Property step ("allow_negative_values": true on the value, through the API). It is offered for number values only; Number of items, timestamps, text and true/false values are never affected. Changing it starts the value again from zero.
A value that was counted ages out with its lookback like any other: a smallest value of -1 is reported only while that event is inside the lookback (give or take the edge described under Precision), not for the life of the attribute.
Lookback
The lookback has the same limits as a realtime audience condition:
| Unit | Longest lookback |
|---|---|
| Seconds | 600 |
| Minutes | 720 |
| Hours | 48 |
| Days | 7 |
A lookback is always the last N units, counted back from now. Calendar periods (“this week”), “not within”, “all time” and anything longer than 7 days are not available; use a Computed Attribute for long-range values.
Precision
- A value over a lookback can include or miss events from up to a tenth of the lookback at its far edge. Latest value is exact.
- Numbers are kept to six decimal places, within about ±9.2 trillion. A single event whose value is outside that range is skipped rather than added. So is a negative number, unless the attribute accepts negative values.
- Timestamps are kept to the microsecond.
Not available
Distinct counts, lists of distinct values, the first value, the most frequent value, the last few values, formulas over realtime attributes and attributes over more than one event are not in this version. Distinct counts and distinct lists are held back on purpose: there is no limit to how many distinct values one visitor can produce, and keeping all of them would let one busy visitor slow down every read of their own data.
Next Steps
- Realtime Attributes — the overview, creating one, and where you can use it.
- Reading Values — read a person’s values from the Membership API.