Warning: This crate is still under development and is not recommended for production use yet.
Installation
Install the posthog-rs
crate by adding it to your Cargo.toml
.
[dependencies]posthog-rs = "0.2.0"
Usage
To setup the client, all you need to do is pass your PostHog project key.
let client = posthog_rs::client(env!("POSTHOG_API_KEY"));
Note: Currently, there is no way to customize the host that events are sent to, and we default to
app.posthog.com
Capturing events
Currently, the only functionality this library supports is sending events, which can be done using the capture
and cature_batch
methods.
let mut event = Event::new("<event_name>", "<distinct_id>");event.insert_prop("key1", "value1").unwrap();event.insert_prop("key2", vec!["a", "b"]).unwrap();client.capture(event).unwrap();
let event1 = posthog_rs::Event::new("event 1", "1234");let event2 = posthog_rs::Event::new("event 2", "1234");client.capture_batch(vec![event1, event2]).unwrap();