TopStats SDK
Elixir analytics SDK
A GenServer holds the buffer, so batching, timed flushes and shutdown draining are ordinary OTP - put it in your supervision tree and capture is a cast that never blocks the caller. The phoenix package adds a Plug with route templates from the Phoenix router.
Install
# Hex soon; today:
{:topstats_analytics, git: "https://github.com/top-stats/analytics-elixir-sdk"}Capture your first event
{:ok, client} = TopstatsAnalytics.start_link(
api_key: System.fetch_env!("TOPSTATS_API_KEY"),
default_source: "api")
TopstatsAnalytics.capture(client, "email_sent", %{"template" => "digest"},
%{actor: "user-88"})
TopstatsAnalytics.flush(client)Behaviour you can rely on
- Capture never throws into your code and never blocks on the network - a bounded queue buffers and a background loop batches.
- Retries only 429, 5xx and network failures, with jittered backoff honouring Retry-After; your API key never appears in error output.
- Zero dependencies: Elixir 1.18 JSON and :httpc do the work.
- Flag evaluation is a direct call returning {:ok, flags} | {:error, reason} - never buffered.