Analytics: Geruest, Datenbank, Website-Register

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Sonnet 5.5 committed 2026-10-01 09:23:27 +00:00
1 parent a1ce46672a
commit f7da79e4b3
6 files changed
+318

No files matched your search

+54
View File
@@ -0,0 +1,54 @@
import { DatabaseSync } from 'node:sqlite';
const SCHEMA = `
CREATE TABLE IF NOT EXISTS sites (
siteKey TEXT PRIMARY KEY,
projectId TEXT NOT NULL,
domains TEXT NOT NULL,
active INTEGER NOT NULL DEFAULT 1,
offSince TEXT
);
CREATE TABLE IF NOT EXISTS events_raw (
id INTEGER PRIMARY KEY AUTOINCREMENT,
site TEXT NOT NULL,
ts INTEGER NOT NULL,
type TEXT NOT NULL,
path TEXT,
vp TEXT,
ref TEXT,
country TEXT,
device TEXT,
visitor TEXT,
sec INTEGER,
scroll INTEGER,
kind TEXT,
host TEXT
);
CREATE INDEX IF NOT EXISTS idx_events_site_ts ON events_raw(site, ts);
CREATE TABLE IF NOT EXISTS clicks (
id INTEGER PRIMARY KEY AUTOINCREMENT,
site TEXT NOT NULL,
ts INTEGER NOT NULL,
path TEXT NOT NULL,
vp TEXT NOT NULL,
x REAL NOT NULL,
y REAL NOT NULL,
sel TEXT
);
CREATE INDEX IF NOT EXISTS idx_clicks_site_path_vp_ts ON clicks(site, path, vp, ts);
CREATE TABLE IF NOT EXISTS daily (
site TEXT NOT NULL,
day TEXT NOT NULL,
dim TEXT NOT NULL,
key TEXT NOT NULL,
count INTEGER NOT NULL DEFAULT 0,
PRIMARY KEY (site, day, dim, key)
);
`;
export function openDb(path) {
const db = new DatabaseSync(path);
if (path !== ':memory:') db.exec('PRAGMA journal_mode = WAL');
db.exec(SCHEMA);
return db;
}