session_count plugin
Calculates sessions count based on ID column over a timeline. The plugin is invoked with the evaluate operator.
Syntax
TabularExpression | evaluate session_count(IdColumn, TimelineColumn, Start, End, Bin, LookBackWindow [, dim1, dim2, ...])
Arguments
- TabularExpression: The tabular expression that serves as input.
- IdColumn: The name of the column with ID values that represents user activity.
- TimelineColumn: The name of the column that represents the timeline.
- Start: A scalar value that defines the start of the analysis period.
- End: A scalar value that defines the end of the analysis period.
- Bin: A constant scalar value that defines the session's analysis step period.
- LookBackWindow: scalar constant value representing session lookback period. If the ID from
IdColumnappears in a time window withinLookBackWindow, the session is considered to be an existing one. If the ID doesn't appear, then the session is considered to be new. - dim1, dim2, ...: (optional) list of the dimensions columns that slice the session count calculation.
Returns
Returns a table that has the session count values for each timeline period and for each existing dimensions combination.
Output table schema is:
| TimelineColumn | dim1 | .. | dim_n | count_sessions |
|---|---|---|---|---|
| type: as of TimelineColumn | .. | .. | .. | long |
Examples
For this example, the data is deterministic, and we use a table with two columns:
Timeline: a running number from 1 to 10,000Id: ID of the user from 1 to 50
Id appears at the specific Timeline slot if it's a divider of Timeline (Timeline % Id == 0).
An event with Id==1 will appear at any Timeline slot, an event with Id==2 at every second Timeline slot, and so on.
Here are few 20 lines of the data:
let _data = range Timeline from 1 to 10000 step 1
| extend __key = 1
| join kind=inner (range Id from 1 to 50 step 1 | extend __key=1) on __key
| where Timeline % Id == 0
| project Timeline, Id;
// Look on few lines of the data
_data
| order by Timeline asc, Id asc
| limit 20
| Timeline | Id |
|---|---|
| 1 | 1 |
| 2 | 1 |
| 2 | 2 |
| 3 | 1 |
| 3 | 3 |
| 4 | 1 |
| 4 | 2 |
| 4 | 4 |
| 5 | 1 |
| 5 | 5 |
| 6 | 1 |
| 6 | 2 |
| 6 | 3 |
| 6 | 6 |
| 7 | 1 |
| 7 | 7 |
| 8 | 1 |
| 8 | 2 |
| 8 | 4 |
| 8 | 8 |
Let's define a session in next terms: session considered to be active as long as user (Id) appears at least once at a timeframe of 100 time slots, while session look-back window is 41 time slots.
The next query shows the count of active sessions according to the above definition.
let _data = range Timeline from 1 to 9999 step 1
| extend __key = 1
| join kind=inner (range Id from 1 to 50 step 1 | extend __key=1) on __key
| where Timeline % Id == 0
| project Timeline, Id;
// End of data definition
_data
| evaluate session_count(Id, Timeline, 1, 10000, 100, 41)
| render linechart