segment_analytics

Crates.iosegment_analytics
lib.rssegment_analytics
version0.1.3
sourcesrc
created_at2016-06-28 18:46:12.819628
updated_at2017-10-15 14:08:53.324083
descriptionSegment Analytics (segment.com) client for rust ;)
homepagehttps://github.com/aagahi/rust-segment-analytics
repositoryhttps://github.com/aagahi/rust-segment-analytics
max_upload_size
id5521
size15,618
Alexis Agahi (aagahi)

documentation

https://github.com/aagahi/rust-segment-analytics

README

Rust Segment Analytics Client

Build Status Crates.io Coverage Status

Segment Analytics Client now available for rust ;)

Usage

Add this to your Cargo.toml:

[dependencies]
segment_analytics = "0.1.3"

and this to your crate root:

extern crate segment_analytics;

Examples

Usage with shared instance across thread.

extern crate segment_analytics;
use segment_analytics::Segment;

let segment = Arc::new(Segment::new(Some(SEGMENT_WRITE_KEY.to_string())));

let segment1 = segment.clone();
thread::spawn(move || {

  let mut properties = HashMap::new();
  properties.insert("firstname", "Jimmy");
  properties.insert("lastname", "Page");

  let mut context = HashMap::new();
  context.insert("ip", "134.157.15.3");

  segment1.track(Some("anonymous_id"),
                 None,
                 "EventName",
                 Some(properties),
                 Some(context))

  segment1.alias("anonymous_id", "user_id");

  let mut traits = HashMap::new();
  traits.insert("email", "bill@gates.com");
  let mut context = HashMap::new();
  context.insert("ip", "134.157.15.3");
  segment1.identify(None,Some("user_id"), None, Some(traits), Some(context));
});

Under the hood, one thread worker is in charge of sending the messages to segment endpoint. If the thread drops, a new one is created.

Traits, Properties and Context must implement ToJsonString (I'm not a fan of current json solutions in rust).

pub trait ToJsonString {
    fn to_json_string(&self) -> String;
}

For convenience ToJsonString is (basically) implemented for HashMap.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Commit count: 8

cargo fmt