Browse docs
On this page

transaction command

Group related events into one row per transaction, such as each visitor's session, with its duration and event count.

All ObiQL commands

Groups related events into transactions: one row for each visitor's session, each order's journey, each request's log lines. Events that share a value of every field you name are put in time order and cut into transactions by the options you give.

Each transaction reads like an event. Its timestamp is its first event's, every other field lists the values its events had, and the message holds each event's message on its own line. It adds duration, the seconds from its first event to its last, and eventcount.

Every stage after it works on the transactions, so stats can measure them: how long sessions last, how many events they hold, how many end in a purchase.

Syntax

ObiQL
| transaction [<field>, ...] [maxspan=<time>] [maxpause=<time>] [maxevents=<count>] [startswith="<filter>"] [endswith="<filter>"] [keepevicted=true] [mvlist=true]

Square brackets mark an optional part, and angle brackets a value you supply.

Arguments

ArgumentRequiredDescription
<field>, ...OptionalThe fields whose values an event must share to join a transaction. Events missing any of them are left out. With no field, every event is a candidate for one transaction, cut only by the options.
maxpause=<time>OptionalThe longest gap allowed between two events in a row, such as 30m. A longer gap starts a new transaction. A plain number is seconds. No limit by default.
maxspan=<time>OptionalThe longest a transaction may last, first event to last. Longer runs are cut at fixed intervals counted from their first event. A plain number is seconds. No limit by default.
maxevents=<count>OptionalThe most events one transaction holds. Defaults to 1000. Use 0 for no limit.
startswith="<filter>"OptionalAn event matching this filter starts a new transaction. Write the filter in quotes, as in startswith="action=login", or in parentheses.
endswith="<filter>"OptionalAn event matching this filter ends its transaction, and the next event starts a new one.
keepevicted=trueOptionalKeep transactions that never saw their startswith or endswith event, and add closed_txn: 1 for a complete transaction, 0 for one that was not. By default they are left out.
mvlist=trueOptionalList every value of a field in event order, repeats included, instead of its distinct values.

Usage

  • Transactions are listed newest first, by the time of their first event. A sort after the stage orders them by anything else.
  • Only the events in the search's time range are grouped, so a transaction that started before the range begins at its first event inside it.
  • A field's values are joined with a comma, so mvexpand after the stage gives each value a row of its own.
  • Fields computed earlier in the query, by eval, extract, json or rename, are listed like any stored field.
  • transaction cannot follow stats, timechart, dedup, mvexpand, lookup, sort, limit or fields. Put those after it. A query can group transactions once.
  • Every event matching the search is held in memory while it is grouped, so a search grouping millions of events can hit the query's memory limit. Narrow the search, or the time range, if it does.

Examples

1. One row per visitor session

ObiQL
_service_type=user-analytics | transaction visitor_id maxpause=30m

A visitor's events belong to one session until they go quiet for more than 30 minutes, the usual web analytics rule.

2. How long sessions last

ObiQL
_service_type=user-analytics | transaction visitor_id maxpause=30m | stats count() AS sessions, avg(duration), p95(duration), avg(eventcount)

stats over transactions measures the sessions rather than the events in them.

3. Login to logout

ObiQL
| transaction session_id startswith="action=login" endswith="action=logout" | sort -duration

Each transaction runs from a login to the logout that follows it. Sessions that never logged out are left out; add keepevicted=true to see them too.

4. Sessions that reached checkout

ObiQL
| transaction visitor_id maxpause=30m | where page="*/checkout*" | fields visitor_id, duration, page

A where after the stage tests the transaction's listed values, so this keeps sessions in which any event was on a checkout page.