통계 콘텐츠 세션 원장 추가

This commit is contained in:
2026-07-29 14:48:14 +09:00
parent 1a5a1542b7
commit 4e7e12d8fe
15 changed files with 481 additions and 47 deletions

View File

@@ -0,0 +1,43 @@
CREATE TABLE IF NOT EXISTS analytics_content_sessions (
content_session_hash TEXT PRIMARY KEY,
day DATE NOT NULL,
visitor_hash TEXT NOT NULL,
session_hash TEXT NOT NULL,
path TEXT NOT NULL,
post_id UUID REFERENCES posts(id) ON DELETE SET NULL,
page_id UUID REFERENCES pages(id) ON DELETE SET NULL,
source_group TEXT NOT NULL DEFAULT '',
source_name TEXT NOT NULL DEFAULT '',
device_type TEXT NOT NULL DEFAULT '',
os_name TEXT NOT NULL DEFAULT '',
keyword TEXT NOT NULL DEFAULT '',
view_recorded BOOLEAN NOT NULL DEFAULT false,
first_seen_at TIMESTAMPTZ NOT NULL DEFAULT now(),
last_seen_at TIMESTAMPTZ NOT NULL DEFAULT now(),
duration_seconds INTEGER NOT NULL DEFAULT 0,
max_scroll_ratio REAL NOT NULL DEFAULT 0,
engaged_recorded BOOLEAN NOT NULL DEFAULT false,
scroll_25_recorded BOOLEAN NOT NULL DEFAULT false,
scroll_50_recorded BOOLEAN NOT NULL DEFAULT false,
scroll_75_recorded BOOLEAN NOT NULL DEFAULT false,
scroll_100_recorded BOOLEAN NOT NULL DEFAULT false,
read_recorded BOOLEAN NOT NULL DEFAULT false,
read_at TIMESTAMPTZ
);
CREATE INDEX IF NOT EXISTS analytics_content_sessions_day_idx
ON analytics_content_sessions (day DESC);
CREATE INDEX IF NOT EXISTS analytics_content_sessions_session_idx
ON analytics_content_sessions (session_hash);
CREATE INDEX IF NOT EXISTS analytics_content_sessions_post_idx
ON analytics_content_sessions (post_id, day DESC)
WHERE post_id IS NOT NULL;
CREATE INDEX IF NOT EXISTS analytics_content_sessions_page_idx
ON analytics_content_sessions (page_id, day DESC)
WHERE page_id IS NOT NULL;
ALTER TABLE analytics_active_sessions
ADD COLUMN IF NOT EXISTS content_session_hash TEXT NOT NULL DEFAULT '';