Skip to main content
GET
/
api
/
websites
/
:id
/
stats
Get Website Stats
curl --request GET \
  --url https://api.example.com/api/websites/:id/stats
{
  "data": {
    "pageviews": 123,
    "visitors": 123,
    "sessions": 123,
    "bounce_rate": 123,
    "avg_duration_seconds": 123,
    "prev_pageviews": 123,
    "prev_visitors": 123,
    "prev_sessions": 123,
    "prev_bounce_rate": 123,
    "prev_avg_duration_seconds": 123,
    "timezone": "<string>"
  },
  "compare": {
    "mode": "<string>",
    "primary_range": [
      {}
    ],
    "comparison_range": [
      {}
    ]
  }
}

Path Parameters

id
string
required
Website ID

Query Parameters

start_date
string
Start date in YYYY-MM-DD format. Defaults to 6 days ago if not provided.
end_date
string
End date in YYYY-MM-DD format. Defaults to today if not provided.
timezone
string
IANA timezone string (e.g., America/New_York). Defaults to UTC.
include_bots
boolean
Whether to include bot traffic in results. Defaults to website’s bot policy setting.

Comparison Parameters

compare_mode
string
Comparison mode: none, previous_period, previous_year, or custom.
compare_start_date
string
Custom comparison start date (required when compare_mode=custom).
compare_end_date
string
Custom comparison end date (required when compare_mode=custom).

Filter Parameters

filter_country
string
ISO 3166-1 alpha-2 country code (e.g., US, GB). Must be exactly 2 uppercase characters.
filter_page
string
Filter by page URL path.
filter_referrer
string
Filter by referrer domain.
filter_browser
string
Filter by browser name.
filter_os
string
Filter by operating system.
filter_device
string
Filter by device type (e.g., desktop, mobile, tablet).
filter_language
string
Filter by browser language.
filter_utm_source
string
Filter by UTM source parameter.
filter_utm_medium
string
Filter by UTM medium parameter.
filter_utm_campaign
string
Filter by UTM campaign parameter.
filter_region
string
Filter by geographic region/state.
filter_city
string
Filter by city name.
filter_hostname
string
Filter by hostname.

Response

data
object
Summary statistics for the requested period.
pageviews
integer
Total number of pageviews in the current period.
visitors
integer
Total unique visitors in the current period.
sessions
integer
Total number of sessions in the current period.
bounce_rate
number
Percentage of single-page sessions (0-100).
avg_duration_seconds
number
Average session duration in seconds.
prev_pageviews
integer
Previous period pageviews (for trend calculation).
prev_visitors
integer
Previous period unique visitors.
prev_sessions
integer
Previous period sessions.
prev_bounce_rate
number
Previous period bounce rate.
prev_avg_duration_seconds
number
Previous period average session duration.
timezone
string
Timezone used for date calculations.
compare
object
Comparison metadata (only present when compare_mode is set).
mode
string
The comparison mode used.
primary_range
array
Two-element array with start and end dates of the primary period.
comparison_range
array
Two-element array with start and end dates of the comparison period.

Example Request

curl -X GET "https://analytics.example.com/api/websites/abc123/stats?start_date=2024-03-01&end_date=2024-03-07&compare_mode=previous_period" \
  -H "Authorization: Bearer spk_live_your_api_key"

Example Response

{
  "data": {
    "pageviews": 12543,
    "visitors": 3891,
    "sessions": 4872,
    "bounce_rate": 42.3,
    "avg_duration_seconds": 127.5,
    "prev_pageviews": 10234,
    "prev_visitors": 3201,
    "prev_sessions": 4012,
    "prev_bounce_rate": 45.1,
    "prev_avg_duration_seconds": 112.8,
    "timezone": "UTC"
  },
  "compare": {
    "mode": "previous_period",
    "primary_range": ["2024-03-01", "2024-03-07"],
    "comparison_range": ["2024-02-23", "2024-02-29"]
  }
}

Notes

  • The prev_* fields represent the previous period for trend calculations (typically the period immediately before the requested date range)
  • When compare_mode is set, the comparison period is returned in the compare object
  • Bounce rate is calculated as the percentage of sessions with only one pageview
  • Session duration is 0 for single-event sessions

Build docs developers (and LLMs) love