---
layout: article
title: Metrics
description: How Appwrite Analytics calculates visitors, visits, pageviews, bounce rate, visit duration, and engagement time, which breakdowns it offers, and how to read metrics from your own code.
---

Every figure on an analytics dashboard comes from the events your property receives. This page defines each metric and breakdown, and shows how to read the same numbers from your own code.

# Dashboard metrics

The row of metrics at the top of the dashboard covers the selected date range.

- **Unique visitors**: distinct visitors in the range. Someone who returns several times counts once.
- **Visits**: visits that started in the range. A visit that started earlier doesn't count, even if it continued into the range.
- **Pageviews**: `pageview` and `screen_view` events, including repeat views of the same page or screen.
- **Views per visit**: pageviews divided by visits.
- **Bounce rate**: the share of visits with fewer than two pageviews.
- **Visit duration**: the average time from a visit's first event to its last. A visit with a single event counts as 0 seconds.
- **Engagement time**: the average active time per visit, counting only visits that reported any. On the web, a page is active while it's visible. In a Flutter app, the app is active while it's in the foreground.

**Bounce rate** and **Visit duration** cover the same visits as **Visits**: the ones that started in the range. The **Visits** chart is different: each point counts the visits with an event in that hour or day, so a visit that crosses midnight appears on both days, and the points can add up to more than the total.

With a **Page** or **Event** filter, the dashboard can't calculate totals for the whole range, so **Unique visitors** and **Visits** add up the chart's points. A visitor who returns on several days then counts once for each day, or once for each hour with **1h**.

Exports and the API also include **Scroll depth**, the average of the deepest scroll positions that pages reported, from `0` to `100` percent. The Web helper reports a page's scroll depth only if the visitor scrolled it.

These metrics include bot traffic. The **Humans vs bots** card shows how much of it comes from bots. For how Appwrite identifies visitors and splits their events into visits, see [Visitors and sessions](/docs/products/analytics/visitors).

# Breakdowns

The cards below the chart break traffic down by one dimension at a time and rank the values by visitors. The **Custom events** card is the exception: it ranks events by how many times they were sent. The API uses the same dimensions, by the names in this table, and ranks by visitors, except for `eventName`, which it ranks by event count. Unlike the card, `eventName` also includes the automatic events.

| Dimension | Dashboard card | Values |
| --- | --- | --- |
| `channel` | Traffic sources | `direct`, `search`, `ai`, `social`, `email`, `paid`, or `referral` |
| `referrerSource` | Traffic sources | The referring hostname, such as `google.com` |
| `utmSource`, `utmMedium`, `utmCampaign`, `utmContent`, `utmTerm` | Traffic sources | UTM parameters from the URL a visitor landed on |
| `page` | Pages | The page path, such as `/pricing` |
| `entryPage`, `exitPage` | Pages | The first and last page of each visit |
| `hostname` | Pages | The hostname of the page |
| `country` | Locations | Two-letter country code, such as `US`. The dashboard shows country names. |
| `region`, `city` | Locations | Region and city names, such as `California` |
| `browser` | Technology | Such as `Chrome`, `Mobile Safari`, or `Firefox` |
| `operatingSystem` | Technology | Such as `Windows`, `iOS`, `Mac`, or `Android` |
| `device` | Technology | Such as `desktop`, `smartphone`, or `tablet` |
| `screenSize` | Technology | `mobile`, `tablet`, `laptop`, or `desktop` |
| `trafficType` | Humans vs bots | `human` or `bot` |
| `botCategory`, `botName` | Humans vs bots, AI agents and crawlers | Such as `ai crawler` and `GPTBot` |
| `eventName` | Custom events | The event name |

Each row has the number of visitors, visits, and events with that value. In the API, visits are the `sessions` field. On **Entry pages** and **Exit pages**, they're the visits that started in the range. On every other breakdown, they're the visits with an event in the range. For how sources and channels are worked out, see [Traffic sources](/docs/products/analytics/sources). For bot categories, see [Bots and AI traffic](/docs/products/analytics/bots).

Screen sizes come from the viewport width: `mobile` below 576 pixels, `tablet` from 576 to 991, `laptop` from 992 to 1439, and `desktop` from 1440 up.

# Read metrics from your code

Read metrics with `listMetrics` and an API key that has the `analytics.read` scope. To create one, follow the steps in [Track events from your server](/docs/products/analytics/server-side#create-an-api-key) and select `analytics.read` instead.

This example lists the five countries with the most visitors over the last seven days.

```server-nodejs
import { Client, Analytics, AnalyticsDimension } from 'node-appwrite';

const client = new Client()
    .setEndpoint('https://<REGION>.cloud.appwrite.io/v1')
    .setProject('<PROJECT_ID>')
    .setKey('<API_KEY>');

const analytics = new Analytics(client);

const countries = await analytics.listMetrics({
    propertyId: '<PROPERTY_ID>',
    dimensions: [AnalyticsDimension.Country],
    dateRange: '7d',
    limit: 5,
});

for (const row of countries.metrics) {
    console.log(row.value, row.visitors);
}
```
```server-deno
import { Client, Analytics, AnalyticsDimension } from 'npm:node-appwrite';

const client = new Client()
    .setEndpoint('https://<REGION>.cloud.appwrite.io/v1')
    .setProject('<PROJECT_ID>')
    .setKey('<API_KEY>');

const analytics = new Analytics(client);

const countries = await analytics.listMetrics({
    propertyId: '<PROPERTY_ID>',
    dimensions: [AnalyticsDimension.Country],
    dateRange: '7d',
    limit: 5,
});

for (const row of countries.metrics) {
    console.log(row.value, row.visitors);
}
```
```server-php
<?php

require 'vendor/autoload.php';

use Appwrite\Client;
use Appwrite\Enums\AnalyticsDimension;
use Appwrite\Services\Analytics;

$client = (new Client())
    ->setEndpoint('https://<REGION>.cloud.appwrite.io/v1')
    ->setProject('<PROJECT_ID>')
    ->setKey('<API_KEY>');

$analytics = new Analytics($client);

$countries = $analytics->listMetrics(
    propertyId: '<PROPERTY_ID>',
    dimensions: [AnalyticsDimension::COUNTRY()],
    dateRange: '7d',
    limit: 5,
);

foreach ($countries->metrics as $row) {
    echo $row->value, ' ', $row->visitors, PHP_EOL;
}
```
```server-python
from appwrite.client import Client
from appwrite.enums.analytics_dimension import AnalyticsDimension
from appwrite.services.analytics import Analytics

client = Client()
client.set_endpoint('https://<REGION>.cloud.appwrite.io/v1')
client.set_project('<PROJECT_ID>')
client.set_key('<API_KEY>')

analytics = Analytics(client)

countries = analytics.list_metrics(
    property_id='<PROPERTY_ID>',
    dimensions=[AnalyticsDimension.COUNTRY],
    date_range='7d',
    limit=5,
)

for row in countries.metrics:
    print(row.value, row.visitors)
```
```server-ruby
require 'appwrite'

include Appwrite
include Appwrite::Enums

client = Client.new
    .set_endpoint('https://<REGION>.cloud.appwrite.io/v1')
    .set_project('<PROJECT_ID>')
    .set_key('<API_KEY>')

analytics = Analytics.new(client)

countries = analytics.list_metrics(
    property_id: '<PROPERTY_ID>',
    dimensions: [AnalyticsDimension::COUNTRY],
    date_range: '7d',
    limit: 5
)

countries.metrics.each do |row|
    puts "#{row.value} #{row.visitors}"
end
```
```server-dotnet
using Appwrite;
using Appwrite.Enums;
using Appwrite.Services;

var client = new Client()
    .SetEndpoint("https://<REGION>.cloud.appwrite.io/v1")
    .SetProject("<PROJECT_ID>")
    .SetKey("<API_KEY>");

var analytics = new Analytics(client);

var countries = await analytics.ListMetrics(
    propertyId: "<PROPERTY_ID>",
    dimensions: new List<AnalyticsDimension> { AnalyticsDimension.Country },
    dateRange: "7d",
    limit: 5
);

foreach (var row in countries.Metrics)
{
    Console.WriteLine($"{row.Value} {row.Visitors}");
}
```
```server-dart
import 'package:dart_appwrite/dart_appwrite.dart';
import 'package:dart_appwrite/enums.dart' as enums;

Future<void> main() async {
  final client = Client()
      .setEndpoint('https://<REGION>.cloud.appwrite.io/v1')
      .setProject('<PROJECT_ID>')
      .setKey('<API_KEY>');

  final analytics = Analytics(client);

  final countries = await analytics.listMetrics(
    propertyId: '<PROPERTY_ID>',
    dimensions: [enums.AnalyticsDimension.country],
    dateRange: '7d',
    limit: 5,
  );

  for (final row in countries.metrics) {
    print('${row.value} ${row.visitors}');
  }
}
```
```server-kotlin
import io.appwrite.Client
import io.appwrite.enums.AnalyticsDimension
import io.appwrite.services.Analytics

suspend fun main() {
    val client = Client()
        .setEndpoint("https://<REGION>.cloud.appwrite.io/v1")
        .setProject("<PROJECT_ID>")
        .setKey("<API_KEY>")

    val analytics = Analytics(client)

    val countries = analytics.listMetrics(
        propertyId = "<PROPERTY_ID>",
        dimensions = listOf(AnalyticsDimension.COUNTRY),
        dateRange = "7d",
        limit = 5,
    )

    for (row in countries.metrics) {
        println("${row.value} ${row.visitors}")
    }
}
```
```server-swift
import Appwrite
import AppwriteEnums

let client = Client()
    .setEndpoint("https://<REGION>.cloud.appwrite.io/v1")
    .setProject("<PROJECT_ID>")
    .setKey("<API_KEY>")

let analytics = Analytics(client)

let countries = try await analytics.listMetrics(
    propertyId: "<PROPERTY_ID>",
    dimensions: [.country],
    dateRange: "7d",
    limit: 5
)

for row in countries.metrics {
    print(row.value ?? "", row.visitors)
}
```
```server-go
package main

import (
    "fmt"
    "log"

    "github.com/appwrite/sdk-for-go/v7/appwrite"
)

func main() {
    client := appwrite.NewClient(
        appwrite.WithEndpoint("https://<REGION>.cloud.appwrite.io/v1"),
        appwrite.WithProject("<PROJECT_ID>"),
        appwrite.WithKey("<API_KEY>"),
    )

    analytics := appwrite.NewAnalytics(client)

    countries, err := analytics.ListMetrics(
        "<PROPERTY_ID>",
        analytics.WithListMetricsDimensions([]string{"country"}),
        analytics.WithListMetricsDateRange("7d"),
        analytics.WithListMetricsLimit(5),
    )
    if err != nil {
        log.Fatal(err)
    }

    for _, row := range countries.Metrics {
        fmt.Println(*row.Value, row.Visitors)
    }
}
```
```server-rust
use appwrite::Client;
use appwrite::enums::AnalyticsDimension;
use appwrite::services::Analytics;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new();
    client.set_endpoint("https://<REGION>.cloud.appwrite.io/v1");
    client.set_project("<PROJECT_ID>");
    client.set_key("<API_KEY>");

    let analytics = Analytics::new(&client);

    let countries = analytics.list_metrics(
        "<PROPERTY_ID>",
        None, // queries
        None, // interval
        Some(vec![AnalyticsDimension::Country]),
        Some("7d"),
        None, // start_at
        None, // end_at
        Some(5),
        None, // total
    ).await?;

    for row in countries.metrics {
        println!("{} {}", row.value.unwrap_or_default(), row.visitors);
    }

    Ok(())
}
```
```bash
appwrite client \
    --endpoint https://<REGION>.cloud.appwrite.io/v1 \
    --project-id '<PROJECT_ID>' \
    --key '<API_KEY>'

appwrite analytics list-metrics \
    --property-id '<PROPERTY_ID>' \
    --dimensions country \
    --date-range 7d \
    --limit 5
```
```curl
curl -G 'https://<REGION>.cloud.appwrite.io/v1/analytics/properties/<PROPERTY_ID>/metrics' \
    -H 'X-Appwrite-Project: <PROJECT_ID>' \
    -H 'X-Appwrite-Key: <API_KEY>' \
    --data-urlencode 'dimensions[]=country' \
    --data-urlencode 'dateRange=7d' \
    --data-urlencode 'limit=5'
```

## Response shapes

`listMetrics` returns one of three shapes, depending on whether you pass `dimensions` or `interval`. You can't pass both.

| You pass | You get | Fields |
| --- | --- | --- |
| Neither | One row with totals for the whole range | Every metric on this page |
| `dimensions` | One row per value, ranked by visitors (`eventName` by events), with `value` set | `visitors`, `sessions`, and `events` |
| `interval` | One row per time bucket, oldest first, with `date` set | `visitors`, `sessions`, `pageviews`, and `events` |

Without `dimensions` or `interval`, the single row looks like this:

```json
{
    "total": 1,
    "metrics": [
        {
            "value": null,
            "date": null,
            "visitors": 14212,
            "sessions": 22603,
            "pageviews": 63207,
            "events": 144886,
            "visits": 22601,
            "bounceRate": 46.9,
            "visitDuration": 77.01,
            "viewsPerVisit": 2.79,
            "scrollDepth": 61.3,
            "engagementTime": 75
        }
    ]
}
```

`visitDuration` and `engagementTime` are in seconds. `bounceRate` and `scrollDepth` are percentages.

`sessions` and `visits` count visits in two ways. `sessions` counts every visit with an event in the range. `visits` counts only the visits that started in it, like **Visits** on the dashboard. They differ when a visit started before the range.

## Parameters

| Parameter | Description |
| --- | --- |
| `dimensions` | One dimension to break down by, from the [breakdowns](#breakdowns) table. |
| `interval` | The bucket size for a time series: `1h`, `1d`, `1w`, or `1m`. Buckets start in UTC. |
| `dateRange` | The length of the range in days, such as `7d`. Defaults to `30d`. Any other format, such as `2w`, also falls back to `30d`. |
| `startAt`, `endAt` | Exact bounds in ISO 8601. Times without an offset are UTC. With both, they override `dateRange`. With only `startAt`, the range ends now. With only `endAt`, the range is `dateRange` long and ends at `endAt`. |
| `queries` | Up to 10 filters. See [Filter metrics](#filters). |
| `limit` | The number of rows a breakdown returns, from 1 to 500. Defaults to 100. |

A range never starts before your plan's [data retention](/docs/products/analytics/limits#retention).

## Filter metrics

Filters narrow the events every metric is calculated from. Each filter is a query on a dimension, using `equal`, `notEqual`, `contains`, `startsWith`, or `endsWith`. This example returns daily visitors who arrived from search engines over the last two weeks.

```server-nodejs
import { Client, Analytics, AnalyticsInterval, Query } from 'node-appwrite';

const client = new Client()
    .setEndpoint('https://<REGION>.cloud.appwrite.io/v1')
    .setProject('<PROJECT_ID>')
    .setKey('<API_KEY>');

const analytics = new Analytics(client);

const days = await analytics.listMetrics({
    propertyId: '<PROPERTY_ID>',
    interval: AnalyticsInterval.OneDay,
    dateRange: '14d',
    queries: [Query.equal('channel', 'search')],
});

for (const row of days.metrics) {
    console.log(row.date, row.visitors);
}
```
```server-deno
import { Client, Analytics, AnalyticsInterval, Query } from 'npm:node-appwrite';

const client = new Client()
    .setEndpoint('https://<REGION>.cloud.appwrite.io/v1')
    .setProject('<PROJECT_ID>')
    .setKey('<API_KEY>');

const analytics = new Analytics(client);

const days = await analytics.listMetrics({
    propertyId: '<PROPERTY_ID>',
    interval: AnalyticsInterval.OneDay,
    dateRange: '14d',
    queries: [Query.equal('channel', 'search')],
});

for (const row of days.metrics) {
    console.log(row.date, row.visitors);
}
```
```server-php
<?php

require 'vendor/autoload.php';

use Appwrite\Client;
use Appwrite\Enums\AnalyticsInterval;
use Appwrite\Query;
use Appwrite\Services\Analytics;

$client = (new Client())
    ->setEndpoint('https://<REGION>.cloud.appwrite.io/v1')
    ->setProject('<PROJECT_ID>')
    ->setKey('<API_KEY>');

$analytics = new Analytics($client);

$days = $analytics->listMetrics(
    propertyId: '<PROPERTY_ID>',
    interval: AnalyticsInterval::ONEDAY(),
    dateRange: '14d',
    queries: [Query::equal('channel', 'search')],
);

foreach ($days->metrics as $row) {
    echo $row->date, ' ', $row->visitors, PHP_EOL;
}
```
```server-python
from appwrite.client import Client
from appwrite.enums.analytics_interval import AnalyticsInterval
from appwrite.query import Query
from appwrite.services.analytics import Analytics

client = Client()
client.set_endpoint('https://<REGION>.cloud.appwrite.io/v1')
client.set_project('<PROJECT_ID>')
client.set_key('<API_KEY>')

analytics = Analytics(client)

days = analytics.list_metrics(
    property_id='<PROPERTY_ID>',
    interval=AnalyticsInterval.ONE_DAY,
    date_range='14d',
    queries=[Query.equal('channel', 'search')],
)

for row in days.metrics:
    print(row.date, row.visitors)
```
```server-ruby
require 'appwrite'

include Appwrite
include Appwrite::Enums

client = Client.new
    .set_endpoint('https://<REGION>.cloud.appwrite.io/v1')
    .set_project('<PROJECT_ID>')
    .set_key('<API_KEY>')

analytics = Analytics.new(client)

days = analytics.list_metrics(
    property_id: '<PROPERTY_ID>',
    interval: AnalyticsInterval::ONE_DAY,
    date_range: '14d',
    queries: [Query.equal('channel', 'search')]
)

days.metrics.each do |row|
    puts "#{row.date} #{row.visitors}"
end
```
```server-dotnet
using Appwrite;
using Appwrite.Enums;
using Appwrite.Services;

var client = new Client()
    .SetEndpoint("https://<REGION>.cloud.appwrite.io/v1")
    .SetProject("<PROJECT_ID>")
    .SetKey("<API_KEY>");

var analytics = new Analytics(client);

var days = await analytics.ListMetrics(
    propertyId: "<PROPERTY_ID>",
    interval: AnalyticsInterval.OneDay,
    dateRange: "14d",
    queries: new List<string> { Query.Equal("channel", "search") }
);

foreach (var row in days.Metrics)
{
    Console.WriteLine($"{row.Date} {row.Visitors}");
}
```
```server-dart
import 'package:dart_appwrite/dart_appwrite.dart';
import 'package:dart_appwrite/enums.dart' as enums;

Future<void> main() async {
  final client = Client()
      .setEndpoint('https://<REGION>.cloud.appwrite.io/v1')
      .setProject('<PROJECT_ID>')
      .setKey('<API_KEY>');

  final analytics = Analytics(client);

  final days = await analytics.listMetrics(
    propertyId: '<PROPERTY_ID>',
    interval: enums.AnalyticsInterval.oneDay,
    dateRange: '14d',
    queries: [Query.equal('channel', 'search')],
  );

  for (final row in days.metrics) {
    print('${row.date} ${row.visitors}');
  }
}
```
```server-kotlin
import io.appwrite.Client
import io.appwrite.Query
import io.appwrite.enums.AnalyticsInterval
import io.appwrite.services.Analytics

suspend fun main() {
    val client = Client()
        .setEndpoint("https://<REGION>.cloud.appwrite.io/v1")
        .setProject("<PROJECT_ID>")
        .setKey("<API_KEY>")

    val analytics = Analytics(client)

    val days = analytics.listMetrics(
        propertyId = "<PROPERTY_ID>",
        interval = AnalyticsInterval.ONE_DAY,
        dateRange = "14d",
        queries = listOf(Query.equal("channel", "search")),
    )

    for (row in days.metrics) {
        println("${row.date} ${row.visitors}")
    }
}
```
```server-swift
import Appwrite
import AppwriteEnums

let client = Client()
    .setEndpoint("https://<REGION>.cloud.appwrite.io/v1")
    .setProject("<PROJECT_ID>")
    .setKey("<API_KEY>")

let analytics = Analytics(client)

let days = try await analytics.listMetrics(
    propertyId: "<PROPERTY_ID>",
    queries: [Query.equal("channel", value: "search")],
    interval: .oneDay,
    dateRange: "14d"
)

for row in days.metrics {
    print(row.date ?? "", row.visitors)
}
```
```server-go
package main

import (
    "fmt"
    "log"

    "github.com/appwrite/sdk-for-go/v7/appwrite"
    "github.com/appwrite/sdk-for-go/v7/query"
)

func main() {
    client := appwrite.NewClient(
        appwrite.WithEndpoint("https://<REGION>.cloud.appwrite.io/v1"),
        appwrite.WithProject("<PROJECT_ID>"),
        appwrite.WithKey("<API_KEY>"),
    )

    analytics := appwrite.NewAnalytics(client)

    days, err := analytics.ListMetrics(
        "<PROPERTY_ID>",
        analytics.WithListMetricsInterval("1d"),
        analytics.WithListMetricsDateRange("14d"),
        analytics.WithListMetricsQueries([]string{
            query.Equal("channel", "search"),
        }),
    )
    if err != nil {
        log.Fatal(err)
    }

    for _, row := range days.Metrics {
        fmt.Println(*row.Date, row.Visitors)
    }
}
```
```server-rust
use appwrite::Client;
use appwrite::enums::AnalyticsInterval;
use appwrite::query::Query;
use appwrite::services::Analytics;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::new();
    client.set_endpoint("https://<REGION>.cloud.appwrite.io/v1");
    client.set_project("<PROJECT_ID>");
    client.set_key("<API_KEY>");

    let analytics = Analytics::new(&client);

    let days = analytics.list_metrics(
        "<PROPERTY_ID>",
        Some(vec![Query::equal("channel", "search").to_string()]),
        Some(AnalyticsInterval::OneDay),
        None, // dimensions
        Some("14d"),
        None, // start_at
        None, // end_at
        None, // limit
        None, // total
    ).await?;

    for row in days.metrics {
        println!("{} {}", row.date.unwrap_or_default(), row.visitors);
    }

    Ok(())
}
```
```bash
appwrite client \
    --endpoint https://<REGION>.cloud.appwrite.io/v1 \
    --project-id '<PROJECT_ID>' \
    --key '<API_KEY>'

appwrite analytics list-metrics \
    --property-id '<PROPERTY_ID>' \
    --interval 1d \
    --date-range 14d \
    --filter channel=search
```
```curl
curl -G 'https://<REGION>.cloud.appwrite.io/v1/analytics/properties/<PROPERTY_ID>/metrics' \
    -H 'X-Appwrite-Project: <PROJECT_ID>' \
    -H 'X-Appwrite-Key: <API_KEY>' \
    --data-urlencode 'interval=1d' \
    --data-urlencode 'dateRange=14d' \
    --data-urlencode 'queries[]={"method":"equal","attribute":"channel","values":["search"]}'
```

You can filter on every dimension except `entryPage`, `exitPage`, and `trafficType`. Filters on `page` and `eventName` work with `interval`, or with a breakdown on any dimension other than `entryPage` and `exitPage`. Totals don't accept them, because totals also cover whole visits.
