Matomo Heartbeat [repack] <HOT · HANDBOOK>
startIdleMonitoring() this.idleCheckId = setInterval(() => const idleTime = (Date.now() - this.lastActivity) / 1000; if (idleTime >= this.options.idleTimeout && this.isActive) this.stopHeartbeat(); this.log(`User idle for $idleTime seconds, stopping heartbeat`); , 1000);
$input = json_decode(file_get_contents('php://input'), true); $result = $handler->processHeartbeat($input); matomo heartbeat
// 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' ); startIdleMonitoring() this
header('Content-Type: application/json'); echo json_encode($result); <!DOCTYPE html> <html> <head> <!-- Matomo Tracking Code --> <script> var _paq = window._paq = window._paq || []; _paq.push(['trackPageView']); _paq.push(['enableLinkTracking']); (function() var u="https://your-matomo-domain.com/"; _paq.push(['setTrackerUrl', u+'matomo.php']); _paq.push(['setSiteId', '1']); var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s); )(); </script> startIdleMonitoring() this.idleCheckId = setInterval(() =>
// Example API endpoint if ($_SERVER['REQUEST_METHOD'] === 'POST') $pdo = new PDO('mysql:host=localhost;dbname=matomo', 'user', 'password'); $tracker = new MatomoEngagementTracker($pdo);