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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
//! 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);
//!
//! // 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);
//! }
//!
//! 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(())
//! }
//! ```
//!
//! # Capture is fire-and-forget
//!
//! [`Client::capture`] and [`Client::capture_batch`] are the primary API: they
//! hand the event to a background worker that batches, sends, and retries it,
//! and return immediately. Delivery failures are not surfaced to the caller —
//! register [`ClientOptionsBuilder::on_error`] to observe them. This is the
//! right choice for essentially all analytics.
//!
//! ## Immediate delivery (advanced)
//!
//! [`Client::capture_immediate`] and [`Client::capture_batch_immediate`] send
//! inline and return a [`CaptureSummary`] once the request reaches a terminal
//! outcome (or an [`Error`] if the retry budget is spent). They bypass the
//! background worker and do not fire `on_error` — the returned value is the
//! signal. Reach for them only when the caller must know a batch persisted
//! before advancing its own durable state (for example, a server-side importer
//! committing an upstream offset); prefer fire-and-forget everywhere else.
// Public interface - any change to this is breaking!
// Client
pub use client;
pub use BeforeSendHook;
pub use CaptureCompression;
pub use CaptureSummary;
pub use Client;
pub use ClientOptions;
pub use ClientOptionsBuilder;
pub use ClientOptionsBuilderError;
pub use ;
// Endpoints
pub use ;
// Error
pub use Error;
// Error Tracking
pub use ;
// Event
pub use Event;
// V1 Capture types
pub use ;
// Feature Flags
pub use ;
pub use ;
// Local Evaluation
pub use ;
pub use AsyncFlagPoller;
// We expose global convenience functions (capture/flush/shutdown) that use a
// global client. flush/shutdown matter because the global singleton lives in a
// `static`, whose `Drop` never runs — they must be called to drain on exit.
pub use capture;
pub use capture_exception;
pub use capture_exception_with;
pub use disable as disable_global;
pub use flush;
pub use init_global_client as init_global;
pub use is_disabled as global_is_disabled;
pub use shutdown;