![Amplitude](https://camo.githubusercontent.com/48e6e09fe361c7f7b56fde889643ac151a3622c5ce510c4519511551044196a7/68747470733a2f2f7374617469632e616d706c69747564652e636f6d2f6c696768746e696e672f343663383562666439313930356465383034376631656536356337633933643666613965653665612f7374617469632f6d656469612f616d706c69747564652d6c6f676f2d776974682d746578742e34666239653436332e737667)
use amplitude::{Amp, Event};
use serde_json::json;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let amp = Amp::from_env()?; // api key as env variable must be provided
let mut event1 = Event::new();
event1
.user_id("some user id")
.event_type("some event type")
.country("UK")
.android_id("slmsung-unlimited-hash")
.ip4(Some(Ipv4Addr::new(127, 0, 0, 5)))
.time(chrono::Utc::now());
let event2 = Event::from_json(json!(
{
"user_id": "some user id",
"event_type": "lay on the beach",
"android_id": "3gfhtey534-647"
}
))?;
let response = amp.send(vec![event1, event2])?;
Ok(())
}
use amplitude::{Amp, Event};
use serde_json::json;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut amp = Amp::from_env()?; // api key as env variable must be provided
amp
.batch() // set batch url
.set_min_id_length(4);
let mut event = Event::new();
event
.device_id("xxxx")
.event_type("register");
#[derive(Serialize)]
struct UserProperties {
age: u8,
gender: String,
interests: Vec<String>,
}
let up = UserProperties {
age: 25,
gender: "female".to_string(),
interests: vec!["football".to_string(), "hockey".to_string()],
};
event.user_properties(up); // set user properties
// also instead of creating a struct, you may pass serde_json::Value
event.event_properties(json!({
"event_group": "children",
"foods": [
{
"apples": 5
}
]
}));
let response = amp.send(vec![event]).await?;
}