event/
event.rs

1use plausible_rs::{EventHeaders, EventPayload, PAGEVIEW_EVENT, Plausible, PropValue};
2use std::collections::HashMap;
3use std::env;
4
5#[tokio::main]
6async fn main() {
7    let domain: String = env::var("PLAUSIBLE_DOMAIN")
8        .expect("set env var `PLAUSIBLE_DOMAIN` to name of site in Plausible");
9
10    Plausible::new().event(
11        EventHeaders::new(
12            String::from("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36"),
13            String::from("127.0.0.1")
14        ),
15        EventPayload::builder(
16            domain.clone(),
17            PAGEVIEW_EVENT.to_string(),
18            format!("https://{domain}/test"))
19            .referrer(String::from("https://www.toddgriffin.me/"))
20            .screen_width(2560)
21            .props(HashMap::from([(
22                String::from("author"),
23                PropValue::from(String::from("Todd Everett Griffin")),
24            )]))
25            .build()
26        ).await.unwrap();
27}