Skip to main content

Crate matomo

Crate matomo 

Source
Expand description

HTTP client-agnostic Rust bindings for the Matomo Reporting API, focused on data export and migration.

The crate is split into a transport-agnostic core (Client, Endpoint, Query) and an optional reqwest-backed transport behind a feature flag. Bring your own HTTP client by implementing Client.

Matomo’s API is a single dispatch endpoint: every call is a POST {base}/index.php with a module=API&method=Module.action&format=json form body. Errors arrive as HTTP 200 with a {"result":"error",...} JSON envelope rather than via status codes, so Endpoint::parse_response detects that envelope instead of mapping status codes.

§Features

  • reqwest — enables crate::reqwest::MatomoClient, a ready-made Client. No TLS backend is selected by default; pair it with one below.
  • reqwest-rustlsreqwest with rustls.
  • reqwest-native-tlsreqwest with the OS-native TLS stack.
  • chrono / timeFrom conversions into Date.

All features are off by default. If none of the reqwest-* features fit, implement Client yourself against any HTTP backend.

Re-exports§

pub use reqwest::Cursor;
pub use reqwest::MatomoClient;
pub use reqwest::MatomoClientError;
pub use reqwest::VisitStream;

Modules§

endpoints
Endpoint impls for each typed Matomo call. These build a Params bag and name a Module.action; the blanket crate::Query turns them into a request. They carry no transport.
reqwest
reqwest-backed Client implementation and the ergonomic high-level API.

Structs§

ActionPage
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.
Download
Actions.getDownloads row.
GoalConversion
A goal conversion attached to a visit.
Outlink
Actions.getOutlinks row.
Params
A reusable, standalone bag of API call parameters.
ReferrerAll
Referrers.getAll row. Note Matomo’s misspelled referer_type field.
ReferrerType
Referrers.getReferrerType row. Note the field is referrer_type here.
Segment
A raw segment expression. Passed verbatim in the POST body; reqwest url-encodes it for us, so do not pre-encode.
Visit
A single visit from Live.getLastVisitsDetails.
VisitsSummary
VisitsSummary.get. Note the mixed numerics: bounce_rate is a string like "64%", nb_actions_per_visit is a float, the rest are ints.

Enums§

ActionDetail
An entry in actionDetails. Internally tagged on Matomo’s type field. action and download are typed precisely from harvested data; the others are modeled minimally; anything else falls through to Unknown for forward-compat. Never #[serde(untagged)].
ApiErrorKind
Best-effort classification of an API error, sniffed from the message text. This is a heuristic; Matomo does not return machine-readable error codes.
Auth
How the client authenticates against the Matomo instance.
Date
A Matomo date in its query grammar.
DateRange
A date range used with Period::Range. Matomo only accepts a single rolling keyword (lastN/previousN) or an absolute start paired with an absolute or today/yesterday end — a keyword start like last7,today is rejected, so it is unrepresentable here.
Error
IdSite
One or more site ids, or all sites.
Limit
filter_limit. All maps to -1.
ParseError
Outcome of Endpoint::parse_response, lifted into QueryError by the blanket Query impl.
Period
A period paired with the date(s) it applies to. Illegal (period, date) combinations are unrepresentable: Range carries its own DateRange, the others carry a single Date.
QueryError
Error returned by Query::execute, generic over the transport error.
RangeEnd
The end of an absolute-start range. Matomo accepts an absolute date or the today/yesterday keywords here, but not lastN-style keywords.
VisitorType

Traits§

Client
A transport capable of dispatching a single Matomo API request.
Endpoint
A single Matomo API endpoint: its Module.action method name, its form params, and how to decode the response.
Query
An asynchronous query against a Client.

Type Aliases§

Result