General
Integrations
How to
Configuration
APIBeta
Stats Aggregation
The aggregation
query lets you compute overall metrics over a time window.
Some of the things you can compute with this query kind:
- Unique visitors and pageviews.
- Page load time statistics.
- Average visit duration.
- Average pages per visit.
- Bounce rate.
Endpoint
POST /v1/stats/aggregation
This endpoint responds with 200 - Success if successful, and will include a JSON object with one entry per selected field.
JSON Parameters
Field | Type | Description |
---|---|---|
site_id | string | The Site ID to query. required |
aggregate | string list | A list of dimensions to aggregate on. required |
period | string | The time window to aggregate. See time periods for valid values. Default: 1h . optional |
filter | object list | List of query filters to apply. optional |
timezone | string | Timezone to use for all time window calculations. For example: America/Costa_Rica . Refer to the list of timezones for possible timezone names. Default: UTC . optional |
Examples
Count unique visitors over the last 24 hours
The following JSON query returns the unique visitor count over the past 24 hours for a given <SITE_ID>
.
$ curl -X POST \ -H "Authorization: Bearer <TOKEN>" \ -H "Content-type: application/json" \ "https://api.panelbear.com/v1/stats/aggregation" \ -d '{ "site_id": "<SITE_ID>", "period": "24h", "aggregate": ["session_count"] }' < HTTP/1.1 200 OK < Content-Type: application/json { "data": { "session_count": { "value": 1417 } } }
Count unique visitors and total pageviews
Query unique visitors and total page views over the past 24 hours, filter to Pageview
events only:
$ curl -X POST \ -H "Authorization: Bearer <TOKEN>" \ -H "Content-type: application/json" \ "https://api.panelbear.com/v1/stats/aggregation" \ -d '{ "site_id": "<SITE_ID>", "period": "24h", "aggregate": ["session_count", "event_count"], "filter": [ { "dimension": "event_name", "operator": "eq", "value": "Pageview" } ] }' < HTTP/1.1 200 OK < Content-Type: application/json { "data": { "session_count": { "value": 1417 }, "event_count": { "value": 2122 } } }
Aggregate dimensions and compare to previous period
Query unique visitors and total page views over the past 4 weeks, and compare to the previous period:
$ curl -X POST \ -H "Authorization: Bearer <TOKEN>" \ -H "Content-type: application/json" \ "https://api.panelbear.com/v1/stats/aggregation" \ -d '{ "site_id": "<SITE_ID>", "period": "4w", "aggregate": ["session_count", "event_count"], "compare": "previous_period", "filter": [ { "dimension": "event_name", "operator": "eq", "value": "Pageview" } ] }' < HTTP/1.1 200 OK < Content-Type: application/json { "data": { "session_count": { "value": 1417, "previous_period_value": 501, "previous_period_change_rate": 2.82 }, "event_count": { "value": 2122, "previous_period_value": 1423, "previous_period_change_rate": 1.49 } } }
Calculate average page load time over the past week
The following JSON query returns the average load time over the past 7 days for a given <SITE_ID>
. The page_load_avg
dimension is measured in milliseconds.
$ curl -X POST \ -H "Authorization: Bearer <TOKEN>" \ -H "Content-type: application/json" \ "https://api.panelbear.com/v1/stats/aggregation" \ -d '{ "site_id": "<SITE_ID>", "period": "7d", "aggregate": ["page_load_avg"] }' < HTTP/1.1 200 OK < Content-Type: application/json { "data": { "page_load_avg": { "value": 915 } } }
Calculate average frontend, backend, and network timings
The following JSON query returns the average load time by frontend, backend and network timings over the past 24 hours for a given <SITE_ID>
. These three dimensions are measured in milliseconds.
$ curl -X POST \ -H "Authorization: Bearer <TOKEN>" \ -H "Content-type: application/json" \ "https://api.panelbear.com/v1/stats/aggregation" \ -d '{ "site_id": "<SITE_ID>", "period": "24h", "aggregate": [ "page_load_frontend_avg", "page_load_backend_avg", "page_load_network_avg" ] }' < HTTP/1.1 200 OK < Content-Type: application/json { "data": { "page_load_frontend_avg": { "value": 237 }, "page_load_backend_avg": { "value": 281 }, "page_load_network_avg": { "value": 51 } } }
Calculate average pages per visit over the past week
The following JSON query returns the average load time over the past 7 days for a given <SITE_ID>
.
$ curl -X POST \ -H "Authorization: Bearer <TOKEN>" \ -H "Content-type: application/json" \ "https://api.panelbear.com/v1/stats/aggregation" \ -d '{ "site_id": "<SITE_ID>", "period": "7d", "aggregate": ["events_per_session_avg"] }' < HTTP/1.1 200 OK < Content-Type: application/json { "data": { "events_per_session_avg": { "value": 2.5 } } }