pub struct Client { /* private fields */ }Expand description
A Client facilitates interactions with the PostHog API over HTTP.
Implementations§
Source§impl Client
impl Client
Sourcepub async fn capture(&self, event: Event) -> Result<(), Error>
pub async fn capture(&self, event: Event) -> Result<(), Error>
Capture the provided event, sending it to PostHog.
Sourcepub async fn capture_batch(
&self,
events: Vec<Event>,
historical_migration: bool,
) -> Result<(), Error>
pub async fn capture_batch( &self, events: Vec<Event>, historical_migration: bool, ) -> Result<(), Error>
Capture a collection of events with a single request. Events are sent to
the /batch/ endpoint. Set historical_migration to true to route
events to the historical ingestion topic, bypassing the main pipeline.
Sourcepub async fn get_feature_flags<S: Into<String>>(
&self,
distinct_id: S,
groups: Option<HashMap<String, String>>,
person_properties: Option<HashMap<String, Value>>,
group_properties: Option<HashMap<String, HashMap<String, Value>>>,
) -> Result<(HashMap<String, FlagValue>, HashMap<String, Value>), Error>
pub async fn get_feature_flags<S: Into<String>>( &self, distinct_id: S, groups: Option<HashMap<String, String>>, person_properties: Option<HashMap<String, Value>>, group_properties: Option<HashMap<String, HashMap<String, Value>>>, ) -> Result<(HashMap<String, FlagValue>, HashMap<String, Value>), Error>
Get all feature flags for a user
Sourcepub async fn get_feature_flag<K: Into<String>, D: Into<String>>(
&self,
key: K,
distinct_id: D,
groups: Option<HashMap<String, String>>,
person_properties: Option<HashMap<String, Value>>,
group_properties: Option<HashMap<String, HashMap<String, Value>>>,
) -> Result<Option<FlagValue>, Error>
👎Deprecated since 0.6.0: Use Client::evaluate_flags() to fetch a snapshot, then call .get_flag(key) on it. The snapshot deduplicates $feature_flag_called events and supports attaching rich metadata to captured events via Event::with_flags().
pub async fn get_feature_flag<K: Into<String>, D: Into<String>>( &self, key: K, distinct_id: D, groups: Option<HashMap<String, String>>, person_properties: Option<HashMap<String, Value>>, group_properties: Option<HashMap<String, HashMap<String, Value>>>, ) -> Result<Option<FlagValue>, Error>
Use Client::evaluate_flags() to fetch a snapshot, then call .get_flag(key) on it. The snapshot deduplicates $feature_flag_called events and supports attaching rich metadata to captured events via Event::with_flags().
Get a specific feature flag value for a user.
Sourcepub async fn is_feature_enabled<K: Into<String>, D: Into<String>>(
&self,
key: K,
distinct_id: D,
groups: Option<HashMap<String, String>>,
person_properties: Option<HashMap<String, Value>>,
group_properties: Option<HashMap<String, HashMap<String, Value>>>,
) -> Result<bool, Error>
👎Deprecated since 0.6.0: Use Client::evaluate_flags() to fetch a snapshot, then call .is_enabled(key) on it. The snapshot deduplicates $feature_flag_called events and supports attaching rich metadata to captured events via Event::with_flags().
pub async fn is_feature_enabled<K: Into<String>, D: Into<String>>( &self, key: K, distinct_id: D, groups: Option<HashMap<String, String>>, person_properties: Option<HashMap<String, Value>>, group_properties: Option<HashMap<String, HashMap<String, Value>>>, ) -> Result<bool, Error>
Use Client::evaluate_flags() to fetch a snapshot, then call .is_enabled(key) on it. The snapshot deduplicates $feature_flag_called events and supports attaching rich metadata to captured events via Event::with_flags().
Check if a feature flag is enabled for a user.
Sourcepub async fn get_feature_flag_payload<K: Into<String>, D: Into<String>>(
&self,
key: K,
distinct_id: D,
) -> Result<Option<Value>, Error>
👎Deprecated since 0.6.0: Use Client::evaluate_flags() to fetch a snapshot, then call .get_flag_payload(key) on it. Reading the payload from a snapshot is event-free, matching this method’s behavior, and avoids the per-call /flags request.
pub async fn get_feature_flag_payload<K: Into<String>, D: Into<String>>( &self, key: K, distinct_id: D, ) -> Result<Option<Value>, Error>
Use Client::evaluate_flags() to fetch a snapshot, then call .get_flag_payload(key) on it. Reading the payload from a snapshot is event-free, matching this method’s behavior, and avoids the per-call /flags request.
Get a feature flag payload for a user.
Sourcepub fn evaluate_feature_flag_locally(
&self,
flag: &FeatureFlag,
distinct_id: &str,
person_properties: &HashMap<String, Value>,
groups: &HashMap<String, String>,
group_properties: &HashMap<String, HashMap<String, Value>>,
) -> Result<FlagValue, Error>
pub fn evaluate_feature_flag_locally( &self, flag: &FeatureFlag, distinct_id: &str, person_properties: &HashMap<String, Value>, groups: &HashMap<String, String>, group_properties: &HashMap<String, HashMap<String, Value>>, ) -> Result<FlagValue, Error>
Evaluate a feature flag locally (requires feature flags to be loaded).
groups and group_properties are only consulted when the flag (or one
of its conditions) targets a group; pass empty maps for person flags.
Sourcepub async fn evaluate_flags<S: Into<String>>(
&self,
distinct_id: S,
options: EvaluateFlagsOptions,
) -> Result<FeatureFlagEvaluations, Error>
pub async fn evaluate_flags<S: Into<String>>( &self, distinct_id: S, options: EvaluateFlagsOptions, ) -> Result<FeatureFlagEvaluations, Error>
Evaluate every feature flag for distinct_id in a single round-trip,
returning a FeatureFlagEvaluations snapshot.
Each is_enabled / get_flag call on the returned snapshot fires a
dedup-aware $feature_flag_called event with full metadata, and the
snapshot can be passed to Event::with_flags so a downstream
Client::capture inherits $feature/<key> and $active_feature_flags
without an extra /flags request.