Matomo Heartbeat ❲2026❳
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()];
getEngagementMetrics() const currentEngagement = this.isActive && this.lastHeartbeatTime ? Math.floor((Date.now() - this.lastHeartbeatTime) / 1000) : 0; return totalEngagedTime: this.totalEngagedTime + currentEngagement, isActive: this.isActive, visitDuration: this.visitStartTime ? Math.floor((Date.now() - this.visitStartTime) / 1000) : 0 ; matomo heartbeat
private function createHeartbeatTable() $sql = " CREATE TABLE IF NOT EXISTS matomo_heartbeat_sessions ( id INT AUTO_INCREMENT PRIMARY KEY, session_id VARCHAR(64) NOT NULL, visitor_id VARCHAR(64) NOT NULL, page_url TEXT, start_time DATETIME NOT NULL, last_heartbeat DATETIME NOT NULL, total_engaged_time INT DEFAULT 0, heartbeat_count INT DEFAULT 0, is_active BOOLEAN DEFAULT TRUE, INDEX idx_session (session_id), INDEX idx_visitor (visitor_id), INDEX idx_active (is_active) )"; $this->db->exec($sql); private function createNewSession($sessionId
