The OneDollarStats Stats API is a powerful, single-endpoint HTTP interface for querying real-time and historical analytics data.
Use the /api endpoint to send flexible POST requests—from simple summaries to complex multi-dimensional queries—and receive JSON responses with calculated metrics.


Authentication

To create an API key:

  1. Log in to your OneDollarStats dashboard.
  2. In the top-right corner, open your account settings.
  3. Go to the API Keys section and click Create API Key.
  4. Name your API Key, then save the key securely—it will be shown only once.
  5. Confirm by clicking Continue.

Authenticate your requests by including the key in the x-api-key header.

Example curl request

Replace YOUR-KEY with your API key and site_id with your site’s domain as registered in your OneDollarStats account:

curl \
--request POST \
--header 'x-api-key: YOUR-KEY' \
--header 'Content-Type: application/json' \
--url 'https://onedollarstats.com/api' \
--data '{ "site_id": "onedollarstats.com", "metrics": ["visitors"], "date_range": "7d" }'

Request Structure

All queries are made via the /api endpoint, which accepts a JSON object with the following fields:

{
  "site_id": "onedollarstats.com",
  "metrics": ["visitors", "pageviews", "bounce_rate"],
  "date_range": "7d",
  "filters": [["is_not", "visit:country_name", [""]]],
  "dimensions": ["visit:country_name", "visit:city_name"]
}

site_id Required

Your site’s domain, exactly as configured in OneDollarStats.


date_range Required

Specifies the date or time range for the query.

OptionDescription
["2024-01-01", "2024-07-01"]Custom date range (ISO8601)
["2024-01-01T12:00:00+02:00", "2024-01-01T15:59:59+02:00"]Custom date-time range (ISO8601)
"day"Current day
"7d"Last 7 days
"30d"Last 30 days
"6mo"Last 6 months
"12mo"Last 12 months
"year"Since the start of this year
"all"All available data in OneDollarStats

metrics Required

Metrics are the numeric values returned by the query.

MetricTypeDescriptionRequirements
visitorsintUnique visitors
visitsintTotal visits or sessions
pageviewsintTotal pageviews
views_per_visitfloatPageviews ÷ visits
bounce_ratefloatPercentage of single-page visits
visit_durationintAverage visit duration (seconds)
eventsintTotal events (pageviews + custom events)
scroll_depthintAverage scroll depth per sessionRequires event:page
conversion_ratefloat% of visitors completing a goalRequires event:goal
group_conversion_ratefloatConversion rate per dimension groupRequires event:goal
average_revenueRevenue or nullAvg. revenue per conversionRequires revenue goals
total_revenueRevenue or nullTotal revenue from conversionsRequires revenue goals
time_on_pageintAverage time on page (seconds)Requires event:page

dimensions Optional

Default: []

A list of attributes to group data by. Dimensions are like SQL GROUP BY fields.

Event dimensions

DimensionExampleDescription
event:goalRegisterCustom goal name
event:page/blog/remove-google-analyticsPage path (wildcards supported, e.g. /blog*)
event:hostnameexample.comEvent hostname
IMPORTANT

You cannot mix session metrics (bounce_rate, views_per_visit, visit_duration) with event dimensions.

Visit dimensions

DimensionExampleDescription
visit:entry_page/homeEntry (landing) page
visit:exit_page/aboutExit page
visit:sourceTwitterTraffic source
visit:channelOrganic SearchAcquisition channel
visit:utm_mediumsocialutm_medium parameter
visit:deviceDesktopDevice type
visit:browserChromeBrowser name
visit:country_nameUnited StatesCountry name
visit:city_nameSan FranciscoCity name

Time dimensions

Group results by time:

DimensionExampleDescription
time2024-01-01Auto time bucket based on range
time:hour2024-01-01T14:00:00ZHourly grouping
time:day2024-01-01Daily grouping
time:week2024-01-01Weekly grouping
time:month2024-01-01Monthly grouping

Notes:


filters Optional

Default: []

Filters restrict which events or sessions are included in the query.

Each filter is an array: [operator, dimension, clauses]
Optionally, a fourth argument {modifiers} can be included.

Supported operators

OperatorExampleDescription
is["is", "visit:country_name", ["Germany"]]Match values exactly
is_not["is_not", "event:page", ["/pricing"]]Exclude values
contains["contains", "event:page", ["/login"]]Match substrings
matches["matches", "event:page", ["^/user/\\d+$"]]Regex match (RE2 syntax)

Combine filters using logical operators:

OperatorExampleDescription
and["and", [["is", "visit:country_name", ["Germany"]], ["is", "visit:city_name", ["Berlin"]]]]Both must match
or["or", [["is", "visit:country_name", ["Germany"]], ["is", "visit:city_name", ["Tallinn"]]]]Either matches
not["not", ["is", "visit:country_name", ["Germany"]]]Negation

Top-level filters are implicitly wrapped in and.

Behavioral filters

Use has_done or has_not_done to filter sessions based on whether specific events occurred within them.
See example


order_by Optional

Defines the sort order of results.

Example:

[
  ["visitors", "desc"],
  ["visit:country_name", "asc"]
]

Default order:

  1. By time dimension (ascending), if present
  2. By the first metric (descending)

include Optional

Adds optional metadata or computed data to the response.

OptionDefaultDescription
include.importsfalseInclude imported analytics data (e.g. from Google Analytics)
include.time_labelsfalseAdd all valid time labels for date_range
include.total_rowsfalseInclude total row count (useful for pagination)

pagination Optional

Default: { "limit": 10000, "offset": 0 }

Use with include.total_rows for paginated results.


Response Structure

Example:

{
  "results": [
    { "metrics": [99, 98, 94], "dimensions": ["Estonia", "Tallinn"] },
    { "metrics": [98, 82, 97], "dimensions": ["Brazil", "São Paulo"] },
    { "metrics": [97, 77, 98], "dimensions": ["Germany", "Berlin"] },
    { "metrics": [94, 86, 93], "dimensions": ["Italy", "Rome"] },
    {
      "metrics": [89, 77, 96],
      "dimensions": ["United States", "San Francisco"]
    },
    { "metrics": [82, 78, 92], "dimensions": ["Poland", "Warsaw"] }
  ],
  "meta": {},
  "query": {
    "site_id": "dummy.site",
    "metrics": ["visitors", "pageviews", "bounce_rate"],
    "date_range": ["2024-09-04T00:00:00+00:00", "2024-09-10T23:59:59+00:00"],
    "filters": [["is_not", "visit:country_name", [""]]],
    "dimensions": ["visit:country_name", "visit:city_name"],
    "order_by": [["visitors", "desc"]],
    "include": {}
  }
}

results

Array of result rows.
Each row contains:

meta

Metadata and warnings about the query.
Includes optional fields like time_labels, imports_included, and total_rows.

{
  // Whether imported data was included
  // Only set if include.imports was set
  "imports_included": false,

// Information about why including imported data failed
"imports_skip_reason": "unsupported_interval",
"imports_warning": "Imported stats are not included because the time dimension (i.e. the interval) is too short.",

// Warnings about specific metrics
// Currently only set if a revenue metric was used and was unable to be calculated
"metric_warnings": {
"total_revenue": {
"code": "no_revenue_goals_matching",
"warning": "Revenue metrics are null as there are no matching revenue goals."
}
},

// Only set if include.time_labels was set
"time_labels": [
"2024-09-10 00:00:00",
"2024-09-10 01:00:00",
"2024-09-10 02:00:00",
"2024-09-10 03:00:00",
"2024-09-10 04:00:00",
"2024-09-10 05:00:00",
"2024-09-10 06:00:00"
],

// Only set if include.total_rows was set
"total_rows": 342
}

Examples

All examples below are live and editable when logged in.

Simple aggregate

Query
Example Response
{
  "site_id": "dummy.site",
  "metrics": ["visitors", "events"],
  "date_range": "7d"
}

Custom date range

Query
Example Response
{
  "site_id": "dummy.site",
  "metrics": ["visitors"],
  "date_range": ["2024-08-01", "2024-08-15"]
}

Country and city breakdown

Query
Example Response
{
"site_id": "dummy.site",
"metrics": ["visitors", "pageviews", "bounce_rate"],
"date_range": "7d",
"filters": [
["is_not", "visit:country_name", [""]]
],
"dimensions": ["visit:country_name", "visit:city_name"]
}

Filtering examples

Query
Example Response
{
  "site_id": "dummy.site",
  "metrics": ["visitors"],
  "date_range": "7d",
  "filters": [
    ["contains", "event:page", ["/docs", "/pricing"]],
    ["or", [
      ["not", ["is", "visit:utm_campaign", ["Referral"]]],
      ["is", "visit:country_name", ["Estonia", "United States of America"]]
    ]]
  ]
}
Query
Example Response
{
  "site_id": "dummy.site",
  "metrics": ["visitors"],
  "date_range": "7d",
  "filters": [
    ["contains", "event:page", ["blog"], {"case_sensitive": false}]
  ]
}
Query
Example Response
{
  "site_id": "dummy.site",
  "metrics": ["visitors", "events"],
  "filters": [["is", "segment", [2]]],
  "date_range": "7d"
}

Timeseries examples

Query
Example Response
{
  "site_id": "dummy.site",
  "metrics": ["visitors", "events"],
  "date_range": "7d",
  "filters": [
    ["is", "visit:os", ["GNU/Linux", "Mac"]]
  ],
  "dimensions": ["time:day"]
}
Query
Example Response
{
  "site_id": "dummy.site",
  "metrics": ["visitors"],
  "date_range": "day",
  "dimensions": ["time:hour"],
  "include": {
    "time_labels": true
  }
}

Custom properties

Query
Example Response
{
  "site_id": "dummy.site",
  "metrics": ["visitors"],
  "date_range": "7d",
  "dimensions": ["time:day", "event:props:is_customer"],
  "order_by": [["time:day", "asc"], ["event:props:is_customer", "desc"]]
}

Pagination and imports

Query
Example Response
{
  "site_id": "dummy.site",
  "metrics": ["visitors", "events", "pageviews"],
  "date_range": "7d",
  "dimensions": ["visit:utm_medium", "visit:utm_source"],
  "include": { "total_rows": true },
  "pagination": { "limit": 3, "offset": 1 }
}
Query
Example Response
{
  "site_id": "dummy.site",
  "metrics": ["visitors"],
  "date_range": "all",
  "dimensions": ["visit:source"],
  "include": {
    "imports": true
  }
}