> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nycadultedlabels.nyc/llms.txt
> Use this file to discover all available pages before exploring further.

# Analytics

> In-app analytics charts and MotherDuck warehouse analytics for district enrollment.

The app has two analytics surfaces:

| Surface        | Path                          | Who              | Data source                                |
| -------------- | ----------------------------- | ---------------- | ------------------------------------------ |
| **Analytics**  | `/admin/analytics`            | Admin, Data Lead | Live MongoDB aggregates                    |
| **MotherDuck** | `/admin/motherduck-analytics` | **Admin only**   | MotherDuck warehouse (synced from MongoDB) |

## In-app Analytics

**Admin → Analytics** shows enrollment, cabinet fill, print activity, and school breakdowns from MongoDB. Data Leads see school-scoped metrics; Admins see district-wide totals.

Use **Refresh** to reload the snapshot. Deeper tools (Enrollment, Activity Report, Print Reports, Cabinets) are linked from the same page.

<Frame caption="In-app Analytics — metric cards, enrollment/print charts, and school breakdown">
  <img src="https://mintcdn.com/district79/1aGp1Oo-djTFJjtB/images/screenshots/analytics-dashboard.png?fit=max&auto=format&n=1aGp1Oo-djTFJjtB&q=85&s=9aa108781bdeb495bbba366a00ce4546" alt="Analytics page with Students, Enrolled today, Cabinet fill, Prints metrics and charts" width="1400" height="1689" data-path="images/screenshots/analytics-dashboard.png" />
</Frame>

## MotherDuck Analytics (Admin only)

**Admin → MotherDuck** queries a [MotherDuck](https://motherduck.com) DuckDB warehouse over the [Postgres endpoint](https://motherduck.com/docs/key-tasks/authenticating-and-connecting-to-motherduck/postgres-endpoint/).

<Frame caption="MotherDuck Analytics — connection status, Sync from MongoDB, and warehouse charts">
  <img src="https://mintcdn.com/district79/1aGp1Oo-djTFJjtB/images/screenshots/motherduck-analytics.png?fit=max&auto=format&n=1aGp1Oo-djTFJjtB&q=85&s=1b11d44b959fab9ea2211ea9680f602a" alt="MotherDuck Analytics page showing Connected status and enrollment charts" width="1400" height="1717" data-path="images/screenshots/motherduck-analytics.png" />
</Frame>

### Setup

1. Create an account and access token at [app.motherduck.com](https://app.motherduck.com) (Settings → Access tokens).
2. Set environment variables on the server:

| Variable              | Required | Default                           |
| --------------------- | -------- | --------------------------------- |
| `MOTHERDUCK_TOKEN`    | Yes      | —                                 |
| `MOTHERDUCK_DATABASE` | No       | `student_label_analytics`         |
| `MOTHERDUCK_HOST`     | No       | `pg.us-east-1-aws.motherduck.com` |

3. Open **Admin → MotherDuck** and click **Sync from MongoDB**.

Sync creates the database (if needed), `students` and `sync_meta` tables, then loads a full student snapshot. Charts (14-day enrollments, status, schools) read from MotherDuck after sync.

<Tip>
  Re-run **Sync from MongoDB** after large imports or end-of-day so warehouse charts stay current. In-app Analytics always reflects live MongoDB without sync.
</Tip>

### APIs (Admin)

| Method | Path                              | Purpose                            |
| ------ | --------------------------------- | ---------------------------------- |
| `GET`  | `/api/admin/motherduck/status`    | Connection, row count, last sync   |
| `POST` | `/api/admin/motherduck/sync`      | Full MongoDB → MotherDuck snapshot |
| `GET`  | `/api/admin/motherduck/analytics` | Warehouse metrics for the UI       |

## ThoughtSpot (optional legacy)

The ThoughtSpot Liveboard embed may still be available at `/admin/thoughtspot-analytics` if `THOUGHTSPOT_*` env vars are set. MotherDuck is the primary warehouse path in navigation.

## Related pages

* [Enrollment dashboard](/admin/enrollment-dashboard)
* [Data Lead tools](/admin/data-lead-tools)
* [System architecture](/contributors/system-architecture)
