Batteries

Analytics

Register the events you care about, log them, and count them back. Types are declared up front so a typo is an error at the call that made it rather than a dimension that reads zero forever.

Every call below goes to the address in your SAASIE_ANALYTICS_URL environment variable, with Authorization: Bearer <token>. Read both from the environment — they are injected, and hardcoding either is how an app breaks when the platform moves. See getting the credential.

POST /v1/analytics/events

Log events

Every event's type must be registered, and every property must be one that type declared. Both are 400s rather than silently-stored data, because an event nobody meant to send is worse than one that was refused.

Request body

FieldType
events* object[]

200 — How many were stored

FieldType
recorded* number How many events were stored.
remainingToday* number How many more this Saasie may log before the daily cap.

When it does not work

400An unregistered type, or an undeclared property
401Missing or invalid service token
403The Saasie is stopped
429The daily event cap is spent
501This Saasie has no analytics storage
502The analytics cluster is unreachable

POST /v1/analytics/query

Count events over a range

A constrained query, never SQL: a type, a range, a bucket size, and optionally one declared property to split by. That is enough to draw a chart and small enough that nothing a caller sends becomes part of a statement.

Request body

FieldType
type* string
since* integer | string Start of the range, inclusive. Epoch milliseconds or ISO.
until integer | string End of the range, exclusive. Left out, it is now.
interval string hour · day · week · month, defaults to day
groupBy string A property of this type to split the counts by. It must be one the type declared.

200 — Counts per bucket

FieldType
type* string
interval* string hour · day · week · month
since* number
until* number
groupBy* string | null
buckets* object[]
total* number

When it does not work

400Unknown type, undeclared groupBy, or too wide a range
401Missing or invalid service token
501This Saasie has no analytics storage
502The analytics cluster is unreachable

POST /v1/analytics/types

Register an event type

Idempotent, so an app can call it at boot without checking. Registering an existing type replaces the properties it declares — which is how a type gains one, and also how an event carrying an old property starts being refused.

Request body

FieldType
name* string The event type, e.g. signup. Registering it again updates it.
properties object The properties every event of this type may carry, and what each one means. An event carrying anything else is refused. defaults to {}

200 — The type, as it now stands

FieldType
name* string
properties* object
createdAt* number
updatedAt* number

When it does not work

400The name or a property name is not usable
401Missing or invalid service token
403The Saasie is stopped

GET /v1/analytics/types

What this Saasie has registered

200 — Every registered type

FieldType
types* object[]

When it does not work

401Missing or invalid service token

Generated from openapi.json, which the service renders from its own routes. * marks a required field. Every error body is { "error": { "code", "message", "details"? } }.