teksilo_analytics_plausible/lib.rs
1// SPDX-License-Identifier: MPL-2.0
2// SPDX-FileCopyrightText: 2026 FernTech
3
4//! `teksilo-analytics-plausible` — Plausible adapter for teksilo-telemetry.
5//!
6//! Privacy posture: **anonymous-by-design**. The adapter transmits no
7//! client-side identifier, no UUID,
8//! no fingerprint. Plausible derives a per-day session hash
9//! server-side from `X-Forwarded-For` + `User-Agent` + a daily-
10//! rotating server-held salt; this scheme is on the CNIL
11//! consent-exempt audience-measurement list.
12//!
13//! ```ignore
14//! use teksilo_analytics_plausible::PlausibleAdapter;
15//! use teksilo_telemetry::{TelemetryBundle, TelemetryMode, UsageReporter};
16//! use std::rc::Rc;
17//!
18//! let plausible = PlausibleAdapter::builder()
19//! .endpoint("https://plausible.io/api/event")
20//! .domain("skribisto.app")
21//! .build();
22//!
23//! let telemetry = TelemetryBundle::new(EVENT_SCHEMA_VERSION)
24//! .with_anonymous(Rc::new(plausible) as Rc<dyn UsageReporter>)
25//! .with_default_mode(TelemetryMode::Anonymous);
26//! ```
27//!
28//! Adapter lifecycle:
29//!
30//! 1. `PlausibleAdapter::builder().build()` spawns a worker thread
31//! that owns the in-flight buffer and the HTTP client.
32//! 2. `record(event)` converts to `OwnedEvent` and sends through
33//! a channel to the worker. Non-blocking — the UI thread never
34//! waits on HTTP.
35//! 3. The worker batches up to `max_batch_size` events or flushes
36//! every `flush_interval` and POSTs to the configured endpoint.
37//! 4. Failed requests are retried with exponential backoff (capped
38//! at `max_backoff`).
39//! 5. `Drop` signals the worker, blocks for graceful shutdown
40//! flush. Pending events are best-effort flushed on exit.
41
42mod adapter;
43mod config;
44mod transport;
45mod wire;
46mod worker;
47
48pub use adapter::{PlausibleAdapter, PlausibleAdapterBuilder};
49pub use config::PlausibleConfig;
50pub use wire::PlausibleEvent;