1. Go to this page and download the library: Download simplestats-io/php-client library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
simplestats-io / php-client example snippets
use SimpleStatsIo\PhpClient\SimplestatsClient;
use SimpleStatsIo\PhpClient\TrackingData;
use SimpleStatsIo\PhpClient\VisitorHashGenerator;
$client = new SimplestatsClient([
'api_token' => 'your-api-token',
]);
// Generate a GDPR-compliant visitor hash
$visitorHash = VisitorHashGenerator::generate(
ip: $_SERVER['REMOTE_ADDR'],
userAgent: $_SERVER['HTTP_USER_AGENT'],
secretKey: 'your-secret-key'
);
// Auto-extract tracking data from the current request
$trackingData = TrackingData::fromGlobals(appUrl: 'https://yourapp.com');
// Track the visitor
$client->trackVisitor($visitorHash, $trackingData);
use SimpleStatsIo\PhpClient\VisitorHashGenerator;
$hash = VisitorHashGenerator::generate(
ip: $_SERVER['REMOTE_ADDR'],
userAgent: $_SERVER['HTTP_USER_AGENT'],
secretKey: 'your-secret-key',
date: '2024-06-15' // optional, defaults to today
);
use SimpleStatsIo\PhpClient\Exceptions\ConfigurationException;
use SimpleStatsIo\PhpClient\Exceptions\ApiRequestFailed;
try {
$client->trackVisitor($visitorHash, $trackingData);
} catch (ConfigurationException $e) {
// Invalid configuration (e.g., missing api_token)
} catch (ApiRequestFailed $e) {
// API request failed after retries
$e->getMessage(); // Error description
$e->statusCode; // HTTP status code
$e->responseBody; // Raw response body
}
// Example: fastcgi_finish_request()
echo $responseBody;
fastcgi_finish_request(); // Response is delivered to the client
$client->trackVisitor($visitorHash, $trackingData); // Runs in the background
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.