SQL
Run your own SELECT across one or more websites when no query type answers your question.
{
"columns": [
{ "name": "path", "type": "String" },
{ "name": "pageviews", "type": "UInt64" },
{ "name": "visitors", "type": "UInt64" }
],
"rows": [{ "path": "/", "pageviews": "1204", "visitors": "811" }],
"truncated": false,
"elapsedMs": 38
}The key needs read:data for every website in the request. 64-bit integers and decimals come back as strings so they stay exact; parse them with Number or BigInt.
Write the request
Compare websites
A query sees only the websites you name. Group by the website column to compare them, such as client_id on analytics.events:
{
"websiteIds": ["FIRST_WEBSITE_ID", "SECOND_WEBSITE_ID"],
"sql": "SELECT client_id, count() AS pageviews FROM analytics.events WHERE event_name = 'screen_view' GROUP BY client_id"
}Join on the website columns too when matches must come from the same website.
Find tables and columns
curl https://api.databuddy.cc/sql/schema -H "x-api-key: $DATABUDDY_API_KEY"GET /sql/schema lists every table and column you can read, with notes on how to count each one. SQL tables shows the same list. On analytics.events, pageviews have event_name = 'screen_view', rows are dated by time, and visitors are uniq(anonymous_id). Tables such as analytics.error_spans need a plan that includes their feature.
Stay within limits
Narrow the date range, select fewer columns or aggregate when you hit a limit.
Fix errors
Related
How is this guide?