Expand description
An ergonomic Rust SDK for PostHog.
This crate offloads network I/O to a background thread, ensuring the main application remains non-blocking and error-free.
§Quick Start
use better_posthog::{events, Event};
// Initialize the client.
let _guard = better_posthog::init(better_posthog::ClientOptions {
api_key: Some("phc_your_api_key".into()),
..Default::default()
});
// Capture events.
events::capture(Event::new("page_view", "user_123"));
// Or use the builder pattern for events.
events::capture(
Event::builder()
.event("button_click")
.distinct_id("user_123")
.property("button_id", "submit")
.build()
);
// Batch multiple events.
events::batch(vec![
Event::new("event_1", "user_123"),
Event::new("event_2", "user_123"),
]);
// Guard is dropped here, triggering graceful shutdown.Re-exports§
pub use events::Event;pub use events::EventBuilder;
Modules§
- events
- Public API for capturing PostHog events.
Structs§
- ApiKey
- PostHog API key newtype.
- Client
Guard - Guard that manages the PostHog client lifecycle.
- Client
Options - Configuration for the PostHog client.
Enums§
- Host
- Target PostHog environment for event submission.
Functions§
- flush
- Flushes pending events, waiting up to the specified timeout.
- init
- Initializes the PostHog client with the given configuration.
Type Aliases§
- Before
Send Fn - Hook that can modify or discard events before sending.