umami-api 0.0.2

Easily interact with the Umami API (self-hosted instances)
Documentation
use serde::Deserialize;

use crate::{Timestamps, Umami, website_stats::get_stats::GetStatsRequestBuilder};

pub mod get_stats;

#[derive(Clone, Debug, Deserialize)]
pub struct Stats {
  /// Page hits
  pub pageviews: u64,
  /// Number of unique visitors
  pub visitors: u64,
  /// Number of unique visitors
  pub visits: u64,
  /// Number of visitors who only visit a single page
  pub bounces: u64,
  /// Time spent on the website
  pub totaltime: u64,
}

#[derive(Clone, Debug, Deserialize)]
pub struct StatsWithComparison {
  /// The Stats for a given time period
  #[serde(flatten)]
  pub base: Stats,
  /// The Stats for a time period which is of the same length as a given time period, and ends when that given time period begins
  pub comparison: Stats,
}

impl Umami {
  // Gets summarized website statistics: <https://umami.is/docs/api/website-stats#get-apiwebsiteswebsiteidstats>
  pub fn get_stats(
    &'_ self,
    website_id: impl Into<String>,
    timestamps: Timestamps,
  ) -> GetStatsRequestBuilder<'_> {
    GetStatsRequestBuilder::new(self, website_id.into(), timestamps)
  }
}