#message #segment #user #track #client-send #batcher

bin+lib analytics

Segment分析客户端,适用于Rust https://segment.com/docs/libraries/rust

2个不稳定版本

0.2.0 2019年6月28日
0.1.0 2019年6月24日

#419 in HTTP客户端

Download history 72/week @ 2024-04-14 69/week @ 2024-04-21 102/week @ 2024-04-28 54/week @ 2024-05-05 9/week @ 2024-05-12 27/week @ 2024-05-19 29/week @ 2024-05-26 43/week @ 2024-06-02 33/week @ 2024-06-09 73/week @ 2024-06-16 67/week @ 2024-06-23 18/week @ 2024-06-30 79/week @ 2024-07-07 73/week @ 2024-07-14 58/week @ 2024-07-21 79/week @ 2024-07-28

每月290次下载

MIT许可证

33KB
508 代码行

Analytics Rust − 构建状态 最新版本

Analytics Rust是Rust语言的Segment分析客户端。有关更多信息,请访问https://segment.com/docs/sources/#server


[dependencies]
analytics = "0.1"

示例用法

use analytics::http::HttpClient;
use analytics::client::Client;
use analytics::message::{BatchMessage, Track, User};
use analytics::batcher::Batcher;
use serde_json::json;

fn main() {
    let write_key = "YOUR_WRITE_KEY";

    let client = HttpClient::default();
    let mut batcher = Batcher::new(None);

    // Pretend this is reading off of a queue, a file, or some other data
    // source.
    for i in 0..100 {
        let msg = BatchMessage::Track(Track {
            user: User::UserId { user_id: format!("user-{}", i) },
            event: "Example Event".to_owned(),
            properties: json!({
                "foo": format!("bar-{}", i),
            }),
            ..Default::default()
        });

        // An error here indicates a message is too large. In real life, you
        // would probably want to put this message in a deadletter queue or some
        // equivalent.
        if let Some(msg) = batcher.push(msg).unwrap() {
            client.send(write_key, &batcher.into_message()).unwrap();

            batcher = Batcher::new(None);
            batcher.push(msg).unwrap(); // Same error condition as above.
        }
    }
}

或者当你想要进行结构到结构的转换时

use analytics::http::HttpClient;
use analytics::client::Client;
use analytics::message::{Track, Message, User};
use serde_json::json;

fn main() {
    let write_key = "YOUR_WRITE_KEY";

    let client = HttpClient::default();
    client.send(write_key, &Message::Track(Track {
        user: User::UserId { user_id: "some_user_id".to_owned() },
        event: "Example Event".to_owned(),
        properties: json!({
            "some property": "some value",
            "some other property": "some other value",
        }),
        ..Default::default()
    })).expect("could not send to Segment");
}

许可证

许可协议 MIT

依赖关系

~21MB
~446K SLoC