plausible_rs/lib.rs
1//! A Rust library for the [Plausible Analytics API](https://plausible.io/docs/events-api).
2//!
3//! ## Example
4//!
5//! Record a `pageview` event!
6//!
7//! `PLAUSIBLE_DOMAIN=<domain> cargo run --example event_inline`
8//!
9//! ```rust no_run
10//! use plausible_rs::{EventHeaders, EventPayload, Plausible, PropValue, PAGEVIEW_EVENT};
11//! use std::collections::HashMap;
12//! use std::env;
13//!
14//! #[tokio::main]
15//! async fn main() {
16//! let domain: String = env::var("PLAUSIBLE_DOMAIN")
17//! .expect("set env var `PLAUSIBLE_DOMAIN` to name of site in Plausible");
18//!
19//! Plausible::new().event(
20//! EventHeaders::new(
21//! 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"),
22//! String::from("127.0.0.1")
23//! ),
24//! EventPayload::builder(
25//! domain.clone(),
26//! PAGEVIEW_EVENT.to_string(),
27//! format!("https://{}/test", domain)
28//! )
29//! .referrer(String::from("https://www.toddgriffin.me/"))
30//! .screen_width(2560)
31//! .props(HashMap::from([(
32//! String::from("author"),
33//! PropValue::from(String::from("Todd Everett Griffin")),
34//! )]))
35//! .build()
36//! ).await.unwrap();
37//! }
38//! ```
39//!
40//! For more examples, check out the `examples` directory within the repository.
41
42mod api;
43mod error;
44mod plausible_analytics;
45
46pub use api::*;
47pub use error::*;
48pub use plausible_analytics::*;