Hello,
Are there any recommendations on how to have funnel-like visualisations from DQL source? Typically business events now, probably user sessions soon.
I’m looking for some practice close to what funnels in USQL currently are, which means:
- count only consecutive events per correlation id (e.g. session)
- visualization (probably bar chart or pie chart is now the only way)
Bizflow app is not an option in my case for several reasons:
- It is not flexible enough (only allows to select events by event.type without any further conditions)
- It is not possible to pin the funnel on a dashboard
Update:
The best I was able to do at the moment follows:
data
record(timestamp = now()-30m, session="session1", `event.provider`="myapp", `event.type`="add_to_cart"),
record(timestamp = now()-25m, session="session1", `event.provider`="myapp", `event.type`="place_order"),
record(timestamp = now()-20m, session="session1", `event.provider`="myapp", `event.type`="payment"),
record(timestamp = now()-30m, session="session2", `event.provider`="myapp", `event.type`="add_to_cart"),
record(timestamp = now()-25m, session="session2", `event.provider`="myapp", `event.type`="place_order"),
// this will not be counted in the funnel
record(timestamp = now()-30m, session="session_without_first_event", `event.provider`="myapp", `event.type`="place_order"),
record(timestamp = now()-25m, session="session_without_first_event", `event.provider`="myapp", `event.type`="payment")
| filter startsWith(event.provider,"myapp")
// Create boolean fields if step exists in a session
| summarize {
`add_to_cart` = countIf(event.type=="add_to_cart")>0,
`place_order` = countIf(event.type=="place_order")>0,
`payment` = countIf(event.type=="payment")>0
}, by: { session }
// Summarize events
| summarize
funnel = array (
record(step="Add to cart", count=countIf(`add_to_cart`)),
record(step="Place order", count=countIf(`add_to_cart` and `place_order`)),
record(step="Payment", count=countIf(`add_to_cart` and `place_order` and `payment`))
)
// Expand events into separate records
| expand funnel
| fieldsFlatten funnel
| fieldsRemove funnel
Example in the playground environment.
If a specific order of steps is required:
data
record(timestamp = now()-30m, session="session1", `event.provider`="myapp", `event.type`="add_to_cart"),
record(timestamp = now()-25m, session="session1", `event.provider`="myapp", `event.type`="place_order"),
record(timestamp = now()-20m, session="session1", `event.provider`="myapp", `event.type`="payment"),
record(timestamp = now()-30m, session="session2", `event.provider`="myapp", `event.type`="add_to_cart"),
record(timestamp = now()-25m, session="session2", `event.provider`="myapp", `event.type`="place_order"),
// this will not be counted in the funnel
record(timestamp = now()-30m, session="session_without_first_event", `event.provider`="myapp", `event.type`="place_order"),
record(timestamp = now()-25m, session="session_without_first_event", `event.provider`="myapp", `event.type`="payment"),
// session with incorrect order
record(timestamp = now()-20m, session="session_with_incorrect_order", `event.provider`="myapp", `event.type`="add_to_cart"),
record(timestamp = now()-25m, session="session_with_incorrect_order", `event.provider`="myapp", `event.type`="place_order"),
record(timestamp = now()-30m, session="session_with_incorrect_order", `event.provider`="myapp", `event.type`="payment")
| filter startsWith(event.provider,"myapp")
| sort session, timestamp asc
// Summarize event by session into an array, so we have steps in an array for each session
| summarize steps = collectArray(event.type), by:{ session }
// Create position of each step
| fieldsAdd
`add_to_cart` = arrayIndexOf(steps,"add_to_cart"),
`place_order` = arrayIndexOf(steps,"place_order"),
`payment` = arrayIndexOf(steps,"payment")
// Replace -1 with null so we can compare order
| fieldsAdd
`add_to_cart` = if(`add_to_cart`>=0, `add_to_cart`, else: null),
`place_order` = if(`place_order`>=0, `place_order`, else: null),
`payment` = if(`payment`>=0, `payment`, else: null)
// Summarize and create a funnel array of steps
| summarize
funnel = array (
record(step="Add to cart", count=countIf(`add_to_cart`>=0)),
record(step="Place order", count=countIf(`add_to_cart`>=0 and `place_order`>`add_to_cart`)),
record(step="Payment", count=countIf(`add_to_cart`>=0 and `place_order`>`add_to_cart` and `payment`>`place_order`))
)
// // Expand events into separate records
| expand funnel
| fieldsFlatten funnel
| fieldsRemove funnel
Example in the playground
Does anyone know a better solution? @KlausEnzenhofer
