use std::collections::HashMap;
use thinkingdata_core::consumer::LogConsumer;
use thinkingdata_core::{TDAnalytics, TDError};
fn main() -> Result<(), TDError> {
let directory = std::env::temp_dir().join("thinkingdata-example-logs");
let consumer = LogConsumer::new(directory.to_str().expect("utf-8 temp dir"))?;
let ta = TDAnalytics::new(consumer)?;
let mut super_properties = HashMap::new();
super_properties.insert("channel".to_string(), "rust".into());
ta.set_super_properties(super_properties)?;
let mut properties = HashMap::new();
properties.insert("product_name".to_string(), "Rust SDK".into());
properties.insert("price".to_string(), 99.0.into());
ta.track("account_id_123", "purchase", properties)?;
ta.user_set(
"account_id_123",
serde_json::json!({ "level": 10, "vip": true }),
)?;
ta.track_first(
"account_id_123",
"register",
"account_id_123",
serde_json::json!({ "signup_channel": "cli" }),
)?;
ta.flush()?;
ta.close()?;
println!("events written to {}", directory.display());
Ok(())
}