Skip to main content
GET
/
api
/
websites
/
:id
/
pageviews
Get Pageviews Time Series
curl --request GET \
  --url https://api.example.com/api/websites/:id/pageviews
{
  "data": {
    "series": [
      {
        "date": "<string>",
        "pageviews": 123,
        "visitors": 123
      }
    ],
    "granularity": "<string>",
    "compare_series": [
      {}
    ]
  },
  "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.
granularity
string
Time series granularity: hour, day, week, or month. Automatically determined based on date range if not specified.
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).
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.
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
Time series data for the requested period.
series
array
Array of time series data points.
date
string
Date/time for this data point in ISO 8601 format.
pageviews
integer
Number of pageviews in this time bucket.
visitors
integer
Number of unique visitors in this time bucket.
granularity
string
The granularity used for the time series (hour, day, week, or month).
compare_series
array
Comparison period time series (only present when compare_mode is set). Same structure as series.
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/pageviews?start_date=2024-03-01&end_date=2024-03-07&granularity=day" \
  -H "Authorization: Bearer spk_live_your_api_key"

Example Response

{
  "data": {
    "series": [
      {
        "date": "2024-03-01",
        "pageviews": 1823,
        "visitors": 542
      },
      {
        "date": "2024-03-02",
        "pageviews": 1654,
        "visitors": 489
      },
      {
        "date": "2024-03-03",
        "pageviews": 1891,
        "visitors": 571
      },
      {
        "date": "2024-03-04",
        "pageviews": 2103,
        "visitors": 623
      },
      {
        "date": "2024-03-05",
        "pageviews": 1987,
        "visitors": 602
      },
      {
        "date": "2024-03-06",
        "pageviews": 1742,
        "visitors": 521
      },
      {
        "date": "2024-03-07",
        "pageviews": 1343,
        "visitors": 543
      }
    ],
    "granularity": "day",
    "compare_series": null
  }
}

Example with Comparison

curl -X GET "https://analytics.example.com/api/websites/abc123/pageviews?start_date=2024-03-01&end_date=2024-03-07&granularity=day&compare_mode=previous_period" \
  -H "Authorization: Bearer spk_live_your_api_key"
{
  "data": {
    "series": [
      { "date": "2024-03-01", "pageviews": 1823, "visitors": 542 },
      { "date": "2024-03-02", "pageviews": 1654, "visitors": 489 },
      { "date": "2024-03-03", "pageviews": 1891, "visitors": 571 },
      { "date": "2024-03-04", "pageviews": 2103, "visitors": 623 },
      { "date": "2024-03-05", "pageviews": 1987, "visitors": 602 },
      { "date": "2024-03-06", "pageviews": 1742, "visitors": 521 },
      { "date": "2024-03-07", "pageviews": 1343, "visitors": 543 }
    ],
    "granularity": "day",
    "compare_series": [
      { "date": "2024-02-23", "pageviews": 1542, "visitors": 461 },
      { "date": "2024-02-24", "pageviews": 1389, "visitors": 412 },
      { "date": "2024-02-25", "pageviews": 1621, "visitors": 498 },
      { "date": "2024-02-26", "pageviews": 1812, "visitors": 537 },
      { "date": "2024-02-27", "pageviews": 1723, "visitors": 523 },
      { "date": "2024-02-28", "pageviews": 1501, "visitors": 449 },
      { "date": "2024-02-29", "pageviews": 1646, "visitors": 521 }
    ]
  },
  "compare": {
    "mode": "previous_period",
    "primary_range": ["2024-03-01", "2024-03-07"],
    "comparison_range": ["2024-02-23", "2024-02-29"]
  }
}

Notes

  • Granularity is automatically selected based on date range if not specified
  • Hour granularity is best for 1-2 day ranges
  • Day granularity is best for weekly/monthly ranges
  • Week and month granularities are best for longer ranges
  • Time series data points are aligned to the start of each time bucket

Build docs developers (and LLMs) love