# thinkingdata
[](https://crates.io/crates/thinkingdata)
[](https://docs.rs/thinkingdata)
[](https://github.com/houseme/thinkingdata/actions/workflows/ci.yml)
[](LICENSE)
[](#installation)
Rust SDK for [ThinkingData Analytics](https://www.thinkingdata.cn) β **API entry** (blocking & async)
plus the `thinkingdata` **CLI**. All functional logic lives in
[`thinkingdata-core`](https://crates.io/crates/thinkingdata-core); this crate re-exports it and adds
the command line client.
The workspace overview, relationship to the official Go SDK, and bilingual data-format guides live
in the [root README](https://github.com/houseme/thinkingdata#readme).
## Installation
```toml
[dependencies]
thinkingdata = { version = "0.2", features = ["blocking"] } # default
# thinkingdata = { version = "0.2", features = ["async"] } # async API
# thinkingdata = { version = "0.2", features = ["full"] } # both
```
## Quick start
### Blocking
```no_run
use thinkingdata::{TDAnalytics, consumer::LogConsumer};
# fn main() -> Result<(), thinkingdata::TDError> {
let consumer = LogConsumer::new("/path/to/log/directory")?;
let ta = TDAnalytics::new(consumer)?;
ta.track("account_id_123", "purchase", serde_json::json!({
"product_name": "Rust SDK",
"price": 99.0,
}))?;
ta.close()?;
# Ok(())
# }
```
### Async
```no_run
# #[cfg(feature = "async")]
# async fn demo() -> Result<(), thinkingdata::TDError> {
use thinkingdata::{TDAnalyticsAsync, consumer::BatchConsumer};
let consumer = BatchConsumer::new("https://receiver.thinkingdata.io", "your_app_id")?;
let ta = TDAnalyticsAsync::new(consumer)?;
ta.track("account_id_123", "purchase", serde_json::json!({ "price": 99.0 })).await?;
ta.close().await?;
# Ok(())
# }
```
## CLI
The same crate name doubles as the `thinkingdata` binary. Pick exactly one consumer:
`--log-dir`, `--server-url` (+ `--app-id`), or `--debug` (+ `--app-id`).
```bash
thinkingdata --log-dir /tmp/ta-logs track \
--account-id acc_1 --event-name purchase \
--properties '{"price": 9.9, "product_name": "book"}'
thinkingdata --server-url https://receiver.thinkingdata.io --app-id YOUR_APP_ID \
track --account-id acc_1 --event-name login
thinkingdata --server-url https://receiver.thinkingdata.io --app-id YOUR_APP_ID --debug \
user-set --account-id acc_1 --properties '{"vip": true}'
```
Commands: `track`, `track-first`, `track-update`, `track-overwrite`, `user-set`, `user-set-once`,
`user-add`, `user-append`, `user-uniq-append`, `user-unset`, `user-del`. Every command flushes and closes the
consumer before exiting, so buffered data is always delivered.
## Documentation
- [Workspace README](https://github.com/houseme/thinkingdata#readme) β full API tour and consumers
- [Data rules (EN / δΈζ)](https://github.com/houseme/thinkingdata/tree/main/docs)
- Official docs: <https://docs-v2.thinkingdata.cn/?code=data_format&lan=zh-CN&version=5.0>
## License
Apache-2.0