Matomo Heartbeat -

// Example API endpoint if ($_SERVER['REQUEST_METHOD'] === 'POST') $pdo = new PDO('mysql:host=localhost;dbname=matomo', 'user', 'password'); $tracker = new MatomoEngagementTracker($pdo);

header('Content-Type: application/json'); echo json_encode(['success' => $result]); <?php // matomo-engagement-tracker.php class MatomoEngagementTracker private $db; private $heartbeatTimeout = 35; // seconds public function __construct($pdo) $this->db = $pdo; $this->createHeartbeatTable(); matomo heartbeat

private function createNewSession($sessionId, $visitorId, $pageUrl) $now = new DateTime(); $stmt = $this->db->prepare(" INSERT INTO matomo_heartbeat_sessions (session_id, visitor_id, page_url, start_time, last_heartbeat, total_engaged_time, heartbeat_count) VALUES (?, ?, ?, ?, ?, ?, 1) "); $stmt->execute([ $sessionId, $visitorId, $pageUrl, $now->format('Y-m-d H:i:s'), $now->format('Y-m-d H:i:s'), 0 ]); return ['status' => 'created', 'session_id' => $this->db->lastInsertId()]; $tracker = new MatomoEngagementTracker($pdo)

// Auto-initialize if Matomo is present if (typeof window._paq !== 'undefined') window.matomoHeartbeat = new MatomoHeartbeat( heartbeatInterval: 15, minVisitLength: 5, idleTimeout: 30, debug: window.location.hostname === 'localhost' ); echo json_encode(['success' =&gt

private function endSession($sessionId) $stmt = $this->db->prepare(" UPDATE matomo_heartbeat_sessions SET is_active = 0 WHERE id = ? "); $stmt->execute([$sessionId]);

Centre de préférences de confidentialité

Necessary

Advertising

Analytics

Other