Files
kaffeekasse-saas/nutzungsanalyse.php
T

45 lines
1.0 KiB
PHP

<?php
declare(strict_types=1);
require_once __DIR__ . '/app/analytics-relay.php';
header('Cache-Control: no-store');
if (($_SERVER['REQUEST_METHOD'] ?? '') !== 'POST') {
header('Allow: POST');
http_response_code(405);
exit;
}
$contentLength = (int)($_SERVER['CONTENT_LENGTH'] ?? 0);
if ($contentLength <= 0 || $contentLength > 8192) {
http_response_code(413);
exit;
}
$rawBody = file_get_contents('php://input');
$payload = is_string($rawBody) ? json_decode($rawBody, true) : null;
if (!is_array($payload)) {
http_response_code(400);
exit;
}
try {
/** @var array<string, string> $cookies */
$cookies = $_COOKIE;
$parameters = app_matomo_page_view_parameters($payload, $_SERVER, $cookies);
} catch (Throwable) {
http_response_code(403);
exit;
}
$result = app_matomo_forward_page_view($parameters);
if (!$result['ok']) {
error_log('First-Party-Matomo-Tracking fehlgeschlagen (HTTP ' . $result['status'] . ').');
http_response_code(502);
exit;
}
http_response_code(204);