quickstart/quickstart.rs
1// Copyright 2026 houseme
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Facade quick start: the same program as the core `log_basic` example, but
16//! depending on the `thinkingdata` facade crate.
17//!
18//! ```text
19//! cargo run -p thinkingdata --example quickstart
20//! ```
21
22use thinkingdata::TDAnalytics;
23use thinkingdata::TDError;
24use thinkingdata::consumer::LogConsumer;
25
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}