better_posthog
An ergonomic Rust SDK for PostHog.
Features
- Configurable API client.
- Non-blocking and error-free event capture with background worker thread.
- Builder pattern for flexible event construction.
- Automatic OS and library metadata enrichment.
- Support for events editing, filtering, and sampling via the
before_send option.
- Graceful shutdown with configurable timeout.
Usage
use better_posthog::{events, Event};
fn main() {
let _guard = better_posthog::init(better_posthog::ClientOptions {
api_key: Some("phc_your_api_key".into()),
..Default::default()
});
events::capture(Event::new("page_view", "user_123"));
events::capture(
Event::builder()
.event("button_click")
.distinct_id("user_123")
.property("button_id", "submit")
.build()
);
events::batch(vec![
Event::new("event_1", "user_123"),
Event::new("event_2", "user_123"),
]);
}
Configuration
let _guard = better_posthog::init(better_posthog::ClientOptions {
api_key: Some("phc_your_api_key".into()),
host: better_posthog::Host::EU, before_send: vec![], shutdown_timeout: std::time::Duration::from_secs(5),
});
License
MIT