Events API

The Events module provides real-time event collection, transformation, validation, and forwarding. It supports standard event types (track, identify, page, group) and includes write key management, schema contracts, JavaScript transformations, and forwarding rules.

Endpoint Groups

GroupDescription
Event IngestionTrack, identify, page, and group calls
Write KeysManage SDK authentication keys
ContractsDefine and enforce event schemas
TransformationsJavaScript event transformations
Forwarding RulesRoute events to destinations
Volume & LiveEvent volume metrics and live stream

Event Ingestion

Track Event

POST /api/v1/workspaces/{id}/events/track

Records a user action or event.

Request Body

FieldTypeRequiredDescription
eventstringYesEvent name (e.g., purchase_completed)
user_idstringConditionalIdentified user ID (required if no anonymous_id)
anonymous_idstringConditionalAnonymous user ID (required if no user_id)
propertiesobjectNoEvent-specific properties
timestampstring (ISO 8601)NoEvent timestamp (defaults to server time)
contextobjectNoContext metadata (device, location, etc.)
{
  "event": "purchase_completed",
  "user_id": "user-123",
  "properties": {
    "order_id": "ORD-456",
    "total": 99.99,
    "currency": "USD",
    "items": ["SKU-001", "SKU-002"]
  },
  "timestamp": "2024-01-15T15:00:00Z",
  "context": {
    "ip": "203.0.113.1",
    "user_agent": "Mozilla/5.0..."
  }
}

Example

curl -X POST https://your-instance.signalsmith.io/api/v1/workspaces/{id}/events/track \
  -H "Authorization: Bearer <write-key>" \
  -H "X-Workspace-ID: <workspace-id>" \
  -H "Content-Type: application/json" \
  -d '{
    "event": "purchase_completed",
    "user_id": "user-123",
    "properties": {
      "order_id": "ORD-456",
      "total": 99.99
    }
  }'

Identify User

POST /api/v1/workspaces/{id}/events/identify

Associates traits with a user identity.

Request Body

FieldTypeRequiredDescription
user_idstringConditionalUser ID
anonymous_idstringConditionalAnonymous ID
traitsobjectNoUser traits to set
{
  "user_id": "user-123",
  "traits": {
    "email": "alice@example.com",
    "name": "Alice Smith",
    "plan": "enterprise",
    "signup_date": "2024-01-01"
  }
}

Page View

POST /api/v1/workspaces/{id}/events/page

Records a page view.

Request Body

FieldTypeRequiredDescription
user_idstringConditionalUser ID
anonymous_idstringConditionalAnonymous ID
namestringNoPage name
propertiesobjectNoPage properties (url, title, referrer, etc.)
{
  "user_id": "user-123",
  "name": "Pricing",
  "properties": {
    "url": "https://example.com/pricing",
    "title": "Pricing - Example App",
    "referrer": "https://google.com"
  }
}

Group Association

POST /api/v1/workspaces/{id}/events/group

Associates a user with a group (company, team, account).

Request Body

FieldTypeRequiredDescription
user_idstringConditionalUser ID
anonymous_idstringConditionalAnonymous ID
group_idstringYesGroup identifier
traitsobjectNoGroup traits
{
  "user_id": "user-123",
  "group_id": "company-456",
  "traits": {
    "name": "Acme Corp",
    "industry": "Technology",
    "employee_count": 250
  }
}

Write Keys

Write keys authenticate event ingestion requests. Each key is scoped to a workspace and environment.

MethodPathDescription
GET/api/v1/workspaces/{id}/event-keysList write keys
POST/api/v1/workspaces/{id}/event-keysCreate a write key
DELETE/api/v1/workspaces/{id}/event-keys/{keyId}Revoke a write key

Create Write Key

{
  "name": "Web SDK - Production",
  "environment": "production"
}

Write Key Object

FieldTypeDescription
idstring (UUID)Unique identifier
workspace_idstring (UUID)Owning workspace
namestringDisplay name
key_prefixstringFirst few characters for identification
environmentstringproduction or development
statusstringactive or revoked
pubsub_topicstringPub/Sub topic for event routing
last_used_atstring (ISO 8601) or nullLast event received time
created_bystring (UUID)Account that created the key
created_atstring (ISO 8601)Creation timestamp
updated_atstring (ISO 8601)Last update timestamp

Contracts

Event contracts define the expected schema for event types and enforce validation rules.

MethodPathDescription
GET/api/v1/workspaces/{id}/event-contractsList contracts
POST/api/v1/workspaces/{id}/event-contractsCreate a contract
GET/api/v1/workspaces/{id}/event-contracts/{contractId}Get a contract
PUT/api/v1/workspaces/{id}/event-contracts/{contractId}Update a contract
DELETE/api/v1/workspaces/{id}/event-contracts/{contractId}Delete a contract
GET/api/v1/workspaces/{id}/event-contracts/{contractId}/violationsGet violations

Create Contract

{
  "name": "Purchase Completed Schema",
  "event_type": "track",
  "event_name": "purchase_completed",
  "description": "Schema for purchase completion events",
  "schema_definition": {
    "properties": {
      "order_id": {"type": "string", "required": true},
      "total": {"type": "number", "required": true},
      "currency": {"type": "string", "required": true}
    }
  },
  "enforcement_mode": "warn",
  "undeclared_fields": "allow"
}

Enforcement Modes

ModeDescription
allowSchema is informational only; all events pass through
warnEvents pass through but violations are recorded
blockEvents that violate the schema are rejected

Contract Object

FieldTypeDescription
idstring (UUID)Unique identifier
namestringDisplay name
event_typestringEvent type (e.g., track, identify)
event_namestringEvent name to match
schema_definitionobjectJSON schema for validation
enforcement_modestringallow, warn, or block
undeclared_fieldsstringHow to handle fields not in the schema
statusstringactive or archived

Transformations

Event transformations apply JavaScript functions to modify events before forwarding.

MethodPathDescription
GET/api/v1/workspaces/{id}/event-transformationsList transformations
POST/api/v1/workspaces/{id}/event-transformationsCreate a transformation
GET/api/v1/workspaces/{id}/event-transformations/{txId}Get a transformation
PUT/api/v1/workspaces/{id}/event-transformations/{txId}Update a transformation
DELETE/api/v1/workspaces/{id}/event-transformations/{txId}Delete a transformation

Create Transformation

{
  "name": "Enrich Purchase Events",
  "description": "Add computed fields to purchase events",
  "source_code": "function transform(event) {\n  if (event.properties.total > 100) {\n    event.properties.tier = 'high_value';\n  }\n  return event;\n}",
  "test_input": {"event": "purchase_completed", "properties": {"total": 150}},
  "test_output": {"event": "purchase_completed", "properties": {"total": 150, "tier": "high_value"}}
}

Transformation Object

FieldTypeDescription
idstring (UUID)Unique identifier
namestringDisplay name
descriptionstringDescription
source_codestringJavaScript transformation function
test_inputobjectSample input for testing
test_outputobjectExpected output for testing
statusstringdraft, active, or error

Forwarding Rules

Forwarding rules define how events are routed to destinations.

MethodPathDescription
GET/api/v1/workspaces/{id}/event-forwarding-rulesList forwarding rules
POST/api/v1/workspaces/{id}/event-forwarding-rulesCreate a forwarding rule
GET/api/v1/workspaces/{id}/event-forwarding-rules/{ruleId}Get a forwarding rule
PUT/api/v1/workspaces/{id}/event-forwarding-rules/{ruleId}Update a forwarding rule
DELETE/api/v1/workspaces/{id}/event-forwarding-rules/{ruleId}Delete a forwarding rule

Create Forwarding Rule

{
  "name": "All Track Events to Amplitude",
  "destination_id": "880e8400-e29b-41d4-a716-446655440000",
  "event_types": ["track"],
  "event_names": [],
  "transformation_id": null,
  "enabled": true
}

Volume & Live

Event Volume

GET /api/v1/workspaces/{id}/event-volume

Returns hourly aggregated event counts for the workspace.

Query Parameters

ParameterTypeDescription
hoursintegerNumber of hours to look back (default: 24)

Response

[
  {
    "event_type": "track",
    "event_name": "purchase_completed",
    "hour_bucket": "2024-01-15T14:00:00Z",
    "event_count": 1523
  }
]

Live Event Stream

GET /api/v1/workspaces/{id}/events/live

Returns a real-time stream of recent events via Server-Sent Events (SSE). Used by the live debugger in the UI.