Skip to main content

event-spec Server Provider

The event-spec server provider is a thin client that forwards analytics events to an event-spec runtime ingestion server over HTTP. The server runs the full hook chain, validation, sampling, batching, and multi-provider dispatch — the client only needs the server URL, an API key, and a source name.

When to use this provider

ScenarioRecommendation
Web apps where bundle size matters✅ Thin client — no vendor SDK in the browser
Centralised provider credentials✅ API keys live server-side only
Dynamic provider routing without client updates✅ Change server config, not client code
PII filtering or server-side governance hooks✅ Applied server-side before reaching any vendor
Native mobile apps requiring offline buffering❌ Use the embedded Amplitude or PostHog provider instead

Installation

go get github.com/dejanradmanovic/event-spec@latest

The event-spec server provider is included in the module at provider/event-spec.

Basic setup

import (
"github.com/dejanradmanovic/event-spec/provider"
eventspec "github.com/dejanradmanovic/event-spec/provider/event-spec"
)

p, err := eventspec.New(eventspec.Config{
BaseURL: "https://events.internal",
APIKey: "bearer-token",
Source: "web-app",
})

Full configuration

p, err := eventspec.New(eventspec.Config{
ProviderConfig: provider.ProviderConfig{
// Proxy through your domain to route through a firewall or bypass ad-blockers
ProxyURL: "https://analytics.yourcompany.com",
ProxyMode: provider.ProxyReverseProxy,

// Retry on transient HTTP errors (429, 500, 502, 503, 504)
RetryConfig: provider.RetryConfig{
MaxRetries: 5,
InitialBackoff: 100 * time.Millisecond,
MaxBackoff: 30 * time.Second,
Jitter: true,
},

// Token-bucket rate limiting
RateLimitConfig: provider.RateLimitConfig{
RequestsPerSecond: 100,
},
},
BaseURL: "https://events.internal",
APIKey: "bearer-token",
Source: "web-app",
})

Wire format

All five analytics operations POST to the corresponding /v1/* endpoint on the ingestion server. Every request includes Authorization: Bearer <api-key> and Content-Type: application/json.

MethodEndpointKey body fields
trackPOST /v1/tracksource, event_name, properties, context, timestamp
identifyPOST /v1/identifysource, user_id, anonymous_id, traits, timestamp
groupPOST /v1/groupsource, user_id, group_id, traits, timestamp
pagePOST /v1/pagesource, user_id, name, properties, timestamp
aliasPOST /v1/aliassource, user_id, previous_id, timestamp
flushPOST /v1/flushsource

Example track request body:

{
"source": "web-app",
"event_name": "Product Viewed",
"properties": { "product_id": "SKU-123" },
"context": {
"user_id": "user-456",
"anonymous_id": "anon-789",
"attributes": { "user_agent": "Mozilla/5.0 ...", "ip_address": "1.2.3.4" }
},
"timestamp": "2026-05-21T10:30:00Z"
}

context.attributes is populated from MessageContext.UserAgent, MessageContext.IPAddress, and MessageContext.Extra. If omitted, the server fills them in from the HTTP request automatically.

Flush and shutdown

Flush sends POST /v1/flush to trigger a server-side drain of queued events and waits for the response. Shutdown calls Flush then closes the provider; all subsequent method calls return an error.

Supported operations

All five analytics operations are supported: track, identify, group, page, alias.