pub struct TDAnalytics { /* private fields */ }Expand description
The blocking analytics facade. Available with the blocking feature.
The blocking analytics facade. Available with the blocking feature.
The blocking analytics facade of the SDK, ported from the Go SDK’s
TDAnalytics.
It is cheap to clone; every clone shares the same consumer and super property state. See the crate documentation for a quick start.
Implementations§
Source§impl TDAnalytics
impl TDAnalytics
Sourcepub fn new(consumer: impl Consumer + 'static) -> Result<TDAnalytics, TDError>
pub fn new(consumer: impl Consumer + 'static) -> Result<TDAnalytics, TDError>
Create an analytics instance delegating delivery to consumer.
Examples found in repository?
26fn main() -> Result<(), TDError> {
27 let directory = std::env::temp_dir().join("thinkingdata-facade-quickstart");
28 let consumer = LogConsumer::new(directory.to_str().expect("utf-8 temp dir"))?;
29 let ta = TDAnalytics::new(consumer)?;
30
31 ta.set_super_properties(serde_json::json!({ "channel": "rust" }))?;
32 ta.track(
33 "account_id_123",
34 "purchase",
35 serde_json::json!({ "product_name": "Rust SDK", "price": 99.0 }),
36 )?;
37
38 ta.close()?;
39 println!("events written to {}", directory.display());
40 Ok(())
41}Sourcepub fn set_super_properties(
&self,
properties: impl IntoPropertyMap,
) -> Result<(), TDError>
pub fn set_super_properties( &self, properties: impl IntoPropertyMap, ) -> Result<(), TDError>
Set common properties applied to every subsequent track* event.
Keys are validated against the key pattern; an invalid key returns an error instead of silently corrupting the stream.
Examples found in repository?
26fn main() -> Result<(), TDError> {
27 let directory = std::env::temp_dir().join("thinkingdata-facade-quickstart");
28 let consumer = LogConsumer::new(directory.to_str().expect("utf-8 temp dir"))?;
29 let ta = TDAnalytics::new(consumer)?;
30
31 ta.set_super_properties(serde_json::json!({ "channel": "rust" }))?;
32 ta.track(
33 "account_id_123",
34 "purchase",
35 serde_json::json!({ "product_name": "Rust SDK", "price": 99.0 }),
36 )?;
37
38 ta.close()?;
39 println!("events written to {}", directory.display());
40 Ok(())
41}Sourcepub fn super_properties(&self) -> Map<String, Value>
pub fn super_properties(&self) -> Map<String, Value>
Snapshot of the currently registered super properties.
Sourcepub fn clear_super_properties(&self)
pub fn clear_super_properties(&self)
Remove every registered super property.
Sourcepub fn set_dynamic_super_properties<F, P>(&self, action: F)
pub fn set_dynamic_super_properties<F, P>(&self, action: F)
Register a callback producing dynamic common properties. It is evaluated once per event, outside of any lock; avoid heavy work in it.
Sourcepub fn dynamic_super_properties(&self) -> Map<String, Value>
pub fn dynamic_super_properties(&self) -> Map<String, Value>
Snapshot of the dynamic super properties.
Sourcepub fn track(
&self,
account_id: &str,
event_name: &str,
properties: impl IntoPropertyMap,
) -> Result<(), TDError>
pub fn track( &self, account_id: &str, event_name: &str, properties: impl IntoPropertyMap, ) -> Result<(), TDError>
Report an ordinary event attributed to account_id.
Examples found in repository?
26fn main() -> Result<(), TDError> {
27 let directory = std::env::temp_dir().join("thinkingdata-facade-quickstart");
28 let consumer = LogConsumer::new(directory.to_str().expect("utf-8 temp dir"))?;
29 let ta = TDAnalytics::new(consumer)?;
30
31 ta.set_super_properties(serde_json::json!({ "channel": "rust" }))?;
32 ta.track(
33 "account_id_123",
34 "purchase",
35 serde_json::json!({ "product_name": "Rust SDK", "price": 99.0 }),
36 )?;
37
38 ta.close()?;
39 println!("events written to {}", directory.display());
40 Ok(())
41}Sourcepub fn track_with_distinct_id(
&self,
account_id: &str,
distinct_id: &str,
event_name: &str,
properties: impl IntoPropertyMap,
) -> Result<(), TDError>
pub fn track_with_distinct_id( &self, account_id: &str, distinct_id: &str, event_name: &str, properties: impl IntoPropertyMap, ) -> Result<(), TDError>
Report an ordinary event with explicit account and distinct IDs.
Sourcepub fn track_first(
&self,
account_id: &str,
event_name: &str,
first_check_id: &str,
properties: impl IntoPropertyMap,
) -> Result<(), TDError>
pub fn track_first( &self, account_id: &str, event_name: &str, first_check_id: &str, properties: impl IntoPropertyMap, ) -> Result<(), TDError>
Report a first-check event; first_check_id deduplicates it.
Sourcepub fn track_first_with_distinct_id(
&self,
account_id: &str,
distinct_id: &str,
event_name: &str,
first_check_id: &str,
properties: impl IntoPropertyMap,
) -> Result<(), TDError>
pub fn track_first_with_distinct_id( &self, account_id: &str, distinct_id: &str, event_name: &str, first_check_id: &str, properties: impl IntoPropertyMap, ) -> Result<(), TDError>
Report a first-check event with explicit account and distinct IDs.
Sourcepub fn track_update(
&self,
account_id: &str,
event_name: &str,
event_id: &str,
properties: impl IntoPropertyMap,
) -> Result<(), TDError>
pub fn track_update( &self, account_id: &str, event_name: &str, event_id: &str, properties: impl IntoPropertyMap, ) -> Result<(), TDError>
Report an updatable event identified by event_id.
Sourcepub fn track_update_with_distinct_id(
&self,
account_id: &str,
distinct_id: &str,
event_name: &str,
event_id: &str,
properties: impl IntoPropertyMap,
) -> Result<(), TDError>
pub fn track_update_with_distinct_id( &self, account_id: &str, distinct_id: &str, event_name: &str, event_id: &str, properties: impl IntoPropertyMap, ) -> Result<(), TDError>
Report an updatable event with explicit account and distinct IDs.
Sourcepub fn track_overwrite(
&self,
account_id: &str,
event_name: &str,
event_id: &str,
properties: impl IntoPropertyMap,
) -> Result<(), TDError>
pub fn track_overwrite( &self, account_id: &str, event_name: &str, event_id: &str, properties: impl IntoPropertyMap, ) -> Result<(), TDError>
Report an overridable event identified by event_id.
Sourcepub fn track_overwrite_with_distinct_id(
&self,
account_id: &str,
distinct_id: &str,
event_name: &str,
event_id: &str,
properties: impl IntoPropertyMap,
) -> Result<(), TDError>
pub fn track_overwrite_with_distinct_id( &self, account_id: &str, distinct_id: &str, event_name: &str, event_id: &str, properties: impl IntoPropertyMap, ) -> Result<(), TDError>
Report an overridable event with explicit account and distinct IDs.
Sourcepub fn user_set(
&self,
account_id: &str,
properties: impl IntoPropertyMap,
) -> Result<(), TDError>
pub fn user_set( &self, account_id: &str, properties: impl IntoPropertyMap, ) -> Result<(), TDError>
Set user properties, overwriting existing values.
Sourcepub fn user_set_with_distinct_id(
&self,
account_id: &str,
distinct_id: &str,
properties: impl IntoPropertyMap,
) -> Result<(), TDError>
pub fn user_set_with_distinct_id( &self, account_id: &str, distinct_id: &str, properties: impl IntoPropertyMap, ) -> Result<(), TDError>
Set user properties with explicit account and distinct IDs.
Sourcepub fn user_set_once(
&self,
account_id: &str,
properties: impl IntoPropertyMap,
) -> Result<(), TDError>
pub fn user_set_once( &self, account_id: &str, properties: impl IntoPropertyMap, ) -> Result<(), TDError>
Set user properties only where they were not set before.
Sourcepub fn user_set_once_with_distinct_id(
&self,
account_id: &str,
distinct_id: &str,
properties: impl IntoPropertyMap,
) -> Result<(), TDError>
pub fn user_set_once_with_distinct_id( &self, account_id: &str, distinct_id: &str, properties: impl IntoPropertyMap, ) -> Result<(), TDError>
user_set_once with explicit account and distinct IDs.
Sourcepub fn user_add(
&self,
account_id: &str,
properties: impl IntoPropertyMap,
) -> Result<(), TDError>
pub fn user_add( &self, account_id: &str, properties: impl IntoPropertyMap, ) -> Result<(), TDError>
Accumulate numeric user properties.
Sourcepub fn user_add_with_distinct_id(
&self,
account_id: &str,
distinct_id: &str,
properties: impl IntoPropertyMap,
) -> Result<(), TDError>
pub fn user_add_with_distinct_id( &self, account_id: &str, distinct_id: &str, properties: impl IntoPropertyMap, ) -> Result<(), TDError>
user_add with explicit account and distinct IDs.
Sourcepub fn user_append(
&self,
account_id: &str,
properties: impl IntoPropertyMap,
) -> Result<(), TDError>
pub fn user_append( &self, account_id: &str, properties: impl IntoPropertyMap, ) -> Result<(), TDError>
Append values to array-typed user properties.
Sourcepub fn user_append_with_distinct_id(
&self,
account_id: &str,
distinct_id: &str,
properties: impl IntoPropertyMap,
) -> Result<(), TDError>
pub fn user_append_with_distinct_id( &self, account_id: &str, distinct_id: &str, properties: impl IntoPropertyMap, ) -> Result<(), TDError>
user_append with explicit account and distinct IDs.
Sourcepub fn user_uniq_append(
&self,
account_id: &str,
properties: impl IntoPropertyMap,
) -> Result<(), TDError>
pub fn user_uniq_append( &self, account_id: &str, properties: impl IntoPropertyMap, ) -> Result<(), TDError>
Append unique values to array-typed user properties.
Sourcepub fn user_uniq_append_with_distinct_id(
&self,
account_id: &str,
distinct_id: &str,
properties: impl IntoPropertyMap,
) -> Result<(), TDError>
pub fn user_uniq_append_with_distinct_id( &self, account_id: &str, distinct_id: &str, properties: impl IntoPropertyMap, ) -> Result<(), TDError>
user_uniq_append with explicit account and distinct IDs.
Sourcepub fn user_unset<S>(&self, account_id: &str, keys: &[S]) -> Result<(), TDError>
pub fn user_unset<S>(&self, account_id: &str, keys: &[S]) -> Result<(), TDError>
Clear the listed user properties.
Sourcepub fn user_unset_with_distinct_id<S>(
&self,
account_id: &str,
distinct_id: &str,
keys: &[S],
) -> Result<(), TDError>
pub fn user_unset_with_distinct_id<S>( &self, account_id: &str, distinct_id: &str, keys: &[S], ) -> Result<(), TDError>
Clear the listed user properties with explicit account and distinct IDs.
Sourcepub fn user_unset_with_properties(
&self,
account_id: &str,
properties: impl IntoPropertyMap,
) -> Result<(), TDError>
pub fn user_unset_with_properties( &self, account_id: &str, properties: impl IntoPropertyMap, ) -> Result<(), TDError>
Clear user properties using a property map (values are ignored by the receiver, but preset keys keep their values, matching the Lua SDK).
Sourcepub fn user_unset_with_properties_with_distinct_id(
&self,
account_id: &str,
distinct_id: &str,
properties: impl IntoPropertyMap,
) -> Result<(), TDError>
pub fn user_unset_with_properties_with_distinct_id( &self, account_id: &str, distinct_id: &str, properties: impl IntoPropertyMap, ) -> Result<(), TDError>
user_unset_with_properties with explicit account and distinct IDs.
Sourcepub fn user_del(&self, account_id: &str) -> Result<(), TDError>
pub fn user_del(&self, account_id: &str) -> Result<(), TDError>
Delete the user; this operation cannot be undone.
Sourcepub fn user_del_with_distinct_id(
&self,
account_id: &str,
distinct_id: &str,
) -> Result<(), TDError>
pub fn user_del_with_distinct_id( &self, account_id: &str, distinct_id: &str, ) -> Result<(), TDError>
Delete the user with explicit account and distinct IDs.
Sourcepub fn user_del_with_properties(
&self,
account_id: &str,
properties: impl IntoPropertyMap,
) -> Result<(), TDError>
pub fn user_del_with_properties( &self, account_id: &str, properties: impl IntoPropertyMap, ) -> Result<(), TDError>
Delete the user together with final property values.
Sourcepub fn user_del_with_properties_with_distinct_id(
&self,
account_id: &str,
distinct_id: &str,
properties: impl IntoPropertyMap,
) -> Result<(), TDError>
pub fn user_del_with_properties_with_distinct_id( &self, account_id: &str, distinct_id: &str, properties: impl IntoPropertyMap, ) -> Result<(), TDError>
user_del_with_properties with explicit account and distinct IDs.
Sourcepub fn flush(&self) -> Result<(), TDError>
pub fn flush(&self) -> Result<(), TDError>
Deliver everything currently buffered by the consumer.
Sourcepub fn close(&self) -> Result<(), TDError>
pub fn close(&self) -> Result<(), TDError>
Flush and shut the consumer down.
Examples found in repository?
26fn main() -> Result<(), TDError> {
27 let directory = std::env::temp_dir().join("thinkingdata-facade-quickstart");
28 let consumer = LogConsumer::new(directory.to_str().expect("utf-8 temp dir"))?;
29 let ta = TDAnalytics::new(consumer)?;
30
31 ta.set_super_properties(serde_json::json!({ "channel": "rust" }))?;
32 ta.track(
33 "account_id_123",
34 "purchase",
35 serde_json::json!({ "product_name": "Rust SDK", "price": 99.0 }),
36 )?;
37
38 ta.close()?;
39 println!("events written to {}", directory.display());
40 Ok(())
41}Trait Implementations§
Source§impl Clone for TDAnalytics
impl Clone for TDAnalytics
Source§fn clone(&self) -> TDAnalytics
fn clone(&self) -> TDAnalytics
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more