Querying analytics
Measures, dimensions, filters and dates
Every report in the dashboard is one query to the same endpoint: POST/v1/projects/{project}/analytics/query. You name the measures you want, and optionally a time step, up to two breakdowns, filters, a comparison and a goal. This page is the whole query language, with what each part means and its limits.
It runs on the data host (https://us.api.vk.viabio.me) and needs a secret key with analytics.view.
The shape of a query
1{2"measures": ["visitors", "pageviews", "bounce_rate"],3"date_range": { "preset": "30d" },4"granularity": "day",5"breakdown": ["channel"],6"filters": [7{ "dimension": "country", "operator": "is", "values": ["IN", "US"] }8],9"compare": { "preset": "previous_period" },10"goal": { "type": "event", "value": "Signup" },11"limit": 100012}
hour, day, week, month or auto. Leave it out for totals.filters. See Two segments side by side.last_touch or first_touch. See Attribution.Measures
A measure is a number the query computes over the matching events. Every measure comes back as a number.
| Name | Unit | What it is |
|---|---|---|
visitors | count | Unique visitors |
visits | count | Visits (sessions) |
pageviews | count | Page views |
views_per_visit | ratio | Page views divided by visits |
bounce_rate | percent | Share of visits that bounced, 0 to 100 |
visit_duration | seconds | Engaged time per visit |
time_on_page | seconds | Average engaged time on a page |
scroll_depth | percent | Average deepest scroll on a page, 0 to 100 |
events | count | Custom events |
conversions | count | Unique visitors who converted |
conversion_rate | percent | Converted visitors divided by all visitors, 0 to 100 |
converted_visits | count | Visits in which a conversion happened |
visit_conversion_rate | percent | Converted visits divided by all visits, 0 to 100 |
revenue | money | Sum of the revenue sent with custom events (with a goal, only the goal's events), converted to the project's currency |
average_order_value | money | Revenue divided by the number of events that carried revenue (with a goal, only the goal's events) |
exits | count | Visits that ended on the page: it was their last page view |
exit_rate | percent | Exits divided by the page's views, 0 to 100 |
A measure that can't be computed, such as bounce_rate with no visits, comes back as 0.
Revenue sent in another currency is converted at the rate of the event's day; see Revenue. When some revenue in the range is in a currency with no exchange rate, it is left out of revenue and average_order_value, and the answer says so in warnings:
1"warnings": [2{3"code": "missing_exchange_rate",4"message": "Revenue in AED is left out: there is no exchange rate to INR for it.",5"currencies": ["AED"]6}7]
warnings is only in the answer when there is something to say.
Not available yet
new_returning is listed in the schema as a measure but is not available as one yet. As a dimension it works (see below). A query that names it as a measure gets 422 validation_error.
Dimensions
A dimension is something you break down or filter by. Each breakdown dimension comes back in each row under its own name, as text.
Page
| Name | What it is |
|---|---|
page | The page's path, such as /pricing |
hostname | The site's hostname |
entry_page | The first page of the visit |
exit_page | The last page of the visit |
page_group | The name of the first page group saved in the project whose pattern the page's path matches, such as Blog for /blog/*. Pages in no group have an empty value |
page_title | The page's title |
search_term | What the visitor searched for on your site |
broken_page | Pages that answered 404 |
Source
| Name | What it is |
|---|---|
source | Where the visit came from, such as Google or Direct |
channel | The kind of source, such as Organic search, Referral or Direct |
referrer_domain | The referring site's domain |
referrer_url | The full referring URL |
utm_source, utm_medium, utm_campaign, utm_term, utm_content | The UTM parameters of the landing URL |
ref | The ref parameter of the landing URL |
paid_click | The ad platform named by a click id in the landing URL: Google Ads (gclid), Meta (fbclid), Microsoft Ads (msclkid) or LinkedIn (li_fat_id) |
Location
| Name | What it is |
|---|---|
continent | Continent |
country | Country, as a two-letter code such as IN |
region | Region or state |
city | City |
Technology
| Name | What it is |
|---|---|
device_type | Desktop, mobile or tablet |
device_brand | Device brand and model |
browser, browser_version | Browser and its version |
os, os_version | Operating system and its version |
screen_size | Screen size |
language | The browser's language |
Visitor
| Name | What it is |
|---|---|
new_returning | New or Returning. A visit is Returning when the same visitor had an earlier visit in the range that day, or when the visitor identified as a user first seen on an earlier day. Without cookies a visitor id lasts one day, so an anonymous visitor who comes back tomorrow counts as New |
user_id | The id you passed to identify |
traits.<key> | One trait you passed to identify, such as traits.company |
Events
| Name | What it is |
|---|---|
event_name | A custom event's name |
props.<key> | One property of a custom event, such as props.plan |
goal | The name of a goal saved in the project that the event reached, such as Signed up. An event that reaches two goals counts in both rows of a breakdown; events that reach none are in the row with an empty value |
outbound_link | The URL of an outbound link that was clicked |
file_download | The URL of a file that was downloaded |
props and traits are keyed: write the key after a dot. A key is 1 to 40 letters, digits, _, . or -. The column in each row is named the same, such as props.plan.
Not available yet
form is in the schema with available: false. It waits for form tracking, and a query that uses it gets 422 validation_error.
To build a picker, GET/v1/projects/{project}/analytics/schema lists every dimension and measure with its group, unit and whether it is available. GET/v1/projects/{project}/analytics/dimensions/{dimension}/values returns the 50 most common values of a dimension in the last 30 days, with an optional ?search=.
Filters
A filter keeps the events whose dimension matches any of its values. Filters in the list are ANDed.
1[2{ "dimension": "page", "operator": "starts_with", "values": ["/blog/"] },3{ "dimension": "props.plan", "operator": "is", "values": ["pro", "business"] },4{ "or": [5{ "dimension": "utm_source", "operator": "is", "values": ["newsletter"] },6{ "dimension": "referrer_domain", "operator": "contains", "values": ["substack"] }7] }8]
| Operator | Matches when the value |
|---|---|
is | Equals any of the values |
is_not | Equals none of the values |
contains | Contains any of the values, ignoring case |
not_contains | Contains none of the values, ignoring case |
starts_with | Starts with any of the values |
regex | Matches any of the regular expressions |
- Each filter takes 1 to 20 values, each up to 255 characters.
- To OR whole filters, put them in an
orlist, as in the last filter above. Anorfilter has nodimensionof its own, andorlists can't be nested. - Up to 20 filters in all, counting each filter inside an
or. - A regular expression that doesn't compile is
422 validation_error.
Dates
date_range takes a preset, or from and to. Days start at midnight in the project's timezone, which you set when you create the project or change with PATCH /v1/projects/{project}.
| Preset | Range |
|---|---|
today | Today so far |
yesterday | Yesterday |
7d | Today and the 6 days before it |
30d | Today and the 29 days before it. Also what an empty date_range means |
90d | Today and the 89 days before it |
this_month | From the 1st of this month |
last_month | The whole of last month |
this_year | From 1 January |
all | Everything |
For a custom range, give both from and to, as dates or as times:
- Dates,
{ "from": "2026-11-01", "to": "2026-11-15" }: whole days in the project's time zone,toincluded. - RFC 3339 times,
{ "from": "2026-11-01T00:00:00Z", "to": "2026-11-02T00:00:00Z" }: exact instants,toexcluded.
from must come before to. The answer's date_range gives the exact range used, in UTC.
Older than your plan keeps
Your plan keeps the last N days of data, today included, in the project's time zone: retention_days from GET /v1/projects/{project}/retention (Free 30, Pro 365, Business 1095, more with a retention add-on, null with no limit). A date_range or compare that starts before the oldest day kept is not refused: it starts on that day instead, date_range (or compare_range) shows where it really starts, and warnings says so:
1"warnings": [2{3"code": "range_clamped",4"message": "The plan keeps 30 days of data, so the range starts on the first day it keeps.",5"retention_days": 306}7]
A range that ends before the oldest day kept comes back empty. The other report endpoints (funnels, journeys, retention cohorts, pages, visitors, heatmaps) start their range on the same day; their date_range shows it, without a warning. Public pages and share tokens are clamped the same way.
Granularity
With granularity, each row is one step of time, with a time column holding the step's start as an ISO time in UTC. Days, weeks (from Monday) and months start in the project's time zone. Steps with no data are left out, so fill gaps in your chart.
auto picks the step from the range's length: hour up to 2 days, day up to 90 days, week up to a year, month beyond. The answer's granularity says which step was used.
Breakdowns
breakdown groups the rows by up to 2 dimensions. With a time step too, you get one row per step per value. Rows are sorted by time, then by the first measure from highest, then by the breakdown values. Without a time step you get the top 100 rows unless you set limit.
Compare
compare runs the same query over a second range and returns those rows in compare, with the range used in compare_range:
{ "preset": "previous_period" }: the same length, just beforedate_range.{ "preset": "previous_year" }: the same dates a year earlier.{ "from": "…", "to": "…" }: any range, read the same way asdate_range.
The comparison uses the same time step, breakdowns, filters and goal.
Two segments side by side
compare_filters puts a second segment beside the first: the compare rows are the same query with these filters instead of filters, over the same date_range (compare_range is then the same range). Give compare too to run the second segment over that range instead. An empty list means every visitor. It takes the same filters, with the same limits.
1{2"measures": ["visitors", "conversion_rate"],3"date_range": { "preset": "30d" },4"filters": [{ "dimension": "device_type", "operator": "is", "values": ["desktop"] }],5"compare_filters": [{ "dimension": "device_type", "operator": "is", "values": ["mobile"] }]6}
Journeys and funnels
POST/v1/projects/{project}/analytics/journeys and POST/v1/projects/{project}/funnels/{funnel}/results take compare and compare_filters too, read the same way. Journeys then also answers compare_before, compare_after and compare_range; a saved funnel answers compare, its steps over the comparison (without the split or median times), and compare_range.
The visitors behind a number
POST/v1/projects/{project}/analytics/visitors lists the visitors behind any number: send the report's date_range and its filters, plus a filter for each value of the row (source is Google). It answers the visitors with an event that passes the filters, latest first, up to limit (100 at most, the default), and total, how many there are in all:
1{2"data": [3{4"visitor": "11013", "user_id": "user_23",5"first_seen": "2026-11-22T10:32:41Z", "last_seen": "2026-11-22T12:03:47Z",6"visits": 2, "pageviews": 5, "events": 2,7"entry_page": "/pricing", "source": "Google",8"country": "BR", "city": "São Paulo", "device_type": "mobile", "browser": "Safari", "os": "iOS"9}10],11"total": 214,12"date_range": { "from": "…", "to": "…" }13}
Each row sums up the visitor's events that passed the filters: entry_page and source are those of their first such visit. user_id is the user the visitor identified as with identify, or empty. A visitor id lasts one day, so someone who came on two days is two rows.
Goals and conversions
conversions and conversion_rate count visitors who completed a goal. Name the goal in the query:
{ "type": "event", "value": "Signup" }: a custom event with this name.{ "type": "page", "value": "/thanks" }: a view of this page. Use*for any part of the path:/docs/*.
An event goal can also take conditions, up to 20 tests on the event's properties that must all pass. Each has a property, an operator (is, is_not, contains, starts_with) and a value: { "type": "event", "value": "Signup", "conditions": [{ "property": "plan", "operator": "is", "value": "pro" }] }.
Without goal, any custom event counts as a conversion. The value is up to 255 characters.
With a goal, revenue and average_order_value count only the goal's events, so a Purchase goal gives the revenue of purchases. A page goal has no revenue.
converted_visits and visit_conversion_rate count visits instead of visitors: a visitor who converts in two visits counts once in conversions and twice in converted_visits.
Attribution
A visit takes its source, channel, referrer and UTM fields from its first page view. attribution picks which visit a visitor's events, conversions included, count for:
last_touch(the default): the visit each event happened in.first_touch: the visitor's first visit in the range.
Without cookies a visitor id lasts one day, so first touch looks back only within that day. first_touch changes every source dimension of the query (source, channel, referrer_domain, utm_*, ref, paid_click), in breakdowns and filters alike:
1{2"measures": ["conversions"],3"goal": { "type": "event", "value": "Purchase" },4"breakdown": ["channel"],5"attribution": "first_touch",6"date_range": { "preset": "30d" }7}
Linear, position-based, and across days
For a goal, the attribution endpoint shares each conversion among all the visits that led to it, under four models at once, and can follow identified users across days and devices:
POST/v1/projects/{project}/analytics/attribution1curl https://us.api.vk.viabio.me/v1/projects/prj_…/analytics/attribution \2-H "Authorization: Bearer sk_live_us_…" \3-H "Content-Type: application/json" \4-d '{5"goal": { "type": "event", "value": "Signup" },6"dimension": "channel",7"count_by": "users",8"date_range": { "preset": "30d" }9}'
Each person who reached the goal in the range is one conversion, at their first goal event. Its credit goes to the visits up to and including the one it happened in:
first_touch: all of it to the first visit.last_touch: all of it to the last.linear: the same share to each.position_based: 40% to the first, 40% to the last, and 20% shared by the visits between (half each when there are two).
dimension is channel (the default), source, referrer_domain, ref or a utm_* field. With count_by: visitors (the default) only the visitor's visits of that day count. With count_by: users, people are identified users, and their visits on every device in the 30 days before the conversion count. filters apply to the conversion.
The answer has conversions (people who converted), window ("1 day" or "30 days") and data: up to 100 rows, by linear credit, each a value with its credit under every model (first_touch, last_touch, linear, position_based). Credit can be a fraction, and each model's column adds up to conversions.
A full example
Daily visitors and conversions from India over the last 7 days, compared with the 7 days before, for visitors who signed up:
1curl https://us.api.vk.viabio.me/v1/projects/prj_…/analytics/query \2-H "Authorization: Bearer sk_live_us_…" \3-H "Content-Type: application/json" \4-d '{5"measures": ["visitors", "conversions"],6"date_range": { "preset": "7d" },7"granularity": "day",8"filters": [{ "dimension": "country", "operator": "is", "values": ["IN"] }],9"compare": { "preset": "previous_period" },10"goal": { "type": "event", "value": "Signup" }11}'
1const res = await fetch("https://us.api.vk.viabio.me/v1/projects/prj_…/analytics/query", {2method: "POST",3headers: {4Authorization: `Bearer ${process.env.VIAKITE_SECRET_KEY}`,5"Content-Type": "application/json",6},7body: JSON.stringify({8measures: ["visitors", "conversions"],9date_range: { preset: "7d" },10granularity: "day",11filters: [{ dimension: "country", operator: "is", values: ["IN"] }],12compare: { preset: "previous_period" },13goal: { type: "event", value: "Signup" },14}),15});16const report = await res.json();17for (const row of report.data) console.log(row.time, row.visitors, row.conversions);
1import os2import requests34res = requests.post(5"https://us.api.vk.viabio.me/v1/projects/prj_…/analytics/query",6headers={"Authorization": f"Bearer {os.environ['VIAKITE_SECRET_KEY']}"},7json={8"measures": ["visitors", "conversions"],9"date_range": {"preset": "7d"},10"granularity": "day",11"filters": [{"dimension": "country", "operator": "is", "values": ["IN"]}],12"compare": {"preset": "previous_period"},13"goal": {"type": "event", "value": "Signup"},14},15)16res.raise_for_status()17for row in res.json()["data"]:18print(row["time"], row["visitors"], row["conversions"])
The answer, for a project in Asia/Kolkata (shortened to 2 days):
1{2"data": [3{ "time": "2026-11-14T18:30:00Z", "visitors": 412, "conversions": 23 },4{ "time": "2026-11-15T18:30:00Z", "visitors": 388, "conversions": 19 }5],6"compare": [7{ "time": "2026-11-07T18:30:00Z", "visitors": 365, "conversions": 17 },8{ "time": "2026-11-08T18:30:00Z", "visitors": 401, "conversions": 21 }9],10"date_range": { "from": "2026-11-14T18:30:00Z", "to": "2026-11-21T18:30:00Z" },11"compare_range": { "from": "2026-11-07T18:30:00Z", "to": "2026-11-14T18:30:00Z" },12"granularity": "day"13}
A breakdown adds one column per dimension. The top 5 campaigns by visitors this month:
1{2"measures": ["visitors", "conversion_rate"],3"date_range": { "preset": "this_month" },4"breakdown": ["utm_campaign"],5"filters": [{ "dimension": "utm_campaign", "operator": "is_not", "values": [""] }],6"limit": 57}
1{2"data": [3{ "utm_campaign": "black-friday", "visitors": 2210, "conversion_rate": 4.6 },4{ "utm_campaign": "newsletter-nov", "visitors": 940, "conversion_rate": 7.1 }5],6"date_range": { "from": "2026-10-31T18:30:00Z", "to": "2026-11-21T18:30:00Z" }7}
A dimension with no value, such as a visit without a campaign, comes back as an empty string. Filter it out with is_not and [""], as above.
Batch queries
A page with many tiles can send up to 10 queries in one request with POST/v1/projects/{project}/analytics/query/batch. The answers come back in data, in the order of the queries:
1{2"queries": [3{ "measures": ["visitors", "visits", "pageviews", "bounce_rate"], "date_range": { "preset": "30d" } },4{ "measures": ["visitors"], "date_range": { "preset": "30d" }, "breakdown": ["source"], "limit": 10 },5{ "measures": ["visitors"], "date_range": { "preset": "30d" }, "breakdown": ["page"], "limit": 10 }6]7}
1{2"data": [3{ "data": [{ "visitors": 8120, "visits": 10433, "pageviews": 27310, "bounce_rate": 41.2 }], "date_range": { "from": "…", "to": "…" } },4{ "data": [{ "source": "Google", "visitors": 3904 }], "date_range": { "from": "…", "to": "…" } },5{ "data": [{ "page": "/", "visitors": 5012 }], "date_range": { "from": "…", "to": "…" } }6]7}
More than 10 queries, or none, is 422 too_many_queries. If one query is wrong, the whole batch fails with that query's error.
Limits
| Limit | Value |
|---|---|
| Measures | At least 1 |
| Breakdown dimensions | Up to 2 |
| Filters | Up to 20, counting those inside or |
| Values per filter | 1 to 20, each up to 255 characters |
| Rows | 100 by default, 10,000 with a time step, at most 10,000 |
| Queries in a batch | 1 to 10 |
Not built yet
There is no cursor to read past 10,000 rows of one report. Split the range or add filters for more.