#analytics #meilisearch #client #user #http-client #message #github

segment

Segment analytics client for Rust. Forked for Meilisearch: https://github.com/meilisearch

9 releases

0.2.5 Jan 8, 2025
0.2.4 May 7, 2024
0.2.3 Oct 25, 2023
0.2.2 Jan 9, 2023
0.1.1 Sep 30, 2021

#331 in Web programming

Download history 8380/week @ 2024-10-29 8130/week @ 2024-11-05 7468/week @ 2024-11-12 7007/week @ 2024-11-19 6389/week @ 2024-11-26 7027/week @ 2024-12-03 6501/week @ 2024-12-10 5905/week @ 2024-12-17 2834/week @ 2024-12-24 4401/week @ 2024-12-31 6975/week @ 2025-01-07 6741/week @ 2025-01-14 7925/week @ 2025-01-21 6622/week @ 2025-01-28 9442/week @ 2025-02-04 6571/week @ 2025-02-11

31,581 downloads per month

MIT license

38KB
602 lines

Segment

Test Status API

This crate is an unofficial segment analytics client for Rust used by Meilisearch

Example usage(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();
}

or when you want to do struct to struct transformations

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");
}

License

Licensed under MIT license.

Dependencies

~5–19MB
~285K SLoC

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy