Skip to main content

Amplitude Provider

The Amplitude provider delivers events to the Amplitude HTTP API v2 using batching, retry, and optional reverse-proxy support.

Installation​

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

The Amplitude provider is included in the module at provider/amplitude.

Basic setup​

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

amp, err := amplitude.New(amplitude.Config{
ProviderConfig: provider.ProviderConfig{
APIKey: "${AMPLITUDE_API_KEY}",
SecretType: provider.SecretEnvVar,
},
})

Full configuration (Go)​

amp, err := amplitude.New(amplitude.Config{
ProviderConfig: provider.ProviderConfig{
APIKey: "${AMPLITUDE_API_KEY}",
SecretType: provider.SecretEnvVar,

// Proxy through your domain to bypass ad-blockers
ProxyURL: "https://analytics.yourcompany.com/amp",
ProxyMode: provider.ProxyReverseProxy,

// Batching
BatchSize: 100,
FlushInterval: 5 * time.Second,
MaxQueueSize: 10_000,
OverflowPolicy: provider.OverflowDropOldest,

// Retry
RetryConfig: provider.RetryConfig{
MaxRetries: 3,
InitialBackoff: 100 * time.Millisecond,
MaxBackoff: 30 * time.Second,
Multiplier: 2.0,
Jitter: true,
},

// Rate limiting
RateLimitConfig: provider.RateLimitConfig{
RequestsPerSecond: 30,
},
},
})

Configuration reference​

Secret management​

SecretTypeBehavior
SecretEnvVarReads the API key from the environment variable named by APIKey (e.g. APIKey: "${AMPLITUDE_API_KEY}")
SecretPlainUses APIKey as the literal key value (not recommended in production)

Proxy modes​

ProxyModeBehavior
ProxyNoneSends directly to api2.amplitude.com
ProxyReverseProxyRoutes through ProxyURL (your reverse proxy forwards to Amplitude)

The proxy mode is used to bypass browser ad-blockers in client-side applications by routing analytics through your own domain.

Overflow policies​

OverflowPolicyBehavior
OverflowDropOldestDrops oldest buffered events when queue is full
OverflowDropNewestDrops new events when queue is full (back pressure)
OverflowBlockBlocks the caller until queue space is available

Destination config (YAML)​

When using the server registry, declare destination config in YAML:

destinations/amplitude.yaml
name: amplitude
type: amplitude
config:
api_key: "${AMPLITUDE_API_KEY}"
batch_size: 100
flush_interval: "5s"

Supported operations​

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