From 763de8c2e907e4e838e1fb06cb23a8da424e6fc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nu=C5=A1a=20Puk=C5=A1i=C4=8D?= Date: Tue, 26 Aug 2025 17:41:45 +0200 Subject: [PATCH] Visit analytics --- .../controllers/visit_analytics_controller.js | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 assets/controllers/visit_analytics_controller.js diff --git a/assets/controllers/visit_analytics_controller.js b/assets/controllers/visit_analytics_controller.js new file mode 100644 index 0000000..5628d32 --- /dev/null +++ b/assets/controllers/visit_analytics_controller.js @@ -0,0 +1,34 @@ +import { Controller } from '@hotwired/stimulus'; + +/** + * Simple analytics controller to record page visits + */ +export default class extends Controller { + static values = { + path: String + } + + connect() { + // Record the visit when the controller connects + this.recordVisit(); + } + + recordVisit() { + // Get the current route path + const path = this.pathValue || window.location.pathname; + + // Send visit data to API + fetch('/api/visit', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + route: path + }) + }) + .catch(error => { + console.error('Error recording visit:', error); + }); + } +}