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

Keeps request context for the visit, so recordings can carry it.

LiveView sees only some request details when it connects. This plug
sees every request of the visit, copies what the `:client` config asks for into
the session, and `PhoenixReplay.Recorder` adds it to each recording's
`client` on the connected mount. Add it to the pipeline your live
sessions use, after `:fetch_session`:

    pipeline :browser do
      plug :accepts, ["html"]
      plug :fetch_session
      # ...
      plug PhoenixReplay.Plug
    end

With no headers or landing configured in `:client`, it does nothing.

## What it keeps

  * **headers** — the `:headers` allowlist, from the latest request,
    each value cut to 256 characters
  * **landing** — the visit's landing request, when `:landing` is
    configured: its URL path and time, the tracked query params, and the
    `Referer`. With `attribution: :first` it is written once per visit;
    with `:last` a request carrying tracked params replaces it.

A visit lasts as long as the session cookie. The session is rewritten
only when the kept context changes. Only `GET` requests are landings.

The kept context stays under 1 KB, so a crafted link cannot overflow a
cookie session: past that, the landing's params are dropped, then the
headers.

# `session_key`

```elixir
@spec session_key() :: String.t()
```

The session key the context is kept under.

---

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