Need Help Building Multi-Site Visitor Dashboard
I manage multiple websites and I’m trying to create a unified dashboard that shows current active users across all my sites. Currently I have to open separate tabs for each property which is really tedious.
The Challenge
Since Google Analytics doesn’t provide a real-time API, I’m looking into extracting this data directly from their interface. I noticed that the live visitor count gets updated through network calls to a specific endpoint.
What I’ve Discovered So Far
The real-time data seems to flow through requests to /analytics/realtime/connect. I’ve been monitoring these calls and found several parameters that I need help understanding:
POST /analytics/realtime/connect?VERSION=9
Parameters:
- token: [mysterious 20-char string, remains constant]
- session: [another 20-char string, stays same]
- viewId: dashboard-main/overview
- query: encoded_data_string
- requestId: rpc_call
- sessionId: [16-char uppercase code, constant]
- counter: [number that increments strangely]
- requestType: xhr
- timestamp: [12-char changing value]
Sample Response Data
The server returns what looks like modified JSON with visitor counts:
42
[[301,["update"]
]
]
456
[[302,["analytics",[{"visitors:live":{
"timeframe":"MINUTES",
"data":[{"counts":[23,31,28,35,41,29,33,27,38,45,52,48,39,44,36,41,47,33,29,51,43,38,42,39,48,35,41,56,49,43],"label":"Active Users"}]
}}]]]]
My main questions:
- How can I authenticate programmatically to access this data?
- What do these mysterious parameter values represent and where do they come from?
- How should I parse the response to extract the actual visitor numbers?
Any guidance would be really appreciated!