matomo-rs 0.1.0

Async client for the Matomo Reporting API, focused on data export and migration
Documentation
use serde::Deserialize;
use serde_with::{serde_as, DisplayFromStr, PickFirst};

/// A node in `Actions.getPageUrls` / `Actions.getPageTitles`. These are
/// recursive trees: a node may carry an inline `subtable` (when Matomo is
/// queried with `flat=0` and expanded) or just an `idsubdatatable` pointer to
/// fetch the children separately.
#[serde_as]
#[derive(Debug, Clone, Deserialize)]
pub struct ActionPage {
    pub label: String,
    #[serde(default)]
    pub nb_visits: i64,
    #[serde(default)]
    pub nb_hits: i64,
    #[serde(default)]
    pub sum_time_spent: i64,
    #[serde(default)]
    pub entry_nb_visits: i64,
    #[serde(default)]
    pub entry_nb_actions: i64,
    #[serde(default)]
    pub exit_nb_visits: i64,
    #[serde_as(as = "Option<PickFirst<(_, DisplayFromStr)>>")]
    #[serde(default)]
    pub avg_time_on_page: Option<f64>,
    #[serde(default)]
    pub bounce_rate: Option<String>,
    #[serde(default)]
    pub exit_rate: Option<String>,
    /// Present only on leaf URL nodes.
    #[serde(default)]
    pub url: Option<String>,
    #[serde(default)]
    pub segment: Option<String>,
    /// Pointer to fetch this node's children in a follow-up call.
    #[serde(default)]
    pub idsubdatatable: Option<i64>,
    /// Inline children when the tree was expanded server-side.
    #[serde(default)]
    pub subtable: Option<Vec<ActionPage>>,
}

/// `Actions.getDownloads` row.
#[derive(Debug, Clone, Deserialize)]
pub struct Download {
    pub label: String,
    #[serde(default)]
    pub nb_visits: i64,
    #[serde(default)]
    pub nb_hits: i64,
    #[serde(default)]
    pub sum_time_spent: i64,
    #[serde(default)]
    pub url: Option<String>,
    #[serde(default)]
    pub idsubdatatable: Option<i64>,
    #[serde(default)]
    pub subtable: Option<Vec<Download>>,
}

/// `Actions.getOutlinks` row.
#[derive(Debug, Clone, Deserialize)]
pub struct Outlink {
    pub label: String,
    #[serde(default)]
    pub nb_visits: i64,
    #[serde(default)]
    pub nb_hits: i64,
    #[serde(default)]
    pub sum_time_spent: i64,
    #[serde(default)]
    pub url: Option<String>,
    #[serde(default)]
    pub idsubdatatable: Option<i64>,
    #[serde(default)]
    pub subtable: Option<Vec<Outlink>>,
}