Get analytics data
curl --request GET \
--url https://api.sapt.ai/web-analytics/{projectId} \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.sapt.ai/web-analytics/{projectId}"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};
fetch('https://api.sapt.ai/web-analytics/{projectId}', 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://api.sapt.ai/web-analytics/{projectId}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.sapt.ai/web-analytics/{projectId}"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.sapt.ai/web-analytics/{projectId}")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.sapt.ai/web-analytics/{projectId}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"projectId": "<string>",
"dateRange": {
"startDate": "<string>",
"endDate": "<string>"
},
"ga4": {
"source": "ga4",
"totalPageviews": 123,
"totalVisitors": 123,
"totalVisits": 123,
"dailyMetrics": [
{
"date": "<string>",
"pageviews": 123,
"visitors": 123,
"visits": 123,
"bounceRate": 123,
"avgSessionDuration": 123
}
],
"fetchedAt": "2023-11-07T05:31:56Z",
"bounceRate": 123,
"avgSessionDuration": 123,
"topPages": [
{
"path": "<string>",
"pageviews": 123,
"visitors": 123
}
],
"topReferrers": [
{
"referrer": "<string>",
"visits": 123
}
],
"topCountries": [
{
"country": "<string>",
"visitors": 123,
"countryName": "<string>"
}
],
"trafficSources": [
{
"source": "<string>",
"medium": "<string>",
"sessions": 123,
"users": 123,
"bounceRate": 123
}
],
"landingPages": [
{
"path": "<string>",
"sessions": 123,
"users": 123,
"bounceRate": 123,
"avgSessionDuration": 123
}
],
"outboundLinks": [
{
"url": "<string>",
"domain": "<string>",
"clicks": 123
}
],
"devices": [
{
"device": "desktop",
"sessions": 123,
"users": 123,
"bounceRate": 123
}
],
"browsers": [
{
"browser": "<string>",
"users": 123
}
],
"operatingSystems": [
{
"os": "<string>",
"users": 123
}
],
"usStates": [
{
"region": "<string>",
"visitors": 123,
"regionCode": "<string>"
}
]
},
"gsc": {
"totalClicks": 123,
"totalImpressions": 123,
"averageCtr": 123,
"averagePosition": 123,
"dailyMetrics": [
{
"date": "<string>",
"clicks": 123,
"impressions": 123,
"ctr": 123,
"position": 123
}
],
"topQueries": [
{
"query": "<string>",
"clicks": 123,
"impressions": 123,
"ctr": 123,
"position": 123
}
],
"topPages": [
{
"page": "<string>",
"clicks": 123,
"impressions": 123,
"ctr": 123,
"position": 123
}
],
"fetchedAt": "2023-11-07T05:31:56Z"
},
"fetchedAt": "2023-11-07T05:31:56Z",
"errors": [
{
"source": "ga4",
"message": "<string>",
"code": "<string>"
}
]
}{
"message": "<string>",
"code": "<string>"
}{
"message": "<string>",
"code": "<string>"
}{
"message": "<string>",
"code": "<string>"
}{
"message": "<string>",
"code": "<string>"
}Web Analytics
Get analytics data
Get analytics data from all configured sources (Cloudflare, GA4, GSC). Returns partial data with errors if some sources fail.
GET
/
web-analytics
/
{projectId}
Get analytics data
curl --request GET \
--url https://api.sapt.ai/web-analytics/{projectId} \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.sapt.ai/web-analytics/{projectId}"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};
fetch('https://api.sapt.ai/web-analytics/{projectId}', 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://api.sapt.ai/web-analytics/{projectId}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.sapt.ai/web-analytics/{projectId}"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.sapt.ai/web-analytics/{projectId}")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.sapt.ai/web-analytics/{projectId}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"projectId": "<string>",
"dateRange": {
"startDate": "<string>",
"endDate": "<string>"
},
"ga4": {
"source": "ga4",
"totalPageviews": 123,
"totalVisitors": 123,
"totalVisits": 123,
"dailyMetrics": [
{
"date": "<string>",
"pageviews": 123,
"visitors": 123,
"visits": 123,
"bounceRate": 123,
"avgSessionDuration": 123
}
],
"fetchedAt": "2023-11-07T05:31:56Z",
"bounceRate": 123,
"avgSessionDuration": 123,
"topPages": [
{
"path": "<string>",
"pageviews": 123,
"visitors": 123
}
],
"topReferrers": [
{
"referrer": "<string>",
"visits": 123
}
],
"topCountries": [
{
"country": "<string>",
"visitors": 123,
"countryName": "<string>"
}
],
"trafficSources": [
{
"source": "<string>",
"medium": "<string>",
"sessions": 123,
"users": 123,
"bounceRate": 123
}
],
"landingPages": [
{
"path": "<string>",
"sessions": 123,
"users": 123,
"bounceRate": 123,
"avgSessionDuration": 123
}
],
"outboundLinks": [
{
"url": "<string>",
"domain": "<string>",
"clicks": 123
}
],
"devices": [
{
"device": "desktop",
"sessions": 123,
"users": 123,
"bounceRate": 123
}
],
"browsers": [
{
"browser": "<string>",
"users": 123
}
],
"operatingSystems": [
{
"os": "<string>",
"users": 123
}
],
"usStates": [
{
"region": "<string>",
"visitors": 123,
"regionCode": "<string>"
}
]
},
"gsc": {
"totalClicks": 123,
"totalImpressions": 123,
"averageCtr": 123,
"averagePosition": 123,
"dailyMetrics": [
{
"date": "<string>",
"clicks": 123,
"impressions": 123,
"ctr": 123,
"position": 123
}
],
"topQueries": [
{
"query": "<string>",
"clicks": 123,
"impressions": 123,
"ctr": 123,
"position": 123
}
],
"topPages": [
{
"page": "<string>",
"clicks": 123,
"impressions": 123,
"ctr": 123,
"position": 123
}
],
"fetchedAt": "2023-11-07T05:31:56Z"
},
"fetchedAt": "2023-11-07T05:31:56Z",
"errors": [
{
"source": "ga4",
"message": "<string>",
"code": "<string>"
}
]
}{
"message": "<string>",
"code": "<string>"
}{
"message": "<string>",
"code": "<string>"
}{
"message": "<string>",
"code": "<string>"
}{
"message": "<string>",
"code": "<string>"
}Authorizations
JWT token obtained from /api/auth/token endpoint. Token is verified using JWKS and must include a valid user identifier.
Path Parameters
Example:
"123e4567-e89b-12d3-a456-426614174000"
Query Parameters
Start date in YYYY-MM-DD format
Pattern:
^\d{4}-\d{2}-\d{2}$Example:
"2024-01-01"
End date in YYYY-MM-DD format
Pattern:
^\d{4}-\d{2}-\d{2}$Example:
"2024-01-31"