Expand description
umbral-analytics — product-analytics event capture for umbral.
Analytics instrumentation, the umbral way: declare the plugin, call
capture / identify from any handler or service, and analytics
failures never break a request. The PostHog backend is fire-and-forget;
every send is spawned on a background task so the caller returns
immediately.
§Quick start
ⓘ
// Wire in main
App::builder()
.plugin(
AnalyticsPlugin::new("phc_your_api_key")
.capture_requests(), // optional: auto pageview per request
)
.build()
.await?;
// In a handler
use umbral_analytics::{capture, identify};
async fn signup(/* ... */) -> impl IntoResponse {
identify("user_42", serde_json::json!({ "$set": { "email": "a@b.com" } })).await;
capture("user_42", "signup", serde_json::json!({ "plan": "pro" })).await;
StatusCode::CREATED
}§Settings keys
Read from UMBRAL_POSTHOG_API_KEY / UMBRAL_POSTHOG_HOST env vars or
umbral.toml extra keys posthog_api_key / posthog_host. Builder
overrides win over environment.
posthog_api_key/UMBRAL_POSTHOG_API_KEY. Your project API key. When absent the plugin is a no-op: captures are dropped with a one-time warning. Never panics, never blocks.posthog_host/UMBRAL_POSTHOG_HOST. Ingest host (defaulthttps://us.i.posthog.com).
§Surface
AnalyticsPlugin. The plugin; registers the ambient client at boot.capture. Fire-and-forget event capture (free function, ambient).identify. Fire-and-forget$identifyperson update (free function, ambient).AnalyticsClient. The typed PostHog client. Public so callers can build one directly for testing or send with an explicit client.
Structs§
- Analytics
Client - A configured PostHog client. Owns an API key + host; reuses the
process-wide
http_clientconnection pool. - Analytics
Plugin - The analytics plugin. Carries no models, no persistent routes — just an
AnalyticsClientit installs as the ambient handle at boot socapture/identifywork anywhere in the process.
Constants§
- DEFAULT_
POSTHOG_ HOST - Default PostHog ingest host (US region).
Functions§
- ambient_
client - Return the ambient client, or
Noneif the plugin isn’t registered / no API key was configured. - capture
- Fire-and-forget event capture. Sends
eventwithpropertiesattributed todistinct_idto PostHog. The HTTP send happens in a background task; this function returns immediately and analytics failures never affect the caller. - http_
client - Returns a clone of the process-wide shared HTTP client.
- identify
- Fire-and-forget person identification. Sends a PostHog
$identifyevent with person properties under$set. Use this to associate adistinct_idwith user properties (name, email, plan, etc.).