Skip to content

Commit

Permalink
Added stats API
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew <mnickson@sidingsmedia.com>
  • Loading branch information
Computroniks committed May 3, 2024
1 parent c90992f commit a82fd61
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 0 deletions.
28 changes: 28 additions & 0 deletions components/schemas/Event.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# SPDX-FileCopyrightText: 2024 Sidings Media
# SPDX-License-Identifier: MIT

type: object
properties:
domain:
type: string
description: Domain of site
name:
type: string
description: Name of event to log.
url:
type: string
format: uri
description: URL of page that triggered event
referrer:
type: string
description: Referrer for this event
props:
type: object
description: |
Custom properties for the event. Note maximum of 30 key value
pairs. If more than 30 are provided the exceeding keys will be
ignored.
required:
- domain
- name
- url
7 changes: 7 additions & 0 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ info:
| `/terms` | `static` | https://github.com/SidingsMedia/static.git |
| `/openapi` | `openapi` | https://github.com/SidingsMedia/openapi.git |
| `/openapi.json` | `openapi` | https://github.com/SidingsMedia/openapi.git |
| `/stats` | stats | https://github.com/plausible/analytics.git |
Each service will expose a health check endpoint that will return a
plaintext `200 OK` response when called. This is documented by this
Expand Down Expand Up @@ -85,4 +86,10 @@ paths:

/terms:
$ref: paths/terms.yaml

/stats/event:
$ref: paths/stats/event.yaml

/stats/health:
$ref: paths/stats/health.yaml

40 changes: 40 additions & 0 deletions paths/stats/event.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# SPDX-FileCopyrightText: 2024 Sidings Media
# SPDX-License-Identifier: MIT

post:
description: Log an analytics event
summary: Log an event
operationId: logEvent
tags:
- stats
parameters:
- in: header
name: User-Agent
schema:
type: string
example: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0.1
required: true
requestBody:
required: true
content:
application/json:
schema:
$ref: ../../components/schemas/Event.yaml
example:
domain: sidingsmedia.com
event: pageview
url: https://sidingsmedia.com
responses:
'202':
content:
text/plain:
schema:
type: string
example:
value: ok
'400':
$ref: ../../components/responses/BadRequest.yaml
'429':
$ref: ../../components/responses/TooManyRequests.yaml
5XX:
$ref: ../../components/responses/ServerError.yaml
16 changes: 16 additions & 0 deletions paths/stats/health.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# SPDX-FileCopyrightText: 2024 Sidings Media
# SPDX-License-Identifier: MIT

get:
description: Stats service health check
summary: Health check
operationId: statsHealth
tags:
- stats
responses:
'200':
$ref: ../../components/responses/HealthCheckOK.yaml
'429':
$ref: ../../components/responses/TooManyRequests.yaml
5XX:
$ref: ../../components/responses/ServerError.yaml

0 comments on commit a82fd61

Please sign in to comment.