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

# upstack query-attribution

> Run an attribution query from the command line. Wraps POST /api/query-attribution.

Run an attribution query. Wraps `POST /api/query-attribution` — see the [API reference](/api-reference/overview).

## Usage

```bash theme={null}
upstack query-attribution \
  --dimension utm_source \
  --model first_click \
  --window 30 \
  --date-start 2026-04-01 \
  --date-end 2026-04-30
```

## Required flags

| Flag                                                  | Description                                                                    |
| ----------------------------------------------------- | ------------------------------------------------------------------------------ |
| `--dimension <d>`                                     | Dimension to attribute by (e.g. `utm_source`, `utm_campaign`).                 |
| `--model <m>`                                         | `first_click`, `last_click`, or `any_click`.                                   |
| `--window <days>`                                     | Attribution window. One of `1`, `7`, `14`, `30`, `60`, `90`, `-1` (unlimited). |
| `--date-start <YYYY-MM-DD>` `--date-end <YYYY-MM-DD>` | Date range.                                                                    |

## Optional flags

| Flag                        | Description                                                                                                  | Default    |
| --------------------------- | ------------------------------------------------------------------------------------------------------------ | ---------- |
| `--filter <json>`           | Canonical [Filter](/cli/query#filters) as JSON. `attribution.utm_*` fields and `orders.*` fields apply here. |            |
| `--timezone <tz>`           | IANA timezone.                                                                                               | `UTC`      |
| `--value-source <s>`        | `orders` or `events`.                                                                                        | `orders`   |
| `--conversion-event <name>` | Required when `--value-source=events`.                                                                       | `purchase` |

See [`upstack query`](/cli/query#shared-flags) for the shared output / interactive / from-file flags.

## Examples

```bash theme={null}
# First-click attribution by UTM source, last 30 days
upstack query-attribution \
  --dimension utm_source --model first_click --window 30 \
  --date-start 2026-04-01 --date-end 2026-04-30

# Last-click, unlimited window, event-based valuation
upstack query-attribution \
  --dimension utm_campaign --model last_click --window -1 \
  --value-source events --conversion-event signup_completed \
  --date-start 2026-04-01 --date-end 2026-04-30

# Scope to one UTM source via canonical filter
upstack query-attribution \
  --dimension utm_campaign --model last_click --window 30 \
  --date-start 2026-04-01 --date-end 2026-04-30 \
  --filter '{"and":[{"field":"attribution.utm_source","op":"equals","value":"google"}]}'

# Interactive
upstack query-attribution -i
```

Run [`upstack filters --detail`](/cli/filters) to see every field valid in
the `attribution` context with its operators.
