Skip to main content

Providers

A provider is an adapter that delivers analytics events to a specific backend (Amplitude, Mixpanel, PostHog, etc.). Providers implement a stable interface so your application code never depends on a vendor SDK directly.

The Provider interface

type Provider interface {
Metadata() ProviderMetadata
Hooks() []hooks.Hook

Track(ctx context.Context, event TrackMessage) error
Identify(ctx context.Context, msg IdentifyMessage) error
Group(ctx context.Context, msg GroupMessage) error
Page(ctx context.Context, msg PageMessage) error
Alias(ctx context.Context, msg AliasMessage) error

Flush(ctx context.Context) error
Shutdown(ctx context.Context) error
}

Providers that don't support a given operation return ErrUnsupportedOperation rather than silently no-op — preventing silent data loss.

Message types

Every call to the runtime dispatches a typed message struct to the provider:

MethodMessage typeKey fields
TrackTrackMessageEventName, Properties, UserId, AnonymousId, Context
IdentifyIdentifyMessageUserId, AnonymousId, Traits, Context
GroupGroupMessageUserId, GroupId, Traits, Context
PagePageMessageUserId, Name, Properties, Context
AliasAliasMessageUserId, PreviousId

MessageContext carries structured environment metadata: UserAgent, Locale, IP, App, Device, OS, Screen, Campaign, and an Extra map for custom keys.

Provider capabilities

type ProviderCapabilities struct {
Track bool
Identify bool
Group bool
Page bool
Alias bool
}

The runtime checks capabilities before dispatch and records Dropped outcomes for unsupported operations.

Multi-provider dispatch

The client sends events to all registered providers simultaneously:

client := analytics.NewClient(
analytics.WithProviders(amplitudeProvider, posthogProvider),
)

// Both providers receive the event concurrently.
// Per-provider outcomes accessible via TrackDetailed:
result, err := client.TrackDetailed(ctx, event)
// result.Success — providers that succeeded
// result.Failed — providers that failed (permanent)

Delivery states

StateMeaning
DeliveredProvider confirmed receipt
FailedPermanently rejected after max retries
DroppedDiscarded by sampling, queue overflow, schema violation, or unsupported operation

Built-in providers

ProviderLanguageStatus
AmplitudeGo, TypeScript, Kotlin✅ Available
event-spec serverGo, TypeScript, Kotlin✅ Available
NoopGo✅ Available
PostHogGo❌ Planned
MixpanelGo❌ Planned
SegmentGo❌ Planned
GA4Go❌ Planned

Writing a custom provider

See Providers — Custom for a full walkthrough.