Rust

Last updated:

Which features are available in this library?
  • Event capture
  • Autocapture
  • User identification
  • Session recording
  • Feature flags
  • Group analytics

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.

Cargo.toml
[dependencies]
posthog-rs = "0.2.0"

Usage

To setup the client, all you need to do is pass your PostHog project key.

Rust
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.

Rust
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();
Rust
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();

Questions?

Was this page useful?

Next article

Integrate PostHog

Once your PostHog instance is up and running, the next step is to start sending events. Installation What to read next Learn how to take your PostHog integrations to the next level with these in-depth guides. Identifying users Adding properties to users Connecting PostHog with your CDP Deploying a reverse proxy Importing historical events

Read next article