Query analytics metrics with optional grouping, sorting and filters.
Method
POST
Path
/v1/analytics/query
The Query Endpoint is very flexible and can be used to retrieve aggregated analytics data based on custom filters, groupings, and time ranges. It basically lets you retrieve all the data you can see in the Vemetric Dashboard, programmatically.
Examples
Below you can see several examples of how to use the Query Endpoint to retrieve different types of aggregated analytics data. Further down this page, you can find a detailed reference of all the available options you can pass.
Copy the JSON body of any of these examples, and use it in a POST request to https://api.vemetric.com/v1/analytics/query with your API key to see the results.
Be sure to also check out the filter values endpoint to see which values you can use in the filters field.
To group by the properties of a custom event (event:prop:<name>), you can look up their names with the event properties endpoint.
How filters work
Filters select users: the results include all data of the users who match your filters in the given period. For example, a page filter for /blog doesn’t only count the blog pages, but also the other pages and sessions of the users who visited your blog. Only the pageviews and events metrics apply page and event filters to the counted pageviews and events themselves.
The operators, empty values, time series intervals, the default order and the values of each field are described in the reference below. What each referrer type (referrerType) means is explained in Referrers and referrer types.
Headers
Authorization
required
Project or organization API key (starts with vem_), created in the project or organization settings on the API tab. Organization keys name the project of each request in the X-Vemetric-Project header.
Example: Bearer vem_xxxxxxxxxxxx
X-Vemetric-Project
optional
ID of the project the request is about. Required for organization keys; optional for project keys (must be the key's project if sent).
Example: 1234567890123456
Request Body (required)
application/json object
dateRange
* required
Description
Can be either one of the preset strings below, or an array with two date strings [start, end]. Date strings can be either in YYYY-MM-DD format or UTC ISO-8601 format with second precision.
Allowed values: "interval:auto", "interval:hour", "interval:day", "interval:week", "interval:month", "country", "city", "page:origin", "page:path", "browser", "deviceType", "os", "referrer", "referrerType", "utm", "event:name", "event:prop:<property_name>", or the first visit: "firstVisit:referrer", "firstVisit:referrerType", "firstVisit:utm", "firstVisit:page:origin", "firstVisit:page:path". At the moment it's only possible to group by one field, please tell us if you need more.
The interval values return a time series with one row per hour, day, week (starting on Monday) or month, for every interval of the period, also the ones without data (users, pageviews and events are 0 there, bounceRate and visitDuration are null). If the period runs until now, its last interval is still in progress, so lower values there aren't a drop. "interval:auto" picks the interval from the length of the period: hourly up to 2 days, daily up to 31 days, weekly up to 90 days and monthly beyond (for presets: live every 30 seconds, 1hr every 10 minutes, 24hrs hourly, 7days and 30days daily, 3months weekly, 6months and 1year monthly).
Rows without a value for the field (e.g. visits without a UTM campaign, or for referrer visits without a referrer and visits from the project's own domain) are grouped under an empty string "", which you can also use as a filter value.
The firstVisit: values group by where each user came from on their first visit ever (first-touch attribution), which can be before the selected period, while referrer, utm and page:* group each visit by its own source (last touch). Combined with the users metric and an event filter, e.g. for a signup event, they show which first-touch sources bring conversions. Vemetric stores the first visit when a user is identified, so anonymous users are grouped under "".
Gives you the ability to order by a specific field and direction. At the moment it's only possible to order by one field. Without it, rows are ordered by date ascending when grouping by an interval, and by the first metric descending for other groupings (skipping metrics that don't apply to the grouping, like bounceRate per page). Rows with equal values are ordered by their group value.
Limits the number of returned rows. Max value is 1000.
Type
integer
Default
100
offset
Description
Number of rows to skip from the start of the result set, to implement pagination.
Type
integer
Default
0
filters
Description
Ability to filter the results based on multiple criteria. Filters select users: the results include all data of the users who match the filters in the period. For example, a page filter for /blog also counts the other pages and sessions of the users who visited the blog. Only the pageviews and events metrics apply page and event filters to the counted pageviews and events themselves. Use an empty string to match a missing value, e.g. {"type":"referrer","operator":"eq","value":""} for visits without a referrer and visits from the project's own domain.
Type
array<object>
Show nested properties (12)
type: page
Description
Filter based on specific page view properties, like the full URL (origin + path + hash) or its individual parts.
Filter based on the page origin (protocol + host). For example, "https://example.com".
Type
object
Show nested properties (2)
value
* required
Description
Value to filter by
Type
string
operator
* required
Description
Operator to apply for the string filter. "eq" means equals, "notEq" means not equals. "any" means no restriction and also matches users without a value; to require a value, use "notEq" with an empty string.
Filter based on the page path. For example, "/blog".
Type
object
Show nested properties (2)
value
* required
Description
Value to filter by
Type
string
operator
* required
Description
Operator to apply for the string filter. "eq" means equals, "notEq" means not equals. "any" means no restriction and also matches users without a value; to require a value, use "notEq" with an empty string.
Filter based on the page hash. For example, "#section1".
Type
object
Show nested properties (2)
value
* required
Description
Value to filter by
Type
string
operator
* required
Description
Operator to apply for the string filter. "eq" means equals, "notEq" means not equals. "any" means no restriction and also matches users without a value; to require a value, use "notEq" with an empty string.
Operator to apply for the string filter. "eq" means equals, "notEq" means not equals. "any" means no restriction and also matches users without a value; to require a value, use "notEq" with an empty string.
Ability to filter for either anonymous or identified users. This is useful when you want to include only known users (for example, for a retention analysis) or only anonymous users (for example, to analyze new visitor behavior).
Type
object
Default
"user"
Example
{"type":"user","anonymous":true}
Show nested properties (1)
anonymous
* required
Description
Filter for anonymous (true) or identified (false) users.
Filter by one or more country codes (ISO-3166 alpha-2, e.g. "US").
Type
object
Show nested properties (2)
value
* required
Description
List of values to filter by
Type
array<string>
operator
* required
Description
Operator to apply for the list filter. The "any" operator means that any value is accepted and effectively disables the filter. To require a value, use "noneOf" with [""].
Operator to apply for the list filter. The "any" operator means that any value is accepted and effectively disables the filter. To require a value, use "noneOf" with [""].
Referrer value to match, as returned when grouping by referrer (e.g. "Google"). An empty string matches visits without a referrer and visits from the project's own domain (referrer type internal). For visits without a referrer only, filter by the referrer type none.
List of referrer types to match: none (no referrer: typed in, bookmarks, apps), search, social, llm, email, paid, internal (came from a page on the project's own domain, e.g. a link from your app to your website; direct is accepted as an old name) or unknown (a website or source that isn't in Vemetric's list of known sources; visits without a referrer are none).
Type
array<string>
Example
["search","social"]
operator
* required
Description
List matching operator for value. To require a value, use "noneOf" with [""].
Operator to apply for the string filter. "eq" means equals, "notEq" means not equals. "any" means no restriction and also matches users without a value; to require a value, use "notEq" with an empty string.
Operator to apply for the string filter. "eq" means equals, "notEq" means not equals. "any" means no restriction and also matches users without a value; to require a value, use "notEq" with an empty string.
Operator to apply for the string filter. "eq" means equals, "notEq" means not equals. "any" means no restriction and also matches users without a value; to require a value, use "notEq" with an empty string.
Operator to apply for the string filter. "eq" means equals, "notEq" means not equals. "any" means no restriction and also matches users without a value; to require a value, use "notEq" with an empty string.
Operator to apply for the string filter. "eq" means equals, "notEq" means not equals. "any" means no restriction and also matches users without a value; to require a value, use "notEq" with an empty string.
Filter based on the page origin (protocol + host). For example, "https://example.com".
Type
object
Show nested properties (2)
value
Description
Value to filter by
Type
string
operator
Description
Operator to apply for the string filter. "eq" means equals, "notEq" means not equals. "any" means no restriction and also matches users without a value; to require a value, use "notEq" with an empty string.
Filter based on the page path. For example, "/blog".
Type
object
Show nested properties (2)
value
Description
Value to filter by
Type
string
operator
Description
Operator to apply for the string filter. "eq" means equals, "notEq" means not equals. "any" means no restriction and also matches users without a value; to require a value, use "notEq" with an empty string.
Filter based on the page hash. For example, "#section1".
Type
object
Show nested properties (2)
value
Description
Value to filter by
Type
string
operator
Description
Operator to apply for the string filter. "eq" means equals, "notEq" means not equals. "any" means no restriction and also matches users without a value; to require a value, use "notEq" with an empty string.
Operator to apply for the string filter. "eq" means equals, "notEq" means not equals. "any" means no restriction and also matches users without a value; to require a value, use "notEq" with an empty string.
Ability to filter for either anonymous or identified users. This is useful when you want to include only known users (for example, for a retention analysis) or only anonymous users (for example, to analyze new visitor behavior).
Type
object
Default
"user"
Example
{"type":"user","anonymous":true}
Show nested properties (1)
anonymous
Description
Filter for anonymous (true) or identified (false) users.
Filter by one or more country codes (ISO-3166 alpha-2, e.g. "US").
Type
object
Show nested properties (2)
value
Description
List of values to filter by
Type
array<string>
operator
Description
Operator to apply for the list filter. The "any" operator means that any value is accepted and effectively disables the filter. To require a value, use "noneOf" with [""].
Operator to apply for the list filter. The "any" operator means that any value is accepted and effectively disables the filter. To require a value, use "noneOf" with [""].
Referrer value to match, as returned when grouping by referrer (e.g. "Google"). An empty string matches visits without a referrer and visits from the project's own domain (referrer type internal). For visits without a referrer only, filter by the referrer type none.
List of referrer types to match: none (no referrer: typed in, bookmarks, apps), search, social, llm, email, paid, internal (came from a page on the project's own domain, e.g. a link from your app to your website; direct is accepted as an old name) or unknown (a website or source that isn't in Vemetric's list of known sources; visits without a referrer are none).
Type
array<string>
Example
["search","social"]
operator
Description
List matching operator for value. To require a value, use "noneOf" with [""].
Operator to apply for the string filter. "eq" means equals, "notEq" means not equals. "any" means no restriction and also matches users without a value; to require a value, use "notEq" with an empty string.
Operator to apply for the string filter. "eq" means equals, "notEq" means not equals. "any" means no restriction and also matches users without a value; to require a value, use "notEq" with an empty string.
Operator to apply for the string filter. "eq" means equals, "notEq" means not equals. "any" means no restriction and also matches users without a value; to require a value, use "notEq" with an empty string.
Operator to apply for the string filter. "eq" means equals, "notEq" means not equals. "any" means no restriction and also matches users without a value; to require a value, use "notEq" with an empty string.
Operator to apply for the string filter. "eq" means equals, "notEq" means not equals. "any" means no restriction and also matches users without a value; to require a value, use "notEq" with an empty string.
Whether users must have completed or not completed the selected step.
Type
"completed" | "notCompleted"
Example
"completed"
filtersOperator
Description
Echo of the incoming filtersOperator request field.
Type
"and" | "or"
pagination
Description
Pagination metadata for the response.
Type
object
limit
Description
Applied row limit after internal normalization.
Type
integer
offset
Description
Applied row offset after internal normalization.
Type
integer
returned
Description
Number of rows returned in data. Can be used to determine if there are more rows available for pagination (when returned is equal to limit, there might be more rows available on the next page).
Type
integer
data
Description
Result rows for the query after grouping, sorting, and pagination.
Type
array<object>
group
Description
Group values for this row. Empty object for aggregate queries.
Type
object
Example
{"date":"2026-01-18T00:00:00Z"}
Show nested properties (25)
date
Description
UTC timestamp in ISO-8601 format with second precision (no milliseconds).
Calculated metric values for the row. Only requested metrics are returned.
Type
object
Show nested properties (5)
users
Description
Unique users count for this row.
Type
number
Example
412
pageviews
Description
Pageview events count for this row.
Type
number
Example
1736
events
Description
Custom events count for this row.
Type
number
Example
43
bounceRate
Description
Bounce rate percentage for this row. Can be null when not applicable for the selected grouping.
Type
number | null
Example
34.12
visitDuration
Description
Average visit duration in seconds for this row. Can be null when not applicable for the selected grouping.
Type
number | null
Example
1222.45
400 Bad request - invalid request payload or parameters, or an organization key without the X-Vemetric-Project header
application/json
error
Description
Error details.
Type
object
code
Description
Machine-readable error code. HTTP_ERROR is returned for a malformed JSON body, PROJECT_REQUIRED for an organization key without the X-Vemetric-Project header.