events: record timeline_view on GET /timeline with view+forced meta

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Arlind Ukshini 2026-04-27 10:52:29 +02:00
parent 9eafba547a
commit 31bfd72b4c

View file

@ -14,6 +14,7 @@ import authRouter from './src/auth.js';
import { requireAuth, requireAdmin } from './src/middleware.js'; import { requireAuth, requireAdmin } from './src/middleware.js';
import { q } from './src/db.js'; // also side-effect: opens DB + runs schema import { q } from './src/db.js'; // also side-effect: opens DB + runs schema
import { MOBILE_UA_RE } from './src/ua.js'; import { MOBILE_UA_RE } from './src/ua.js';
import { recordEvent } from './src/events.js';
const __dirname = path.dirname(fileURLToPath(import.meta.url)); const __dirname = path.dirname(fileURLToPath(import.meta.url));
const app = express(); const app = express();
@ -191,7 +192,15 @@ function wantsMobileView(req) {
} }
app.get('/timeline', requireAuth, (req, res) => { app.get('/timeline', requireAuth, (req, res) => {
if (wantsMobileView(req)) { const forced = ['mobile', 'desktop'].includes((req.query.view || '').toLowerCase());
const view = wantsMobileView(req) ? 'mobile' : 'desktop';
recordEvent(req, {
type: 'timeline_view',
email: req.session.email,
sessionId: req.session.id,
meta: { view, forced },
});
if (view === 'mobile') {
return res.sendFile(path.join(__dirname, 'protected', 'mobile', 'index.html')); return res.sendFile(path.join(__dirname, 'protected', 'mobile', 'index.html'));
} }
return res.sendFile(path.join(__dirname, 'protected', 'index.html')); return res.sendFile(path.join(__dirname, 'protected', 'index.html'));