Is there an API for the content in the "Web Analytics" dashboard?

I'm wanting to create a custom dashboard for my web analytics, but the API documentation seems to have no message of them. There appear to be other, eerily similar APIs, but none that seem to have the same coverage as the Web Analytics dashboard.
7 Replies
Chaika
Chaika15mo ago
The Cloudflare GraphQL Analytics API is where you can find most of Cloudflare's Analytics. https://developers.cloudflare.com/analytics/graphql-api/ You can use a client like GraphiQL which has schema introspection to help you out (https://developers.cloudflare.com/analytics/graphql-api/getting-started/compose-graphql-query/), as well as using the Dev Tools Network Tab (look for requests for the file graphql) to find the datasets/use the queries the dashboard uses as a starting point. There's a nicely formatted community website here also showing the graphql schema: https://cfdata.lol/graphql/ Looks like the Web Analytics Data is called "Rum". The Dashboard uses RumPageLoadEventsAdaptiveGroups and RumPerformanceEventsAdaptiveGroupsDatasets look like, both account scoped. There is a tutorial here on making your own dashboard: https://developers.cloudflare.com/analytics/graphql-api/tutorials/build-your-own-analytics/, but it's using one/website analytics rather then Web Analytics, so you'd have to adapt it
quisi.do
quisi.do15mo ago
If there is data on the Web Analytics UI that isn't in the Cloudflare Analytics RUM GraphQL schema, does that mean that that data cannot be accessed via the API?
Chaika
Chaika15mo ago
There is no such data. All of the data the Web Analytics UI pulls is from one of the RUM Datasets (well ok, it looks like there is one undocumented endpoint it uses for set up data, but none of the analytics data) The entire dashboard operates off the same API + GraphQL API. Some of it uses undocumented (and thus unsafe for you to use, subject to change at any time without warning) Rest APIs, but the entire graphql api should be fine to use I believe You can pop open dev tools (ctrl+shift+i) -> Network, and then switch to Web Analytics, and see the exact graphql queries it uses and steal them
quisi.do
quisi.do15mo ago
I suppose it's unsafe then. What I am doing is querying every field in the GraphQL API and noticing that I cannot reconstruct the UI with that data alone. I thought the rest of the data must be coming from an API other than Web Analytics, but it sounds instead like the other data is possibly deprecated instead?
Chaika
Chaika15mo ago
What data are you missing?
quisi.do
quisi.do15mo ago
I'm probably just being dumb, but I don't seem to have the cached/uncached breakdown of request counts, requests by country, bytes saved, SSL requests served, attacked blocked, any bandwidth statistics (cached or uncached), minimum/maximum/total unique visitors, any data from the security page, client HTTP and content type breakdown, DNS queries by response code, workers bandwidth, workers status codes, etc., etc., etc. Really seems like most of the stats in my Cloudflare dashboard (especially from secondary pages) aren't present in the GraphQL API.
Chaika
Chaika15mo ago
ahh ok, that's not "Web Analytics"/RUM which refer to Cloudflare's free private analytics using JS Snippets, those are part of Zone Analytics. Dev tools (ctrl+shift+i) -> Network is your friend, to find what exact queries a page uses/what dataset it is using. httpRequestsAdaptiveGroups is the generic zone or account scoped dataset that contains all sorts of information like that. The workers tab uses workersZoneSubrequestsAdaptiveGroups HttpRequestsAdaptiveGroups also contains firewall/security information, via securityAction/securitySource Looks like the older/free zone analytics uses the zone dataset httpRequests1mGroups for all that info. HttpRequestsAdaptiveGroups with adaptive sampling is used the newer pro or higher Web Traffic Analytics, which I don't think you have access to on free.