1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//! Official Rust SDK for PostHog.
//!
//! Use [`client`] to construct a [`Client`], [`Event`] to capture analytics
//! events, and [`Client::evaluate_flags`] with [`EvaluateFlagsOptions`] for
//! feature flag evaluation.
//!
//! See the [PostHog Rust SDK documentation](https://posthog.com/docs/libraries/rust)
//! for installation, configuration, and more examples.
//!
//! # Getting started
//!
//! Add `posthog-rs` to your `Cargo.toml`, then initialize a client with your
//! project API key.
//!
//! ```no_run
//! use posthog_rs::{client, EvaluateFlagsOptions, Event};
//!
//! #[cfg(feature = "async-client")]
//! #[tokio::main]
//! async fn main() -> Result<(), posthog_rs::Error> {
//! let api_key = std::env::var("POSTHOG_API_KEY")
//! .expect("set POSTHOG_API_KEY to your PostHog project API key");
//!
//! let posthog = client(api_key.as_str()).await;
//! let distinct_id = "user-123";
//!
//! // Capture an analytics event.
//! let mut event = Event::new("signed_up", distinct_id);
//! event.insert_prop("plan", "pro")?;
//! posthog.capture(event).await?;
//!
//! // Evaluate feature flags once, then read from the snapshot.
//! let flags = posthog
//! .evaluate_flags(distinct_id, EvaluateFlagsOptions::default())
//! .await?;
//!
//! if flags.is_enabled("new-onboarding") {
//! let mut event = Event::new("onboarding_step_completed", distinct_id);
//! event.with_flags(&flags.only_accessed());
//! posthog.capture(event).await?;
//! }
//!
//! Ok(())
//! }
//!
//! #[cfg(not(feature = "async-client"))]
//! fn main() -> Result<(), posthog_rs::Error> {
//! let api_key = std::env::var("POSTHOG_API_KEY")
//! .expect("set POSTHOG_API_KEY to your PostHog project API key");
//!
//! let posthog = client(api_key.as_str());
//! let distinct_id = "user-123";
//!
//! // Capture an analytics event.
//! let mut event = Event::new("signed_up", distinct_id);
//! event.insert_prop("plan", "pro")?;
//! posthog.capture(event)?;
//!
//! // Evaluate feature flags once, then read from the snapshot.
//! let flags = posthog.evaluate_flags(distinct_id, EvaluateFlagsOptions::default())?;
//!
//! if flags.is_enabled("new-onboarding") {
//! let mut event = Event::new("onboarding_step_completed", distinct_id);
//! event.with_flags(&flags.only_accessed());
//! posthog.capture(event)?;
//! }
//!
//! Ok(())
//! }
//! ```
// Public interface - any change to this is breaking!
// Client
pub use client;
pub use CaptureCompression;
pub use Client;
pub use ClientOptions;
pub use ClientOptionsBuilder;
pub use ClientOptionsBuilderError;
// Endpoints
pub use ;
// Error
pub use Error;
// Event
pub use Event;
pub use EventOptions;
// V1 Capture types
pub use ;
// Feature Flags
pub use ;
pub use ;
// Local Evaluation
pub use ;
pub use AsyncFlagPoller;
// We expose a global capture function as a convenience, that uses a global client
pub use capture;
pub use disable as disable_global;
pub use init_global_client as init_global;
pub use is_disabled as global_is_disabled;