Skip to content

Triggers & Events

Triggers are the heart of Ostrakon. They let you organize and track your events.

A trigger is a logical container that groups similar events. Think of it as a category or a named counter.

Examples of triggers:

  • "Page Views" - Page views on your site
  • "User Signups" - User sign-ups
  • "API Requests" - Calls to your API
  • "Button Clicks" - Clicks on a specific button
Terminal window
curl -X POST https://ostrakon.example.com/api/v1/triggers \
-H "X-API-Key: sk_votre_cle" \
-H "Content-Type: application/json" \
-d '{
"name": "Page Views",
"description": "Track page views",
"tags": ["analytics", "frontend"],
"color": "#3B82F6"
}'

Creating a trigger requires the trigger:manage scope (a JWT has it by default). The response contains the trigger id. The name must be unique within your account (409 name_exists otherwise).

Property Type Description
name string Trigger name (required)
slug string Readable identifier for public access by slug
description string Optional description
tags string[] Tags for organizing
color string Hex color for the UI
visibility string private (default) or public
allow_public_events boolean Lets anonymous visitors send events (public trigger)
event_mode string click (single events only), batch or both (default): the last two also accept /events/batch
max_batch_size integer Maximum batch size for this trigger (1 to 100)
group_id string UUID of the trigger's group

Field names are snake_case. An unknown field is ignored without error: a typo changes nothing.

Terminal window
curl -X POST https://ostrakon.example.com/api/v1/triggers/{id}/events \
-H "X-API-Key: sk_votre_cle" \
-H "Content-Type: application/json" \
-d '{}'
Terminal window
curl -X POST https://ostrakon.example.com/api/v1/triggers/{id}/events \
-H "X-API-Key: sk_votre_cle" \
-H "Content-Type: application/json" \
-d '{
"metadata": {
"page": "/products",
"userId": "user_123",
"referrer": "google.com",
"device": "mobile"
}
}'

For better performance, send several events at once (100 at most per request). A trigger with event_mode: "click" refuses batches (403, batch_not_allowed):

Terminal window
curl -X POST https://ostrakon.example.com/api/v1/triggers/{id}/events/batch \
-H "X-API-Key: sk_votre_cle" \
-H "Content-Type: application/json" \
-d '{
"events": [
{"metadata": {"page": "/home"}},
{"metadata": {"page": "/about"}},
{"metadata": {"page": "/contact"}}
]
}'

A 202 response means the event is accepted in memory, not yet written to the database. It is recorded a few moments later (about 1 s by default). If the server stops abruptly, the event can be lost (a full buffer, or a server shutdown in progress, return 503): see the "Ingest durability" page of the repository documentation (docs/features/ingest-durability.md).

Terminal window
curl https://ostrakon.example.com/api/v1/triggers/{id}/stats \
-H "X-API-Key: sk_votre_cle"

Reading statistics requires the trigger:stats scope on the trigger. By default, the window is the last hour; from, to (e.g. now-24h), interval (e.g. 1h) and filter (JSON on the metadata) change it:

Terminal window
curl "https://ostrakon.example.com/api/v1/triggers/{id}/stats?from=now-24h&interval=1h" \
-H "X-API-Key: sk_votre_cle"

Response:

{
"trigger_id": "550e8400-e29b-41d4-a716-446655440000",
"from": "2024-01-15T09:30:00Z",
"to": "2024-01-15T10:30:00Z",
"total": 1523,
"buckets": [
{"time": "2024-01-15T09:00:00Z", "count": 156},
{"time": "2024-01-15T10:00:00Z", "count": 203}
]
}

Only the intervals that contain events appear in buckets.

Make a trigger publicly accessible (without authentication):

Terminal window
curl -X PATCH https://ostrakon.example.com/api/v1/triggers/{id} \
-H "X-API-Key: sk_votre_cle" \
-H "Content-Type: application/json" \
-d '{
"visibility": "public",
"slug": "my-public-counter"
}'

GET reads the trigger, without authentication:

Terminal window
# By ID
curl https://ostrakon.example.com/api/v1/public/triggers/{id}
# By slug
curl https://ostrakon.example.com/api/v1/public/trigger/my-public-counter

Public statistics are at /public/triggers/{id}/stats. A POST reads nothing: it records an event, and only if the trigger has allow_public_events: true (to enable with a PATCH, otherwise 403):

Terminal window
curl -X POST https://ostrakon.example.com/api/v1/public/trigger/my-public-counter \
-H "Content-Type: application/json" \
-d '{"metadata": {"source": "widget"}}'

Give another account access to a trigger, by its account_id (JWT or trigger:manage key):

Terminal window
curl -X POST https://ostrakon.example.com/api/v1/triggers/{id}/access \
-H "Authorization: Bearer TOKEN" \
-H "Content-Type: application/json" \
-d '{
"account_id": "550e8400-e29b-41d4-a716-446655440000",
"permissions": ["read", "stats"]
}'
Permission Grants access to
read The trigger and its metadata
stats The data: statistics and events
hit Sending events
manage Everything, including sharing

GET /triggers/{id}/access lists the accesses (id, account_id, permissions, granted_by, granted_at), DELETE /triggers/{id}/access/{accessId} revokes one. If you do not know the person's account_id, create an invitation (POST /triggers/{id}/invitations, with permissions and expires_in_hours): they accept it with POST /invitations/{token}/accept.

A trigger moves from your personal account to an organization (tenant) where you are owner or admin, or from an organization to an account. A personal trigger cannot be transferred directly to another account. A JWT is required (an API key cannot transfer).

Terminal window
curl -X POST https://ostrakon.example.com/api/v1/triggers/{id}/transfer \
-H "Authorization: Bearer TOKEN" \
-H "Content-Type: application/json" \
-d '{
"target_type": "tenant",
"target_id": "550e8400-e29b-41d4-a716-446655440000"
}'

target_type is tenant (target_id is the organization) or account (target_id is the account receiving the trigger, from an organization). The trigger becomes private and leaves its group. See Organizations (Tenants) for roles and limits.

Terminal window
curl -X DELETE https://ostrakon.example.com/api/v1/triggers/{id} \
-H "X-API-Key: sk_votre_cle"

Editing (PATCH) and deleting a trigger require trigger:manage. The response is 204.

Warning: Deleting a trigger also erases all its events.

  1. Consistent naming - Use a convention: category_action (e.g. user_signup, page_view)

  2. Relevant tags - Make searching easier with useful tags

  3. Structured metadata - Keep a consistent structure for your metadata

  4. Batch when possible - Group events to reduce API calls