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

The browser and the visit a recording came from, when the browser told
PhoenixReplay (see `PhoenixReplay.Capture.Browser`):

  * `:viewport` — `%{width: integer, height: integer, dpr: number}` when
    the LiveView connected; later changes are `:viewport` events
  * `:user_agent` — the `User-Agent` header, when the endpoint's socket
    lists `:user_agent` in its `:connect_info`
  * `:tab` — an id of the browser tab, shared by the tab's sessions
  * `:navigated_from` — the URL of the LiveView that live-navigated here
  * `:headers` — request headers listed in the `:client` config, kept by
    `PhoenixReplay.Plug`
  * `:landing` — the visit's first request, when the `:client` config asks for it;
    see `PhoenixReplay.Recording.Client.Landing`

Its functions describe the device, named from its user agent with
`UAParser`, and where the visit came from.

# `device_type`

```elixir
@type device_type() :: String.t()
```

The kind of device a session ran on, by its viewport's width; see `device_type/1`.

# `t`

```elixir
@type t() :: %PhoenixReplay.Recording.Client{
  headers: %{required(String.t()) =&gt; String.t()},
  landing: PhoenixReplay.Recording.Client.Landing.t() | nil,
  navigated_from: String.t() | nil,
  tab: String.t() | nil,
  user_agent: String.t() | nil,
  viewport: PhoenixReplay.Recording.viewport() | nil
}
```

# `browser_family`

```elixir
@spec browser_family(String.t() | nil) :: String.t() | nil
```

The browser in a user agent, without its version, such as `"Mobile
Safari"`, or `nil` when it is not recognized.

# `campaign`

```elixir
@spec campaign(map()) :: String.t() | nil
```

Describes a landing's campaign as `"google / cpc / spring_sale"`, from
its UTM source, medium and campaign, or returns `nil` without them.

# `decode_viewport`

```elixir
@spec decode_viewport(String.t() | nil) :: PhoenixReplay.Recording.viewport() | nil
```

Reads a viewport written by `encode_viewport/1`, or `nil`.

# `default_viewport`

```elixir
@spec default_viewport() :: PhoenixReplay.Recording.viewport()
```

The viewport a recording without one is shown at, such as in an export.

# `device`

```elixir
@spec device(String.t() | nil) :: String.t() | nil
```

Names the browser, with its major version, and the system in a user
agent, such as `"Mobile Safari 18 on iOS"`, or returns `nil` when neither
is recognized.

# `device_type`

```elixir
@spec device_type(PhoenixReplay.Recording.viewport() | nil) :: device_type() | nil
```

The kind of device a viewport belongs to, by its width in CSS pixels:
`"phone"` below 640, `"tablet"` below 1024, `"desktop"` otherwise, or
`nil` without a viewport.

# `device_types`

```elixir
@spec device_types() :: [device_type()]
```

The kinds of device `device_type/1` tells apart.

# `encode_viewport`

```elixir
@spec encode_viewport(PhoenixReplay.Recording.viewport() | nil) :: String.t() | nil
```

Writes a viewport as `"390x844@3"`, compact for storing alongside a
summary, or `nil`.

# `media`

```elixir
@spec media(PhoenixReplay.Recording.viewport() | nil) :: %{
  required(String.t()) =&gt; String.t()
}
```

A viewport's media settings as the CSS media features they are, for the
replay to apply to the replayed page's media rules: `%{"pointer" =>
"coarse", "prefers-color-scheme" => "dark", ...}`, with those the browser
did not report left out.

# `orientation`

```elixir
@spec orientation(%{
  :width =&gt; pos_integer(),
  :height =&gt; pos_integer(),
  optional(atom()) =&gt; term()
}) ::
  :portrait | :landscape
```

A viewport's orientation as CSS's `orientation` media feature tells it:
portrait when it is at least as tall as it is wide.

# `referrer_host`

```elixir
@spec referrer_host(String.t() | nil) :: String.t() | nil
```

The host of a referrer URL, such as `"news.ycombinator.com"`, or `nil`.

# `traffic`

```elixir
@spec traffic(t()) :: PhoenixReplay.Recording.Traffic.t()
```

Where the visit came from, as Google Analytics tells it; see
`PhoenixReplay.Recording.Traffic`.

# `upgrade`

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

Brings a client context stored by an earlier version up to date: plain
maps before 0.6, which named `:navigated_from` `:referer`.

---

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