# Connection milestones

`ConnectionMilestones` records when a site first connects to Power and when
its connection state last changed. WP Data Collector reads the option to
measure time from first connection to chatbot enablement. The chatbot half
lives in the chatbot plugin's
[telemetry doc](../../../plugins/chatbot/docs/telemetry.md).

## Option

`wpe_auth_connection_milestones` — one non-autoloaded array:

| Key | Type | Meaning |
| --- | --- | --- |
| `connected` | `bool` | Last observed connection state. |
| `first_connected_at` | `int` or `null` | Unix epoch seconds (UTC) of the first observed connection. Write-once. `null` until the site is seen connected. |
| `updated_at` | `int` | Unix epoch seconds (UTC) of the last change to `connected`. |

The option holds no user-identifying data.

## When it changes

- **Connect:** `Register::promote_pending_to_options()` records `connected = true`
  when it sets `wpe_auth_registered`.
- **Disconnect:** `Core::clear_registration()` records `connected = false`. The
  known clear paths route through it: explicit disconnect, site-copy and
  URL-drift detection, heartbeat revocation, and key migrations. None of them
  reset `first_connected_at`. Any future path that clears registration without
  calling `clear_registration()` would be missed until the next reconcile.
- **Reconcile:** on `admin_init`, the observed state
  (`wpe_auth_is_connected()`) is recorded. This catches changes made before
  these hooks load, and is the backstop for any write path not listed above.
- **Uninstall:** `Core::clear_all()` deletes the option.

Writes are idempotent: recording the stored state again changes nothing.

## Copied sites

The option is copied along with the rest of `wp_options`, so a clone reports
its origin's `first_connected_at` until copy detection clears the registration
and a later reconnect leaves the original timestamp in place. The value is
therefore not unique per site: collector-side analysis should deduplicate on
site identity rather than treating each reporting site as a distinct first
connection.

## Existing installs

Sites connected before this option existed get it on their next wp-admin
request. For them `first_connected_at` is the observation time, not the real
connection date, and nothing marks it as backfilled. Analytics should expect
that cohort's time-to-enable figures to be understated.
