How do I see web analytics data thorugh API?

Hi, I need to create an API for my blog site, where I will need to expose last 24 hours most visited blog urls (Page View) in the API. How can I do it? I have tried to get this one, https://api.cloudflare.com/client/v4/zones/{ZONE_ID}/analytics/dashboard but it's giving error, look like this API doesn't works. These urls I want to get through API.
No description
1 Reply
Chaika
Chaika2w ago
The answer is GraphQL, https://developers.cloudflare.com/analytics/graphql-api/, which Cloudflare does all its analytics via nowadays Page Views in the API just check for requests returning 200 & html, essentially like
{
viewer {
zones(filter: {zoneTag: "<zoneId>"}) {
httpRequestsAdaptiveGroups(filter: {date_gt: "2024-11-07", AND: [{edgeResponseContentTypeName: "html"}, {edgeResponseStatus: 200}]}, limit: 100, orderBy: [count_DESC]) {
dimensions {
clientRequestPath
}
count
sum {
visits
}
}
}
}
}
{
viewer {
zones(filter: {zoneTag: "<zoneId>"}) {
httpRequestsAdaptiveGroups(filter: {date_gt: "2024-11-07", AND: [{edgeResponseContentTypeName: "html"}, {edgeResponseStatus: 200}]}, limit: 100, orderBy: [count_DESC]) {
dimensions {
clientRequestPath
}
count
sum {
visits
}
}
}
}
}
then you can filter further by hostname (clientRequestHTTPHost) either in filters or dimensions, etc
Want results from more Discord servers?
Add your server