# Stats section

Show beautiful stats for your site or shop: revenues, orders, likes, views, etc.

****

- Source: <https://github.com/getkirby/kirby/tree/5.5.3/config/sections/stats.php>

****

<figure class="image"><a data-lightbox href="https://assets.getkirby.com/media/pages/docs/reference/panel/sections/stats/2932154912-1717846665/stats-section.png?width=2136&amp;height=468&amp;enlarge=0"><img alt="" class="rounded" height="202" loading="lazy" sizes="auto" src="https://assets.getkirby.com/media/pages/docs/reference/panel/sections/stats/2932154912-1717846665/stats-section.png?width=924&amp;height=202&amp;enlarge=0" srcset="https://assets.getkirby.com/media/pages/docs/reference/panel/sections/stats/2932154912-1717846665/stats-section.png?width=462&amp;height=101&amp;enlarge=0 462w, https://assets.getkirby.com/media/pages/docs/reference/panel/sections/stats/2932154912-1717846665/stats-section.png?width=690&amp;height=151&amp;enlarge=0 690w, https://assets.getkirby.com/media/pages/docs/reference/panel/sections/stats/2932154912-1717846665/stats-section.png?width=924&amp;height=202&amp;enlarge=0 924w, https://assets.getkirby.com/media/pages/docs/reference/panel/sections/stats/2932154912-1717846665/stats-section.png?width=1380&amp;height=302&amp;enlarge=0 1380w, https://assets.getkirby.com/media/pages/docs/reference/panel/sections/stats/2932154912-1717846665/stats-section.png?width=1848&amp;height=405&amp;enlarge=0 1848w" width="924"></a></figure>

## Example

```yaml
title: Shop
sections:
  stats:
    type: stats
    # Available size options: small, medium, large, huge. Default is large
    size: huge
    reports:
      - label: Revenue
        value: €29,682
        info: +112.5%
        link: https://getkirby.com/shop
        theme: positive
      - label: Orders
        value: 265
        info: +82.8%
        theme: positive
      - label: Avg. Transaction
        value: €112.01
        info: +16.3%
        theme: positive
      - label: Refunds
        value: €15.20
        info: +10.5%
        theme: positive
      - label: Discount sales
        value: €1,422
        info: n/a
```

## Section shortcuts

For simple sections that are only used once per blueprint, you can use shortcuts. In its most basic form, a `stats` section consists of the section type as name, and the `reports` property with the information you want to show.

```yaml
sections:
  stats:
    reports: ...
```

Keep in mind that the same section name can only be used once per blueprint.

## Section properties



<div class="table">
	<table class="parameters">
		<thead>
			<tr>
				<th>Name</th>
				<th>Type</th>
				<th>Default</th>

								<th>Description</th>
							</tr>
		</thead>
		<tbody>
						<tr>
				<td>
					headline				</td>
				<td><code class="type type-mixed">mixed</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>The headline for the section. This can be a simple string or a template with additional info from the parent page.</td>
							</tr>
						<tr>
				<td>
					label				</td>
				<td><code class="type type-mixed">mixed</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>The label for the section. This can be a simple string or a template with additional info from the parent page. Replaces the <code class="type">headline</code> prop.</td>
							</tr>
						<tr>
				<td>
					reports				</td>
				<td><code class="type type-array">array</code><span class="px-1 color-gray-400" aria-hidden="true">|</span><span class="sr-only">or</span><code class="type type-string">string</code></td>

				<td data-label="Default:">
															<code>null</code>
									</td>

								<td>Array or query string for reports. Each report needs a <code class="type">label</code> and <code class="type">value</code> and can have additional <code class="type">info</code>, <code class="type">link</code>, <code class="type">icon</code> and <code class="type">theme</code> settings.</td>
							</tr>
						<tr>
				<td>
					size				</td>
				<td><code class="type type-string">string</code></td>

				<td data-label="Default:">
															<code>'large'</code>
									</td>

								<td>The size of the report cards. Available sizes: <code class="type">tiny</code>, <code class="type">small</code>, <code class="type">medium</code>, <code class="type">large</code></td>
							</tr>
					</tbody>
	</table>
</div>

## Reports

You can add as many reports to your stats section as needed. Each report can be customized to fit your data.

### Label & Value

Each report must have a label and value

```yaml
stats:
  type: stats
  reports:
    - label: Revenue
      value: €29,682
```

### Info

The info text is shown below the value and is optional. It can be fully customized.

```yaml
stats:
  type: stats
  reports:
    - label: Revenue
      value: €29,682
      info: +112.5%
```

### Links, dialogs or drawers

Reports can link to a URL or open a dialog/drawer for more details.

```yaml
stats:
  type: stats
  reports:
    - label: Revenue
      value: €29,682
      info: +112.5%
      link: /revenue
    - label: Orders
      value: 265
      dialog: orders/details
    - label: Top customers
      value: 12
      drawer: customers/top
```

### Icons

You can add an <a href="https://getkirby.com/docs/reference/panel/icons">icon</a> for each report:

```yaml
stats:
  type: stats
  reports:
    - label: Revenue
      value: €29,682
      icon: store
```

### Themes

You can colorize the info value with the theme option. Available themes are:

- `positive` (green)
- `negative` (red)
- `notice` (orange)
- `info` (blue)

```yaml
stats:
  type: stats
  reports:
    - label: Revenue
      value: €29,682
      info: +112.5%
      theme: positive
```

### Translations

All parts of a report can be translated by defininig an associative array with translations

```yaml
stats:
  type: stats
  reports:
    - label:
        de: Revenue
        en: Umsatz
      value: €29,682
      info: +112.5%
```

### Template strings

A report can be dynamic by querying data from pages, sites, collections or custom methods from plugins.

```yaml
stats:
  type: stats
  reports:
    - label: Revenue
      value: "{{ page.revenue }}"
      info: "{{ page.revenueIncrease }}"
```

Here's a simplified example for a revenue method in a page model.
```php "/site/models/shop.php"
class ShopPage extends Page
{
  public function revenue(): string
  {
    return '€29,682'
  }
}
```

### Queries

You can also generate an entire report in a page method for example and return an associative array with the report parts (label, value, info, theme, link). This will add extra flexibility and you can use logic in your methods to create dynamic reports.

```yaml
stats:
  type: stats
  reports:
    - page.revenueReport
    - page.ordersReport
    - page.discountsReport
```

Here's an example for the custom page method in a shop page model to create the revenue report.

```php "/site/models/shop.php"
class ShopPage extends Page
{
  public function revenueReport(): array
  {
    return [
      'label' => 'Revenue',
      'value' => // calculate revenue here
    ];
  }
}
```

Instead of querying individual reports, you can also query the entire report array at once:

```yaml
stats:
  type: stats
  reports: page.reports
```

```php "/site/models/shop.php"
class ShopPage extends Page
{
  public function reports(): array
  {
    return [
      [
        'label' => 'Revenue',
        'value' => // calculate revenue here
      ],
      [
        'label' => 'Orders',
        'value' => // count orders
      ],
    ];
  }
}

```

## Size

The size option controls the size of the report cards.

Available sizes:

- `small`
- `medium`
- `large`
- `huge`