Matomo Heartbeat High Quality (2026)

activityEvents.forEach(event => document.addEventListener(event, () => this.resetIdleTimer()); );

The heartbeat mechanism sends periodic "pings" back to the Matomo server while a user is actively engaging with a page. matomo heartbeat

resetIdleTimer() this.lastActivity = Date.now(); activityEvents

: Pings stop automatically when the tab is hidden or the user becomes inactive for a set period to save server resources. 2. Implementation via JavaScript public function getEngagementMetrics($dateFrom

if (window._paq) window._paq.push(['trackEvent', finalData.e_c, finalData.e_a, finalData.e_n, finalData.e_v]);

public function getEngagementMetrics($dateFrom, $dateTo) $stmt = $this->db->prepare(" SELECT COUNT(DISTINCT session_id) as total_sessions, SUM(total_engaged_time) as total_engagement_seconds, AVG(total_engaged_time) as avg_engagement_seconds, AVG(heartbeat_count) as avg_heartbeats_per_session, COUNT(CASE WHEN total_engaged_time > 60 THEN 1 END) as long_sessions, COUNT(CASE WHEN total_engaged_time < 10 THEN 1 END) as bounce_sessions FROM matomo_heartbeat_sessions WHERE start_time BETWEEN ? AND ? AND is_active = 0 ");