Skip to main content

Stats registry

Stats consumers receive a StatsEvent whenever a download starts, completes, or fails. The registry is a fan-out: every registered consumer sees every event. Consumers decide what to do. Increment a counter, ship to an analytics backend, write a log line.

KeyValue
Container keymc_dm.stats_registry
Eventmc_dm_stats_handlers

Built-in consumers

IDClassWhat it does
built_in_aggregatorMC\DownloadsManager\Stats\BuiltInAggregatorIncrements xf_mc_dm_download.download_count and writes per-day rows for AdminCP analytics.

Interface

namespace MC\DownloadsManager\Stats;

interface StatsConsumer
{
public function consume(StatsEvent $event): void;
}

StatsEvent carries the event type (started, completed, failed), the Download, the DownloadVersion, the DownloadFile, the visitor, and the bytes-served count (for completed).

Wiring an adapter

public static function statsHandlers(StatsRegistry $registry)
{
$registry->register('plausible', new YourAddon\Stats\PlausibleConsumer($apiKey));
}

Stats consumers run after the lifecycle event fires. A consumer that throws will not roll back the download. Failures are caught and logged.