# CLI guide

How the CLI fits into your work: set up a project, fail a deploy when tracking breaks, mark releases and hand speed fixes to an agent.

The Ultanimus CLI covers the parts of analytics that happen next to your code: setting up a project, checking a deploy, marking a release, keeping goals and dashboards in code, and reading a report from a terminal or a build. The dashboard covers everything else. This page shows where the CLI fits, and the [command reference](/docs/cli) lists every option.

## For developers

### Set up a new project

```bash
npx @ultanimus/cli init
```

`init` finds the framework, adds the package or the script tag to your root layout, and saves the site ID in `ultanimus.config.json`. After you deploy, it waits for the first event from the live site, so you see tracking work before you close the terminal. Add `--vitals --load` to measure page speed and page weight from the start.

It changes the root layout, `package.json` and the config file. When it cannot find the layout, it prints the code to paste instead. Review the diff as you would any other change, and commit the config file.

### Fail a deploy when tracking breaks

A Content Security Policy change or a layout refactor can drop the script without any error, and you find out when the numbers fall. `check` loads the live page and exits with 1 when the script is missing, blocked by the policy, or sent no events in the last day, so the job fails instead.

Add it after your deploy step, with an API key in your CI secrets. The job reads the site from the committed `ultanimus.config.json`.

```yaml
- name: Check tracking and mark the release
  run: |
    npx @ultanimus/cli check https://example.com
    npx @ultanimus/cli annotate "Deployed ${GITHUB_SHA::7}"
  env:
    ULTANIMUS_API_KEY: ${{ secrets.ULTANIMUS_API_KEY }}
```

On Glance, the API keys page creates no keys, so leave the key and the `annotate` line out. `check` still tests the page and its policy, and skips the events check.

When a job fails on its key, run `ultanimus whoami` first. It prints the organization and plan the key belongs to, and exits with 1 when the key no longer works.

### Mark releases on the charts

`annotate` puts a note on the site's charts at the time it runs. When a number moves, the note shows which release came just before. Running it from the deploy job, as above, means nobody has to remember. It needs Insight or Foresight.

### Review analytics changes like code

Goals, funnels and dashboards can live in `ultanimus.config.json` next to your code. `ultanimus pull` writes the site's into the file. After that, a new goal is a line in a pull request: the reviewer sees it, CI shows what it changes on the site, and the merge applies it.

```yaml
name: Analytics setup
on:
  pull_request:
    paths: ['ultanimus.config.json']
  push:
    branches: [main]
    paths: ['ultanimus.config.json']

jobs:
  setup:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Show what would change
        if: github.event_name == 'pull_request'
        run: npx @ultanimus/cli diff
        env:
          ULTANIMUS_API_KEY: ${{ secrets.ULTANIMUS_API_KEY }}
      - name: Apply the file
        if: github.event_name == 'push'
        run: npx @ultanimus/cli push --yes
        env:
          ULTANIMUS_API_KEY: ${{ secrets.ULTANIMUS_API_KEY }}
```

`diff` needs a key that reads stats, and `push` a key that can change dashboards. A push saves the whole file or nothing, so a mistake in one goal never leaves the site half updated. The server checks every item with the same rules as the dashboard's editors, and the job fails with the file path and the item when one breaks a rule.

Items you delete from the file stay on the site until you add `--prune` to the push. Its key then needs Delete dashboards (`dashboards:delete`). To run staging and production from one file, add a second push with `--site staging.example.com`.

### Send sitemaps we cannot fetch

We look for your sitemap when you add a site and every week after. A login or bot protection stops that, so push the sitemap after the build instead.

```bash
npx @ultanimus/cli sitemap push out/sitemap.xml
```

Fields that ask for a page path then suggest your pages. If we can fetch your sitemap, you can skip this. The upload works once the site has sent its first event, so run it after the deploy that adds the script.

### Hand speed fixes to a coding agent

`vitals` and `load` print the same reports as the [Web vitals](/docs/dashboard/vitals) and [Load](/docs/dashboard/load) pages, from real visits. The fixes are ranked by the page loads they slow or the bytes they save. `--prompt` prints them as a brief for a coding agent.

```bash
ultanimus vitals --prompt | pbcopy
```

An agent that runs commands, such as Claude Code, can run `ultanimus vitals --prompt` itself and work through the list. The reports need samples first, so turn the add-ons on with `init --vitals --load` and let real visits come in. Both need Insight or Foresight.

### Use the numbers in a script

Every command prints JSON with `--json`.

```bash
ultanimus stats --range 7d --json | jq '.totals.visitors'
```

Exit codes are 0 when the command worked, 1 when it or a check failed, and 2 for a wrong command or option.

## For site owners

The CLI suits people who already work in a terminal. If that is you, a few commands save opening the dashboard.

- `ultanimus stats --range 7d` prints last week's visitors, visits, pageviews, bounce rate and visit duration against the week before, with the top five pages and sources.
- `ultanimus vitals` says whether the site passes Core Web Vitals, and what to fix first.
- `ultanimus whoami` shows the organization and plan you are signed in to.

If you do not use a terminal, the dashboard shows everything these commands print, and the weekly email sends last week's numbers every Monday.

## What it does not do

- It prints reports, but it does not filter, segment or explore them. The dashboard does.
- It cannot create alerts or segments. It manages goals, funnels and dashboards through `ultanimus.config.json`.
- It has no live view.
- `stats`, `vitals`, `load`, `errors`, `search`, `annotate`, `pull`, `diff` and `push` need Insight or Foresight. On Glance, `login`, `whoami`, `init`, `check` and `sitemap push` work.
