Reusable PHP client for applications that submit opt-in usage statistics using Usage Statistics Protocol v1.
- PHP 8.2 or newer
- Composer
composer require librecodecoop/usage-statistics-clientuse LibreCode\UsageStatistics\Client;
use LibreCode\UsageStatistics\ConsentState;
use LibreCode\UsageStatistics\Endpoint;
use LibreCode\UsageStatistics\InstallationId;
use LibreCode\UsageStatistics\Metric;
use LibreCode\UsageStatistics\Report;
use LibreCode\UsageStatistics\ReportingPeriod;
use LibreCode\UsageStatistics\Transport\StreamTransport;
$report = new Report(
application: 'libresign',
installationId: (string) InstallationId::derive('libresign', $localInstallationIdentifier),
schemaVersion: 1,
period: ReportingPeriod::monthContaining(new DateTimeImmutable()),
metrics: [
Metric::string('environment', 'version', '12.0.0'),
Metric::integer('usage', 'requests_completed', 72),
],
);
$client = new Client(
new StreamTransport(),
new Endpoint('https://statistics.example/api/v1/reports'),
);
$client->submit($report, ConsentState::Enabled);Applications define their own metrics, consent UI and persistence, endpoint, scheduling and logging policy. The client validates and serializes Protocol v1 reports and submits them when consent is enabled.
- Integration
- Privacy
- Architecture
- PHP-Scoper
- Mozart
- Development
- Versioning
- Troubleshooting
- Contributing
AGPL-3.0-or-later. See COPYING and LICENSES/AGPL-3.0-or-later.txt.