pub struct Event { /* private fields */ }Expand description
An Event represents an interaction a user has with your app or
website. Examples include button clicks, pageviews, query completions, and signups.
See the PostHog documentation
for a detailed explanation of PostHog Events.
Implementations§
Source§impl Event
impl Event
Sourcepub fn new<S: Into<String>>(event: S, distinct_id: S) -> Self
pub fn new<S: Into<String>>(event: S, distinct_id: S) -> Self
Create a new identified Event. Unless you have a distinct ID you can
associate with a user, you probably want to use Event::new_anon
instead.
§Parameters
event: Event name, such as"user_signed_up".distinct_id: Stable user or account identifier. For backend events, use the same distinct ID your frontend passes toposthog.identify().
Sourcepub fn new_anon<S: Into<String>>(event: S) -> Self
pub fn new_anon<S: Into<String>>(event: S) -> Self
Create a new anonymous event.
See https://posthog.com/docs/data/anonymous-vs-identified-events#how-to-capture-anonymous-events.
§Parameters
event: Event name.
§Remarks
Generates a random distinct ID and sets $process_person_profile to
false so PostHog does not create a person profile for the event.
Sourcepub fn insert_prop<K: Into<String>, P: Serialize>(
&mut self,
key: K,
prop: P,
) -> Result<(), Error>
pub fn insert_prop<K: Into<String>, P: Serialize>( &mut self, key: K, prop: P, ) -> Result<(), Error>
Add a property to the event.
§Parameters
key: Property name.prop: Any value that can be serialized to JSON.
§Errors
Returns Error::Serialization if prop cannot be serialized.
Sourcepub fn remove_prop(&mut self, key: &str) -> Option<Value>
pub fn remove_prop(&mut self, key: &str) -> Option<Value>
Remove a property from the event and return its previous value, if any.
Sourcepub fn add_group(&mut self, group_name: &str, group_id: &str)
pub fn add_group(&mut self, group_name: &str, group_id: &str)
Capture this as a group event.
See https://posthog.com/docs/product-analytics/group-analytics#how-to-capture-group-events.
§Parameters
group_name: Group type, such as"company".group_id: Stable identifier for the group.
§Remarks
Group events cannot be personless, and will be automatically upgraded to include person profile processing if they were anonymous. This might lead to “empty” person profiles being created.
Sourcepub fn set_timestamp<Tz>(
&mut self,
timestamp: DateTime<Tz>,
) -> Result<(), Error>where
Tz: TimeZone,
pub fn set_timestamp<Tz>(
&mut self,
timestamp: DateTime<Tz>,
) -> Result<(), Error>where
Tz: TimeZone,
Set the event timestamp, for events that happened in the past.
§Parameters
timestamp: Timestamp to send with the event. It is converted to UTC before serialization.
§Errors
Returns Error::InvalidTimestamp if the timestamp is in the future.
Sourcepub fn set_uuid(&mut self, uuid: Uuid)
pub fn set_uuid(&mut self, uuid: Uuid)
Override the auto-generated UUID for this event.
Useful for deduplication when re-importing historical data.
Sourcepub fn with_flags(&mut self, flags: &FeatureFlagEvaluations) -> &mut Self
pub fn with_flags(&mut self, flags: &FeatureFlagEvaluations) -> &mut Self
Attach the flag state captured by a FeatureFlagEvaluations snapshot
to this event.
Adds $feature/<key> for every evaluated flag plus a sorted
$active_feature_flags list of enabled keys, mirroring what
send_feature_flags would otherwise fetch — but without making an
extra /flags request.
§Returns
Returns self so calls can be chained before capture.
Sourcepub fn event_name(&self) -> &str
pub fn event_name(&self) -> &str
Return the event name.
Sourcepub fn distinct_id(&self) -> &str
pub fn distinct_id(&self) -> &str
Return the event distinct ID.
Sourcepub fn properties(&self) -> &HashMap<String, Value>
pub fn properties(&self) -> &HashMap<String, Value>
Return the event properties.