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

# ドメイン別の Citation Rank(差分付き)

> Citation Rank のリーダーボードを作成します。ドメインをシェア順に並べ、行ごとに前の期間からの pp 変化を表示します

Profound アプリで Citation Share タイルの横にある "Citation Rank" パネルは、
`root_domain` でグループ化した引用エンドポイントを `citation_share` の降順で並べたもので、
各行には前の期間からのシェアの変化が表示されます。2 回の呼び出し(現在と前の期間)を行い、
ドメインで結合して、シェアの差を求めます。

## この例の仕組み

1. **`dimensions: ["root_domain"]`** — 各呼び出しで、引用されたドメインごとに 1 行が返されます。
   現在の期間と前の期間の両方を実行します。
2. **ドメインで結合します。** 現在の期間の各行について、前の期間のシェアを
   調べ(存在しない場合のデフォルトは 0)、差を求めます。
3. UI に合わせて、**現在の `citation_share` の降順で並べ替えます**。

<Note>
  **`count` と `citation_share` は異なるものを測定します。** `count` は、
  期間内にそのドメインが引用された生の回数です。`citation_share` は、
  **AI モデルごとに** `count / total_citations` **を計算し、それをモデル間で
  平均したもの**です。低ボリュームのモデル(例: Perplexity)で多く引用されたドメインは、
  高ボリュームのモデル全体に分散してより多くの引用を得たドメインよりも、高いシェアになる
  ことがあります。2 つの列の並び順は一致しません。
  答えたい問いに合ったほうを選んで、それで並べ替えてください。
</Note>

<RequestExample>
  ```python Python theme={null}
  import os
  from datetime import date, timedelta
  from profound import Profound

  client = Profound(api_key=os.environ["PROFOUND_API_KEY"])

  # What to fetch — replace with your own values.
  CATEGORY_NAME = "<your-category-name>"
  DAYS          = 7
  INCLUSIVE_END = date(2026, 5, 11)    # the last day of your current window
  TOP_N         = 10


  def get_domain_shares(category_id, start, end):
      """Return {domain: share} for every cited domain in the window."""
      res = client.reports.citations(
          category_id=category_id,
          start_date=start.isoformat(),
          end_date=end.isoformat(),
          metrics=["count", "citation_share"],
          dimensions=["root_domain"],
          filters=[{"field": "prompt_type", "operator": "is", "value": "visibility"}],
          pagination={"limit": 50000, "offset": 0},
      )
      m = res.info.query["metrics"]
      d = res.info.query["dimensions"]
      i_count  = m.index("count")
      i_share  = m.index("citation_share")
      i_domain = d.index("root_domain")
      return {
          row.dimensions[i_domain]: {
              "count": row.metrics[i_count],
              "share": row.metrics[i_share],
          }
          for row in res.data
      }


  def current_and_prior_windows(inclusive_end, days):
      """Two (start, end_exclusive) pairs of equal length, back-to-back."""
      current = (
          inclusive_end - timedelta(days=days - 1),
          inclusive_end + timedelta(days=1),     # +1 day → exclusive end
      )
      prior = (current[0] - timedelta(days=days), current[0])
      return current, prior


  def find_category_id(name):
      """Return the UUID of the category whose name matches (case-insensitive)."""
      for c in client.organizations.categories.list():
          if c.name.lower() == name.lower():
              return c.id
      raise ValueError(f"No category named {name!r}")


  # Resolve name → ID, run current + prior, then build the leaderboard with deltas.
  category_id    = find_category_id(CATEGORY_NAME)
  current, prior = current_and_prior_windows(INCLUSIVE_END, DAYS)

  current_domains = get_domain_shares(category_id, *current)
  prior_domains   = get_domain_shares(category_id, *prior)

  rows = sorted(
      (
          {
              "domain":    name,
              "count":     d["count"],
              "share":     d["share"],
              "delta_pp":  (d["share"] - prior_domains.get(name, {"share": 0})["share"]) * 100,
          }
          for name, d in current_domains.items()
      ),
      key=lambda r: r["share"],
      reverse=True,
  )[:TOP_N]

  for rank, r in enumerate(rows, start=1):
      sign = "+" if r["delta_pp"] >= 0 else "−"
      delta_str = f"{sign}{abs(r['delta_pp']):.1f} pp"
      print(f"{rank:>2}. {r['domain']:<32} {r['share']:>6.1%}  {delta_str}")
  ```

  ```bash curl theme={null}
  export PROFOUND_API_KEY=your_api_key_here

  # Current window
  curl -X POST "https://api.tryprofound.com/v1/reports/citations" \
    -H "X-API-Key: $PROFOUND_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "category_id": "your-category-uuid",
      "start_date": "2026-05-05",
      "end_date": "2026-05-12",
      "metrics": ["count", "citation_share"],
      "dimensions": ["root_domain"],
      "filters": [{"field": "prompt_type", "operator": "is", "value": "visibility"}],
      "pagination": {"limit": 50000, "offset": 0}
    }'

  # Previous window — same body, prior dates. Merge by root_domain client-side
  # to compute the per-row share delta.
  curl -X POST "https://api.tryprofound.com/v1/reports/citations" \
    -H "X-API-Key: $PROFOUND_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "category_id": "your-category-uuid",
      "start_date": "2026-04-28",
      "end_date": "2026-05-05",
      "metrics": ["count", "citation_share"],
      "dimensions": ["root_domain"],
      "filters": [{"field": "prompt_type", "operator": "is", "value": "visibility"}],
      "pagination": {"limit": 50000, "offset": 0}
    }'
  ```
</RequestExample>

## ページレベルの内訳

`dimensions` の `root_domain` を `url` に置き換えると、上位の引用ドメインではなく、
上位の引用**ページ**(URL ごとに 1 行)を取得できます。
