Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

Add new API endpoints

Blue Mouse98938e73bb91
diff --git a/docs/docs/api/admin.md b/docs/docs/api/admin.md
index 75ca37e87..28c28ced8 100644
--- a/docs/docs/api/admin.md
+++ b/docs/docs/api/admin.md
@@ -44,8 +44,96 @@ If you have special needs for more requests, please [contact us](https://swetrix
| `botsProtectionLevel` | `off` or `basic` | Set to `basic` or `off`. `basic` will block common bots by user agent and `off` will allow all traffic. `basic` by default. |
| `organisationId` | `string` | Organisation you want to add this project to. You must be an owner or admin of the organisation to add a project to it. |
+### Organisations manipulation
+
+#### 'Create organisation' payload
+
+| Name | Type | Required | Description |
+| ------ | -------- | -------- | ------------------------------------------------------------- |
+| `name` | `string` | `true` | A display name for your organisation, max length is 50 chars. |
+
+#### 'Invite member' payload
+
+| Name | Type | Required | Description |
+| ------- | ------------------------------ | -------- | ------------------------------------------------- |
+| `email` | `string` | `true` | The email address of the user you want to invite. |
+| `role` | `owner` or `admin` or `viewer` | `true` | The role to assign to the invited user. |
+
+#### 'Update member role' payload
+
+| Name | Type | Required | Description |
+| ------ | ------------------------------ | -------- | ------------------------------------- |
+| `role` | `owner` or `admin` or `viewer` | `true` | The new role to assign to the member. |
+
+### Funnels manipulation
+
+#### 'Create funnel' payload
+
+| Name | Type | Required | Description |
+| ------- | --------------- | -------- | --------------------------------------------------------------------------- |
+| `name` | `string` | `true` | A display name for your funnel, max length is 50 chars. |
+| `pid` | `string` | `true` | The Project ID the funnel belongs to. |
+| `steps` | `Array<string>` | `true` | An array of paths for the funnel steps (e.g., `['/', '/signup', '/dash']`). |
+
+#### 'Update funnel' payload
+
+| Name | Type | Required | Description |
+| ------- | --------------- | -------- | --------------------------------------------------------------------------- |
+| `id` | `string` | `true` | The ID of the funnel to update. |
+| `pid` | `string` | `true` | The Project ID the funnel belongs to. |
+| `name` | `string` | `true` | A display name for your funnel, max length is 50 chars. |
+| `steps` | `Array<string>` | `true` | An array of paths for the funnel steps (e.g., `['/', '/signup', '/dash']`). |
+
+### Annotations manipulation
+
+#### 'Create annotation' payload
+
+| Name | Type | Required | Description |
+| ------ | -------- | -------- | ----------------------------------------- |
+| `pid` | `string` | `true` | The Project ID the annotation belongs to. |
+| `date` | `string` | `true` | Date of the annotation (YYYY-MM-DD). |
+| `text` | `string` | `true` | Annotation text (max 120 characters). |
+
+#### 'Update annotation' payload
+
+| Name | Type | Required | Description |
+| ------ | -------- | -------- | ----------------------------------------- |
+| `id` | `string` | `true` | The ID of the annotation to update. |
+| `pid` | `string` | `true` | The Project ID the annotation belongs to. |
+| `date` | `string` | `false` | Date of the annotation (YYYY-MM-DD). |
+| `text` | `string` | `false` | Annotation text (max 120 characters). |
+
## Endpoints
+### GET /v1/project
+
+This endpoint allows you to list all your projects.
+
+```bash title="Request"
+curl -i -X GET https://api.swetrix.com/v1/project \
+ -H "X-Api-Key: ${SWETRIX_API_KEY}"
+```
+
+```json title="Response (200 OK)"
+[
+ {
+ "id": "WvZCYTrOPzSK",
+ "name": "My Project",
+ "active": true,
+ "public": false
+ }
+]
+```
+
+### GET /v1/project/:id
+
+This endpoint allows you to get details of a specific project.
+
+```bash title="Request"
+curl -i -X GET https://api.swetrix.com/v1/project/WvZCYTrOPzSK \
+ -H "X-Api-Key: ${SWETRIX_API_KEY}"
+```
+
### POST /v1/project
This endpoint allows you to create a new project.
@@ -126,6 +214,24 @@ curl -i -X DELETE https://api.swetrix.com/v1/project/WvZCYTrOPzSK \
```
+### POST /v1/project/:id/pin
+
+Pin a project to the top of the dashboard.
+
+```bash title="Request"
+curl -i -X POST https://api.swetrix.com/v1/project/WvZCYTrOPzSK/pin \
+ -H "X-Api-Key: ${SWETRIX_API_KEY}"
+```
+
+### DELETE /v1/project/:id/pin
+
+Unpin a project from the top of the dashboard.
+
+```bash title="Request"
+curl -i -X DELETE https://api.swetrix.com/v1/project/WvZCYTrOPzSK/pin \
+ -H "X-Api-Key: ${SWETRIX_API_KEY}"
+```
+
### PATCH /v1/project/:id/organisation
This endpoint allows you to assign a project to an organisation, or unassign it from an organisation. To unassign a project from an organisation, don't pass the request body.
@@ -141,6 +247,166 @@ curl -i -X PATCH https://api.swetrix.com/v1/project/WvZCYTrOPzSK/organisation \
```
+### GET /v1/project/funnels/:pid
+
+Get all funnels for a specific project.
+
+```bash title="Request"
+curl -i -X GET https://api.swetrix.com/v1/project/funnels/WvZCYTrOPzSK \
+ -H "X-Api-Key: ${SWETRIX_API_KEY}"
+```
+
+### POST /v1/project/funnel
+
+Create a new funnel.
+
+```bash title="Request"
+curl -i -X POST https://api.swetrix.com/v1/project/funnel \
+ -H "X-Api-Key: ${SWETRIX_API_KEY}" \
+ -H "Content-Type: application/json" \
+ -d '{"name": "Sign up","pid": "WvZCYTrOPzSK", "steps": ["/", "/signup"]}'
+```
+
+### PATCH /v1/project/funnel
+
+Update an existing funnel.
+
+```bash title="Request"
+curl -i -X PATCH https://api.swetrix.com/v1/project/funnel \
+ -H "X-Api-Key: ${SWETRIX_API_KEY}" \
+ -H "Content-Type: application/json" \
+ -d '{"id": "FUNNEL_ID", "name": "Sign up 2", "pid": "WvZCYTrOPzSK", "steps": ["/", "/signup"]}'
+```
+
+### DELETE /v1/project/funnel/:id/:pid
+
+Delete a funnel.
+
+```bash title="Request"
+curl -i -X DELETE https://api.swetrix.com/v1/project/funnel/FUNNEL_ID/WvZCYTrOPzSK \
+ -H "X-Api-Key: ${SWETRIX_API_KEY}"
+```
+
+### GET /v1/project/annotations/:pid
+
+Get all annotations for a specific project.
+
+```bash title="Request"
+curl -i -X GET https://api.swetrix.com/v1/project/annotations/WvZCYTrOPzSK \
+ -H "X-Api-Key: ${SWETRIX_API_KEY}"
+```
+
+### POST /v1/project/annotation
+
+Create a new annotation.
+
+```bash title="Request"
+curl -i -X POST https://api.swetrix.com/v1/project/annotation \
+ -H "X-Api-Key: ${SWETRIX_API_KEY}" \
+ -H "Content-Type: application/json" \
+ -d '{"text": "Marketing campaign", "pid": "WvZCYTrOPzSK", "date": "2023-10-01"}'
+```
+
+### PATCH /v1/project/annotation
+
+Update an existing annotation.
+
+```bash title="Request"
+curl -i -X PATCH https://api.swetrix.com/v1/project/annotation \
+ -H "X-Api-Key: ${SWETRIX_API_KEY}" \
+ -H "Content-Type: application/json" \
+ -d '{"id": "ANNOTATION_ID", "pid": "WvZCYTrOPzSK", "text": "Updated text"}'
+```
+
+### DELETE /v1/project/annotation/:id/:pid
+
+Delete an annotation.
+
+```bash title="Request"
+curl -i -X DELETE https://api.swetrix.com/v1/project/annotation/ANNOTATION_ID/WvZCYTrOPzSK \
+ -H "X-Api-Key: ${SWETRIX_API_KEY}"
+```
+
+### GET /v1/organisation
+
+List all organisations you are a member of.
+
+```bash title="Request"
+curl -i -X GET https://api.swetrix.com/v1/organisation \
+ -H "X-Api-Key: ${SWETRIX_API_KEY}"
+```
+
+### GET /v1/organisation/:orgId
+
+Get details of a specific organisation.
+
+```bash title="Request"
+curl -i -X GET https://api.swetrix.com/v1/organisation/ORG_ID \
+ -H "X-Api-Key: ${SWETRIX_API_KEY}"
+```
+
+### POST /v1/organisation
+
+Create a new organisation.
+
+```bash title="Request"
+curl -i -X POST https://api.swetrix.com/v1/organisation \
+ -H "X-Api-Key: ${SWETRIX_API_KEY}" \
+ -H "Content-Type: application/json" \
+ -d '{"name": "My Organisation"}'
+```
+
+### PATCH /v1/organisation/:orgId
+
+Update an organisation.
+
+```bash title="Request"
+curl -i -X PATCH https://api.swetrix.com/v1/organisation/ORG_ID \
+ -H "X-Api-Key: ${SWETRIX_API_KEY}" \
+ -H "Content-Type: application/json" \
+ -d '{"name": "My Updated Organisation"}'
+```
+
+### DELETE /v1/organisation/:orgId
+
+Delete an organisation. You must be the owner to do this.
+
+```bash title="Request"
+curl -i -X DELETE https://api.swetrix.com/v1/organisation/ORG_ID \
+ -H "X-Api-Key: ${SWETRIX_API_KEY}"
+```
+
+### POST /v1/organisation/:orgId/invite
+
+Invite a new member to the organisation.
+
+```bash title="Request"
+curl -i -X POST https://api.swetrix.com/v1/organisation/ORG_ID/invite \
+ -H "X-Api-Key: ${SWETRIX_API_KEY}" \
+ -H "Content-Type: application/json" \
+ -d '{"email": "[email protected]", "role": "viewer"}'
+```
+
+### PATCH /v1/organisation/member/:memberId
+
+Update a member's role.
+
+```bash title="Request"
+curl -i -X PATCH https://api.swetrix.com/v1/organisation/member/MEMBER_ID \
+ -H "X-Api-Key: ${SWETRIX_API_KEY}" \
+ -H "Content-Type: application/json" \
+ -d '{"role": "admin"}'
+```
+
+### DELETE /v1/organisation/member/:memberId
+
+Remove a member from the organisation.
+
+```bash title="Request"
+curl -i -X DELETE https://api.swetrix.com/v1/organisation/member/MEMBER_ID \
+ -H "X-Api-Key: ${SWETRIX_API_KEY}"
+```
+
## Status and error codes
### 200 OK
diff --git a/docs/docs/api/stats.md b/docs/docs/api/stats.md
index 6ef3bba53..48b2c6715 100644
--- a/docs/docs/api/stats.md
+++ b/docs/docs/api/stats.md
@@ -53,7 +53,7 @@ It supports the following values:
1. `median` (default) - the middle value of a set of numbers (i.e. 50th percentile).
2. `average` - the arithmetic mean value.
3. `p95` - the 95th quantile.
-4. `quantiles` - it's a special measure, because instead of the regular metrics (e.g. `dns`, `tls`, etc.) it will return load time (the sum on all metrics) across 3 qunatiles: `p50`, `p75` and `p95`.
+4. `quantiles` - it's a special measure, because instead of the regular metrics (e.g. `dns`, `tls`, etc.) it will return load time (the sum on all metrics) across 3 quantiles: `p50`, `p75` and `p95`.
### Filters
@@ -303,7 +303,7 @@ The `meta` is an array of objects like:
"key": "amount", // equals to "metricKey" provided
"current": { // for the current period or from / to pair
"sum": 100, // the sum of all custom metrics
- "avg": 20, // the averae of all custom metrics
+ "avg": 20, // the average of all custom metrics
},
"previous": { // for the previous period of the same length as the current one
"sum": 80,
@@ -962,6 +962,419 @@ The timezone to use for the time range. The default is `Etc/GMT`. You can use an
<hr />
+### GET /v1/log/funnel
+
+Returns a funnel analysis for a specific set of pages.
+
+```bash
+curl 'https://api.swetrix.com/v1/log/funnel?pid=YOUR_PROJECT_ID&pages=["/","/pricing","/signup"]&period=30d'\
+ -H "X-Api-Key: ${SWETRIX_API_KEY}"
+```
+
+```json title="Response"
+{
+ "funnel": [
+ {
+ "page": "/",
+ "count": 100,
+ "dropoff": 0,
+ "dropoffPercentage": 0
+ },
+ {
+ "page": "/pricing",
+ "count": 50,
+ "dropoff": 50,
+ "dropoffPercentage": 50
+ },
+ {
+ "page": "/signup",
+ "count": 10,
+ "dropoff": 40,
+ "dropoffPercentage": 80
+ }
+ ],
+ "totalPageviews": 160
+}
+```
+
+#### Parameters
+
+The parameters are similar to the [`/log` endpoint](#get-v1log), with the addition of:
+
+**pages** (optional)
+
+A stringified JSON array of page paths to define the funnel steps.
+
+**funnelId** (optional)
+
+The ID of a saved funnel to retrieve.
+
+### GET /v1/log/user-flow
+
+Returns the user flow diagram data, showing how users navigate through your website.
+
+```bash
+curl 'https://api.swetrix.com/v1/log/user-flow?pid=YOUR_PROJECT_ID&period=7d'\
+ -H "X-Api-Key: ${SWETRIX_API_KEY}"
+```
+
+#### Parameters
+
+The parameters are similar to the [`/log` endpoint](#get-v1log).
+
+### GET /v1/log/chart
+
+Returns data for the main chart (visits, uniques, sessions duration, etc.) grouped by time bucket. This is useful when you only need the chart data without other aggregations.
+
+```bash
+curl 'https://api.swetrix.com/v1/log/chart?pid=YOUR_PROJECT_ID&timeBucket=day&period=7d'\
+ -H "X-Api-Key: ${SWETRIX_API_KEY}"
+```
+
+#### Parameters
+
+The parameters are the same as for the [`/log` endpoint](#get-v1log).
+
+### GET /v1/log/performance/chart
+
+Returns performance data for the chart (DNS, TLS, etc.) grouped by time bucket.
+
+```bash
+curl 'https://api.swetrix.com/v1/log/performance/chart?pid=YOUR_PROJECT_ID&timeBucket=day&period=7d'\
+ -H "X-Api-Key: ${SWETRIX_API_KEY}"
+```
+
+#### Parameters
+
+The parameters are the same as for the [`/log/performance` endpoint](#get-v1logperformance).
+
+### GET /v1/log/captcha
+
+Returns aggregated CAPTCHA statistics.
+
+```bash
+curl 'https://api.swetrix.com/v1/log/captcha?pid=YOUR_PROJECT_ID&period=7d'\
+ -H "X-Api-Key: ${SWETRIX_API_KEY}"
+```
+
+#### Parameters
+
+The parameters are the same as for the [`/log` endpoint](#get-v1log).
+
+### GET /v1/log/keywords
+
+Returns the search keywords data from Google Search Console integration.
+
+```bash
+curl 'https://api.swetrix.com/v1/log/keywords?pid=YOUR_PROJECT_ID&period=30d'\
+ -H "X-Api-Key: ${SWETRIX_API_KEY}"
+```
+
+#### Parameters
+
+<hr />
+
+**pid** (required)
+
+The project ID.
+
+<hr />
+
+**period** (required)
+
+See [periods](#periods).
+
+<hr />
+
+**from** / **to**
+
+Custom date range.
+
+<hr />
+
+**timezone**
+
+Timezone for the data.
+
+<hr />
+
+### GET /v1/log/custom-events
+
+Returns aggregated data for specific custom events, grouped by time bucket.
+
+```bash
+curl 'https://api.swetrix.com/v1/log/custom-events?pid=YOUR_PROJECT_ID&period=7d&customEvents=["signup","purchase"]'\
+ -H "X-Api-Key: ${SWETRIX_API_KEY}"
+```
+
+#### Parameters
+
+The parameters are similar to the [`/log` endpoint](#get-v1log), with the addition of:
+
+**customEvents** (required)
+
+A stringified JSON array of custom event names to retrieve data for.
+
+### GET /v1/log/profiles
+
+Returns a list of user profiles (visitors).
+
+```bash
+curl 'https://api.swetrix.com/v1/log/profiles?pid=YOUR_PROJECT_ID&period=30d&take=20'\
+ -H "X-Api-Key: ${SWETRIX_API_KEY}"
+```
+
+#### Parameters
+
+The parameters are similar to the [`/log/sessions` endpoint](#get-v1logsessions), with the addition of:
+
+**profileType** (optional)
+
+Filter by profile type. Possible values: `all` (default), `anonymous`, `identified`.
+
+### GET /v1/log/profile
+
+Returns details for a specific user profile.
+
+```bash
+curl 'https://api.swetrix.com/v1/log/profile?pid=YOUR_PROJECT_ID&profileId=PROFILE_ID'\
+ -H "X-Api-Key: ${SWETRIX_API_KEY}"
+```
+
+#### Parameters
+
+<hr />
+
+**pid** (required)
+
+The project ID.
+
+<hr />
+
+**profileId** (required)
+
+The unique identifier of the profile.
+
+<hr />
+
+**timezone**
+
+Timezone for the data.
+
+<hr />
+
+**period**, **from**, **to**
+
+Time range parameters.
+
+<hr />
+
+### GET /v1/log/profile/sessions
+
+Returns a list of sessions for a specific user profile.
+
+```bash
+curl 'https://api.swetrix.com/v1/log/profile/sessions?pid=YOUR_PROJECT_ID&profileId=PROFILE_ID&take=20'\
+ -H "X-Api-Key: ${SWETRIX_API_KEY}"
+```
+
+#### Parameters
+
+Same as [`/log/sessions`](#get-v1logsessions), but requires `profileId`.
+
+### GET /v1/log/errors
+
+Returns a list of error events.
+
+```bash
+curl 'https://api.swetrix.com/v1/log/errors?pid=YOUR_PROJECT_ID&period=7d'\
+ -H "X-Api-Key: ${SWETRIX_API_KEY}"
+```
+
+#### Parameters
+
+Same as [`/log/sessions`](#get-v1logsessions), with an optional `options` parameter.
+
+### GET /v1/log/get-error
+
+Returns details for a specific error group (by error ID `eid`).
+
+```bash
+curl 'https://api.swetrix.com/v1/log/get-error?pid=YOUR_PROJECT_ID&eid=ERROR_ID'\
+ -H "X-Api-Key: ${SWETRIX_API_KEY}"
+```
+
+#### Parameters
+
+<hr />
+
+**pid** (required)
+
+The project ID.
+
+<hr />
+
+**eid** (required)
+
+The error ID.
+
+<hr />
+
+**period**, **from**, **to**, **timezone**
+
+Time range parameters.
+
+<hr />
+
+### GET /v1/log/error-overview
+
+Returns an overview of error statistics (occurrences, users affected, etc.) for the chart.
+
+```bash
+curl 'https://api.swetrix.com/v1/log/error-overview?pid=YOUR_PROJECT_ID&period=7d'\
+ -H "X-Api-Key: ${SWETRIX_API_KEY}"
+```
+
+#### Parameters
+
+Same as [`/log` endpoint](#get-v1log).
+
+### GET /v1/log/error-sessions
+
+Returns a list of sessions affected by a specific error.
+
+```bash
+curl 'https://api.swetrix.com/v1/log/error-sessions?pid=YOUR_PROJECT_ID&eid=ERROR_ID'\
+ -H "X-Api-Key: ${SWETRIX_API_KEY}"
+```
+
+#### Parameters
+
+Same as [`/log/get-error`](#get-v1logget-error), with `take` and `skip`.
+
+### GET /v1/log/filters
+
+Returns available filter values for a specific column (e.g. all browser names).
+
+```bash
+curl 'https://api.swetrix.com/v1/log/filters?pid=YOUR_PROJECT_ID&type=br'\
+ -H "X-Api-Key: ${SWETRIX_API_KEY}"
+```
+
+#### Parameters
+
+**pid** (required)
+
+The project ID.
+
+**type** (required)
+
+The column to get filters for (e.g., `br`, `os`, `cc`).
+
+### GET /v1/log/errors-filters
+
+Returns available filter values for error tracking.
+
+```bash
+curl 'https://api.swetrix.com/v1/log/errors-filters?pid=YOUR_PROJECT_ID&type=os'\
+ -H "X-Api-Key: ${SWETRIX_API_KEY}"
+```
+
+#### Parameters
+
+Same as `/filters`.
+
+### GET /v1/log/filters/versions
+
+Returns available versions (browser or OS) for filtering.
+
+```bash
+curl 'https://api.swetrix.com/v1/log/filters/versions?pid=YOUR_PROJECT_ID&type=traffic&column=br'\
+ -H "X-Api-Key: ${SWETRIX_API_KEY}"
+```
+
+#### Parameters
+
+**pid** (required)
+
+The project ID.
+
+**type** (required)
+
+Data type: `traffic` or `errors`.
+
+**column** (required)
+
+Column: `br` or `os`.
+
+### GET /goal/:id/stats
+
+Returns statistics for a specific goal (conversions, conversion rate, trend).
+
+```bash
+curl 'https://api.swetrix.com/goal/GOAL_ID/stats?period=7d'\
+ -H "X-Api-Key: ${SWETRIX_API_KEY}"
+```
+
+#### Parameters
+
+**period**, **from**, **to**, **timezone**
+
+Time range parameters.
+
+### GET /goal/:id/chart
+
+Returns chart data for a specific goal.
+
+```bash
+curl 'https://api.swetrix.com/goal/GOAL_ID/chart?period=7d'\
+ -H "X-Api-Key: ${SWETRIX_API_KEY}"
+```
+
+#### Parameters
+
+**period**, **from**, **to**, **timezone**, **timeBucket**
+
+Time range parameters.
+
+### GET /v1/feature-flag/:id/stats
+
+Returns statistics for a specific feature flag (evaluations, true/false counts).
+
+```bash
+curl 'https://api.swetrix.com/v1/feature-flag/FLAG_ID/stats?period=7d'\
+ -H "X-Api-Key: ${SWETRIX_API_KEY}"
+```
+
+#### Parameters
+
+**period**, **from**, **to**, **timezone**
+
+Time range parameters.
+
+### GET /v1/feature-flag/:id/profiles
+
+Returns a list of profiles that have evaluated a specific feature flag.
+
+```bash
+curl 'https://api.swetrix.com/v1/feature-flag/FLAG_ID/profiles?period=7d'\
+ -H "X-Api-Key: ${SWETRIX_API_KEY}"
+```
+
+#### Parameters
+
+**period**, **from**, **to**, **timezone**
+
+Time range parameters.
+
+**take**, **skip**
+
+Pagination parameters.
+
+**result** (optional)
+
+Filter by result (`true` or `false`).
+
## Common request examples
### Data on visitors from the UK who did not visit the website using a mobile device