Execute an analytics query
curl --request POST \
--url https://your-instance.example.com/api/analytics.query \
--header 'Content-Type: application/json' \
--data '
{
"workspace_id": "<string>",
"metrics": [
"<string>"
],
"dateRange": {
"start": "<string>",
"end": "<string>"
},
"dimensions": [
"<string>"
],
"filters": [
{
"dimension": "<string>",
"values": [
{}
]
}
],
"metricFilters": [
{
"metric": "<string>",
"values": [
{}
]
}
],
"compareDateRange": {
"start": "<string>",
"end": "<string>"
},
"timezone": "<string>",
"order": {},
"limit": 5000.5,
"havingMinSessions": 2,
"totalsGroupBy": [
"<string>"
]
}
'import requests
url = "https://your-instance.example.com/api/analytics.query"
payload = {
"workspace_id": "<string>",
"metrics": ["<string>"],
"dateRange": {
"start": "<string>",
"end": "<string>"
},
"dimensions": ["<string>"],
"filters": [
{
"dimension": "<string>",
"values": [{}]
}
],
"metricFilters": [
{
"metric": "<string>",
"values": [{}]
}
],
"compareDateRange": {
"start": "<string>",
"end": "<string>"
},
"timezone": "<string>",
"order": {},
"limit": 5000.5,
"havingMinSessions": 2,
"totalsGroupBy": ["<string>"]
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
workspace_id: '<string>',
metrics: ['<string>'],
dateRange: {start: '<string>', end: '<string>'},
dimensions: ['<string>'],
filters: [{dimension: '<string>', values: [{}]}],
metricFilters: [{metric: '<string>', values: [{}]}],
compareDateRange: {start: '<string>', end: '<string>'},
timezone: '<string>',
order: {},
limit: 5000.5,
havingMinSessions: 2,
totalsGroupBy: ['<string>']
})
};
fetch('https://your-instance.example.com/api/analytics.query', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://your-instance.example.com/api/analytics.query",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'workspace_id' => '<string>',
'metrics' => [
'<string>'
],
'dateRange' => [
'start' => '<string>',
'end' => '<string>'
],
'dimensions' => [
'<string>'
],
'filters' => [
[
'dimension' => '<string>',
'values' => [
[
]
]
]
],
'metricFilters' => [
[
'metric' => '<string>',
'values' => [
[
]
]
]
],
'compareDateRange' => [
'start' => '<string>',
'end' => '<string>'
],
'timezone' => '<string>',
'order' => [
],
'limit' => 5000.5,
'havingMinSessions' => 2,
'totalsGroupBy' => [
'<string>'
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://your-instance.example.com/api/analytics.query"
payload := strings.NewReader("{\n \"workspace_id\": \"<string>\",\n \"metrics\": [\n \"<string>\"\n ],\n \"dateRange\": {\n \"start\": \"<string>\",\n \"end\": \"<string>\"\n },\n \"dimensions\": [\n \"<string>\"\n ],\n \"filters\": [\n {\n \"dimension\": \"<string>\",\n \"values\": [\n {}\n ]\n }\n ],\n \"metricFilters\": [\n {\n \"metric\": \"<string>\",\n \"values\": [\n {}\n ]\n }\n ],\n \"compareDateRange\": {\n \"start\": \"<string>\",\n \"end\": \"<string>\"\n },\n \"timezone\": \"<string>\",\n \"order\": {},\n \"limit\": 5000.5,\n \"havingMinSessions\": 2,\n \"totalsGroupBy\": [\n \"<string>\"\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://your-instance.example.com/api/analytics.query")
.header("Content-Type", "application/json")
.body("{\n \"workspace_id\": \"<string>\",\n \"metrics\": [\n \"<string>\"\n ],\n \"dateRange\": {\n \"start\": \"<string>\",\n \"end\": \"<string>\"\n },\n \"dimensions\": [\n \"<string>\"\n ],\n \"filters\": [\n {\n \"dimension\": \"<string>\",\n \"values\": [\n {}\n ]\n }\n ],\n \"metricFilters\": [\n {\n \"metric\": \"<string>\",\n \"values\": [\n {}\n ]\n }\n ],\n \"compareDateRange\": {\n \"start\": \"<string>\",\n \"end\": \"<string>\"\n },\n \"timezone\": \"<string>\",\n \"order\": {},\n \"limit\": 5000.5,\n \"havingMinSessions\": 2,\n \"totalsGroupBy\": [\n \"<string>\"\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://your-instance.example.com/api/analytics.query")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"workspace_id\": \"<string>\",\n \"metrics\": [\n \"<string>\"\n ],\n \"dateRange\": {\n \"start\": \"<string>\",\n \"end\": \"<string>\"\n },\n \"dimensions\": [\n \"<string>\"\n ],\n \"filters\": [\n {\n \"dimension\": \"<string>\",\n \"values\": [\n {}\n ]\n }\n ],\n \"metricFilters\": [\n {\n \"metric\": \"<string>\",\n \"values\": [\n {}\n ]\n }\n ],\n \"compareDateRange\": {\n \"start\": \"<string>\",\n \"end\": \"<string>\"\n },\n \"timezone\": \"<string>\",\n \"order\": {},\n \"limit\": 5000.5,\n \"havingMinSessions\": 2,\n \"totalsGroupBy\": [\n \"<string>\"\n ]\n}"
response = http.request(request)
puts response.read_body{}Analytics
Execute an analytics query
POST
/
api
/
analytics.query
Execute an analytics query
curl --request POST \
--url https://your-instance.example.com/api/analytics.query \
--header 'Content-Type: application/json' \
--data '
{
"workspace_id": "<string>",
"metrics": [
"<string>"
],
"dateRange": {
"start": "<string>",
"end": "<string>"
},
"dimensions": [
"<string>"
],
"filters": [
{
"dimension": "<string>",
"values": [
{}
]
}
],
"metricFilters": [
{
"metric": "<string>",
"values": [
{}
]
}
],
"compareDateRange": {
"start": "<string>",
"end": "<string>"
},
"timezone": "<string>",
"order": {},
"limit": 5000.5,
"havingMinSessions": 2,
"totalsGroupBy": [
"<string>"
]
}
'import requests
url = "https://your-instance.example.com/api/analytics.query"
payload = {
"workspace_id": "<string>",
"metrics": ["<string>"],
"dateRange": {
"start": "<string>",
"end": "<string>"
},
"dimensions": ["<string>"],
"filters": [
{
"dimension": "<string>",
"values": [{}]
}
],
"metricFilters": [
{
"metric": "<string>",
"values": [{}]
}
],
"compareDateRange": {
"start": "<string>",
"end": "<string>"
},
"timezone": "<string>",
"order": {},
"limit": 5000.5,
"havingMinSessions": 2,
"totalsGroupBy": ["<string>"]
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
workspace_id: '<string>',
metrics: ['<string>'],
dateRange: {start: '<string>', end: '<string>'},
dimensions: ['<string>'],
filters: [{dimension: '<string>', values: [{}]}],
metricFilters: [{metric: '<string>', values: [{}]}],
compareDateRange: {start: '<string>', end: '<string>'},
timezone: '<string>',
order: {},
limit: 5000.5,
havingMinSessions: 2,
totalsGroupBy: ['<string>']
})
};
fetch('https://your-instance.example.com/api/analytics.query', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://your-instance.example.com/api/analytics.query",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'workspace_id' => '<string>',
'metrics' => [
'<string>'
],
'dateRange' => [
'start' => '<string>',
'end' => '<string>'
],
'dimensions' => [
'<string>'
],
'filters' => [
[
'dimension' => '<string>',
'values' => [
[
]
]
]
],
'metricFilters' => [
[
'metric' => '<string>',
'values' => [
[
]
]
]
],
'compareDateRange' => [
'start' => '<string>',
'end' => '<string>'
],
'timezone' => '<string>',
'order' => [
],
'limit' => 5000.5,
'havingMinSessions' => 2,
'totalsGroupBy' => [
'<string>'
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://your-instance.example.com/api/analytics.query"
payload := strings.NewReader("{\n \"workspace_id\": \"<string>\",\n \"metrics\": [\n \"<string>\"\n ],\n \"dateRange\": {\n \"start\": \"<string>\",\n \"end\": \"<string>\"\n },\n \"dimensions\": [\n \"<string>\"\n ],\n \"filters\": [\n {\n \"dimension\": \"<string>\",\n \"values\": [\n {}\n ]\n }\n ],\n \"metricFilters\": [\n {\n \"metric\": \"<string>\",\n \"values\": [\n {}\n ]\n }\n ],\n \"compareDateRange\": {\n \"start\": \"<string>\",\n \"end\": \"<string>\"\n },\n \"timezone\": \"<string>\",\n \"order\": {},\n \"limit\": 5000.5,\n \"havingMinSessions\": 2,\n \"totalsGroupBy\": [\n \"<string>\"\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://your-instance.example.com/api/analytics.query")
.header("Content-Type", "application/json")
.body("{\n \"workspace_id\": \"<string>\",\n \"metrics\": [\n \"<string>\"\n ],\n \"dateRange\": {\n \"start\": \"<string>\",\n \"end\": \"<string>\"\n },\n \"dimensions\": [\n \"<string>\"\n ],\n \"filters\": [\n {\n \"dimension\": \"<string>\",\n \"values\": [\n {}\n ]\n }\n ],\n \"metricFilters\": [\n {\n \"metric\": \"<string>\",\n \"values\": [\n {}\n ]\n }\n ],\n \"compareDateRange\": {\n \"start\": \"<string>\",\n \"end\": \"<string>\"\n },\n \"timezone\": \"<string>\",\n \"order\": {},\n \"limit\": 5000.5,\n \"havingMinSessions\": 2,\n \"totalsGroupBy\": [\n \"<string>\"\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://your-instance.example.com/api/analytics.query")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"workspace_id\": \"<string>\",\n \"metrics\": [\n \"<string>\"\n ],\n \"dateRange\": {\n \"start\": \"<string>\",\n \"end\": \"<string>\"\n },\n \"dimensions\": [\n \"<string>\"\n ],\n \"filters\": [\n {\n \"dimension\": \"<string>\",\n \"values\": [\n {}\n ]\n }\n ],\n \"metricFilters\": [\n {\n \"metric\": \"<string>\",\n \"values\": [\n {}\n ]\n }\n ],\n \"compareDateRange\": {\n \"start\": \"<string>\",\n \"end\": \"<string>\"\n },\n \"timezone\": \"<string>\",\n \"order\": {},\n \"limit\": 5000.5,\n \"havingMinSessions\": 2,\n \"totalsGroupBy\": [\n \"<string>\"\n ]\n}"
response = http.request(request)
puts response.read_body{}Body
application/json
Minimum array length:
1Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Required range:
1 <= x <= 10000Required range:
x >= 1Available options:
sessions, pages, goals When set, enables "filtered totals" mode for queries with no dimensions. The query will:
- Group by these dimensions in an inner subquery
- Apply metricFilters via HAVING clause
- Aggregate the filtered results in an outer query
Use this for totals that should respect metricFilters. Example: Get total sessions where bounce_rate > 50%, grouped by landing_path.
Response
200 - application/json
The response is of type object.
⌘I