#analytics #meilisearch #client #message #user #github #server

segment

Segment 分析客户端,适用于 Rust。基于 Meilisearch 分支:https://github.com/meilisearch

8 个版本

0.2.4 2024 年 5 月 7 日
0.2.3 2023 年 10 月 25 日
0.2.2 2023 年 1 月 9 日
0.2.1 2022 年 9 月 26 日
0.1.1 2021 年 9 月 30 日

#635网页编程

Download history 7011/week @ 2024-05-04 8328/week @ 2024-05-11 8058/week @ 2024-05-18 6805/week @ 2024-05-25 8151/week @ 2024-06-01 7533/week @ 2024-06-08 7556/week @ 2024-06-15 8809/week @ 2024-06-22 7474/week @ 2024-06-29 8051/week @ 2024-07-06 7240/week @ 2024-07-13 7966/week @ 2024-07-20 7015/week @ 2024-07-27 8133/week @ 2024-08-03 7019/week @ 2024-08-10 5517/week @ 2024-08-17

28,997 每月下载

MIT 许可证

37KB
602 代码行

Segment

Test Status API

此包是 Meilisearch 使用的 Rust 非官方 Segment 分析客户端

示例用法(s)

use segment::{HttpClient, Client, AutoBatcher, Batcher};
use segment::message::{Track, User};
use serde_json::json;

#[tokio::main(flavor = "current_thread")]
async fn main() {
    let write_key = "YOUR_WRITE_KEY";

    let client = HttpClient::default();
    let batcher = Batcher::new(None);
    let mut batcher = AutoBatcher::new(client, batcher, write_key.to_string());

    // Pretend this is reading off of a queue, a file, or some other data
    // source.
    for i in 0..100 {
        let msg = 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.
        batcher.push(msg).await.unwrap();
    }

    batcher.flush().await.unwrap();
}

或当您想进行结构到结构的转换时

use segment::{HttpClient, Client};
use segment::message::{Track, Message, User};
use serde_json::json;

#[tokio::main(flavor = "current_thread")]
async fn main() {
    let write_key = "YOUR_WRITE_KEY";

    let client = HttpClient::default();
    client.send(write_key.to_string(), Message::from(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()
    })).await.expect("could not send to Segment");
}

许可证

根据 MIT 许可证 许可。

依赖关系

~4–18MB
~287K SLoC