# `PhoenixReplay.Recording.Summary`
[🔗](https://github.com/elixir-vibe/phoenix_replay/blob/v0.6.2/lib/phoenix_replay/recording/summary.ex#L1)

Lightweight description of a recording, used for listings and filtering.

Storage backends return summaries without decoding full recordings.
`event_names` are the distinct `handle_event/3` names, sorted, and
`marks` the moments the session reached, by name, with how many times;
see `PhoenixReplay.Recording.Event.mark_name/1`.
`error_count` counts the events for which `PhoenixReplay.Recording.Event.error?/1`
holds. `tab` is the browser tab the session ran in, when the client sent
it, shared by the sessions of one journey. `viewport`, `device`,
`device_type` and `browser` describe the browser, and `source`, `medium`
and `campaign` where the visit came from, as
`PhoenixReplay.Recording.Client` names them. `saved_at` is when storage
saved the recording, in Unix milliseconds, or `nil` before it is saved and
for recordings saved before PhoenixReplay 0.5. `live?` is true while the
recorded LiveView process is still running.

# `t`

```elixir
@type t() :: %PhoenixReplay.Recording.Summary{
  browser: String.t() | nil,
  campaign: String.t() | nil,
  connected_at: integer(),
  device: String.t() | nil,
  device_type: PhoenixReplay.Recording.Client.device_type() | nil,
  duration_ms: non_neg_integer(),
  error_count: non_neg_integer(),
  event_count: non_neg_integer(),
  event_names: [String.t()],
  id: PhoenixReplay.Recording.id(),
  live?: boolean(),
  marks: %{required(String.t()) =&gt; pos_integer()},
  medium: String.t() | nil,
  release: String.t() | nil,
  saved_at: integer() | nil,
  source: String.t() | nil,
  tab: String.t() | nil,
  url: String.t() | nil,
  view: String.t(),
  viewport: PhoenixReplay.Recording.viewport() | nil
}
```

# `totals`

```elixir
@type totals() :: %{
  event_count: non_neg_integer(),
  error_count: non_neg_integer(),
  event_names: [String.t()],
  marks: %{required(String.t()) =&gt; pos_integer()},
  duration_ms: non_neg_integer()
}
```

What a summary counts of a recording's events; see `totals/2`.

# `add_mark`

```elixir
@spec add_mark(%{required(String.t()) =&gt; pos_integer()}, String.t() | nil) :: %{
  required(String.t()) =&gt; pos_integer()
}
```

Adds one reaching of the mark `name` to `marks`, as `totals/2` counts them.

# `counts`

```elixir
@spec counts(PhoenixReplay.Recording.Event.t()) ::
  {0 | 1, 0 | 1, String.t() | nil, String.t() | nil}
```

How one event adds to `totals/2`: `1` or `0` to the event count and to
the error count, its `handle_event/3` name, if it has one, and its name
as a mark, if it is one.
`PhoenixReplay.Session.Buffer` keeps running totals with it as events
are written.

# `new`

```elixir
@spec new(PhoenixReplay.Recording.t(), keyword()) :: t()
```

Summarizes a recording.

# `sort`

```elixir
@spec sort([t()]) :: [t()]
```

Orders summaries most recent first. Sessions that started in the same
millisecond are ordered by id, so pages never repeat or skip them.

# `stored_at`

```elixir
@spec stored_at(t()) :: integer()
```

When the recording reached storage: `saved_at`, or `connected_at` for
recordings saved before PhoenixReplay 0.5 recorded it. Lists are read
as of a moment by this time, so recordings saved later wait instead of
shifting the rows.

# `totals`

```elixir
@spec totals([PhoenixReplay.Recording.Event.t()], totals()) :: totals()
```

Counts `events` into `totals`, which start at zero: every event but
pointer batches and client state, which are not shown as events; the events for which
`PhoenixReplay.Recording.Event.error?/1` holds; the distinct
`handle_event/3` names, sorted; the marks reached, by name, with how
many times; and the time of the last event.

A recording flushed to storage in chunks is counted chunk by chunk.

# `upgrade`

```elixir
@spec upgrade(t()) :: t()
```

Brings a summary saved by an earlier version up to date. Before 0.6,
`source` held the campaign as `"google / cpc / spring"`, now split into
`source`, `medium` and `campaign`, and there was no `device_type`.
The browser's family cannot be told from the `device` saved then, so
`browser` stays `nil`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
