Triggers & Events
Triggers are the heart of Ostrakon. They let you organize and track your events.
What is a Trigger?
Section titled “What is a Trigger?”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
Create a Trigger
Section titled “Create a Trigger”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).
Properties
Section titled “Properties”| 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.
Send events
Section titled “Send events”Single event
Section titled “Single event”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 '{}'Event with metadata
Section titled “Event with metadata”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" } }'Batch events
Section titled “Batch events”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):
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).
Get statistics
Section titled “Get statistics”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:
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.
Public triggers
Section titled “Public triggers”Make a trigger publicly accessible (without authentication):
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" }'Access a public trigger
Section titled “Access a public trigger”GET reads the trigger, without authentication:
# By IDcurl https://ostrakon.example.com/api/v1/public/triggers/{id}
# By slugcurl https://ostrakon.example.com/api/v1/public/trigger/my-public-counterPublic 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):
curl -X POST https://ostrakon.example.com/api/v1/public/trigger/my-public-counter \ -H "Content-Type: application/json" \ -d '{"metadata": {"source": "widget"}}'Share access
Section titled “Share access”Give another account access to a trigger, by its account_id (JWT or trigger:manage key):
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.
Transfer a trigger
Section titled “Transfer a trigger”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).
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.
Delete a trigger
Section titled “Delete a trigger”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.
Best practices
Section titled “Best practices”-
Consistent naming - Use a convention:
category_action(e.g.user_signup,page_view) -
Relevant tags - Make searching easier with useful tags
-
Structured metadata - Keep a consistent structure for your metadata
-
Batch when possible - Group events to reduce API calls