feat: implement comprehensive reading analytics system with bot detection
Features: - Add article view tracking with automatic deduplication (per user/IP) - Implement intelligent bot detection (35+ patterns: Google, Bing, Baidu, GPTBot, etc) - Create admin analytics dashboard with statistics and filtering - Display view count and comment count on article cards - Add search-based article filter (replaced dropdown for scalability) Analytics Dashboard: - Global stats: total views, human/bot views, unique IPs/users - Top 20 articles ranking with detailed metrics - Detailed view records with time, article, user, IP, user-agent - Filters: article title search, IP search, show/hide bots - Pagination support (50 records per page) Technical Implementation: - Async view recording (non-blocking) - Dual deduplication (application + database layer) - Database indexes for performance optimization - Batch query for comment counts - Full i18n support (Chinese/English) Files Added: - models/article_view.go: View tracking model - models/bot_detector.go: Bot detection logic - handlers/admin_analytics.go: Analytics page handler - templates/admin/analytics_views.html: Analytics UI - test_analytics.sh: Testing script - Documentation: implementation guide, usage guide, changelog Files Modified: - handlers/home.go: Add view recording and comment count queries - models/db.go: Add ArticleView to auto-migration - main.go: Add analytics routes - i18n/i18n.go: Add 35+ translation keys - templates/admin/dashboard.html: Add analytics entry link - templates/pages/home.html: Display view/comment counts on cards Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -325,6 +325,44 @@ var translations = map[Lang]map[string]string{
|
||||
"user_cannot_disable_self": "You cannot disable or lock your own account.",
|
||||
"user_cannot_remove_last_admin": "Cannot remove the last administrator.",
|
||||
"dash_user_mgmt": "Manage Users",
|
||||
|
||||
// Analytics
|
||||
"analytics_views_title": "Reading Analytics",
|
||||
"analytics_views_desc": "Track article views, identify unique visitors and detect bots.",
|
||||
"analytics_stats_total": "Total Views",
|
||||
"analytics_stats_human_views": "Human Views",
|
||||
"analytics_stats_bot_views": "Bot Views",
|
||||
"analytics_stats_unique_ips": "Unique IPs",
|
||||
"analytics_stats_unique_users": "Unique Users",
|
||||
"analytics_article_stats": "Article Statistics (Top 20)",
|
||||
"analytics_col_article": "Article",
|
||||
"analytics_col_total_views": "Total Views",
|
||||
"analytics_col_human_views": "Human",
|
||||
"analytics_col_bot_views": "Bots",
|
||||
"analytics_col_unique_ips": "Unique IPs",
|
||||
"analytics_col_time": "Time",
|
||||
"analytics_col_user": "User",
|
||||
"analytics_col_ip": "IP Address",
|
||||
"analytics_col_user_agent": "User Agent",
|
||||
"analytics_col_is_bot": "Type",
|
||||
"analytics_filters": "Filters",
|
||||
"analytics_filter_article": "Article Title",
|
||||
"analytics_filter_article_placeholder": "Search article title",
|
||||
"analytics_filter_ip": "IP Address",
|
||||
"analytics_filter_ip_placeholder": "Search by IP",
|
||||
"analytics_filter_show_bots": "Show Bots",
|
||||
"analytics_include_bots": "Include bot traffic",
|
||||
"analytics_apply_filters": "Apply Filters",
|
||||
"analytics_recent_views": "Recent Views",
|
||||
"analytics_bot": "Bot",
|
||||
"analytics_human": "Human",
|
||||
"analytics_anonymous": "Anonymous",
|
||||
"analytics_article_deleted": "(Deleted)",
|
||||
"analytics_no_data": "No data available.",
|
||||
"analytics_no_views": "No view records found.",
|
||||
"analytics_showing": "Showing",
|
||||
"analytics_of": "of",
|
||||
"analytics_load_more": "Load More",
|
||||
},
|
||||
ZH: {
|
||||
// 导航
|
||||
@@ -635,6 +673,44 @@ var translations = map[Lang]map[string]string{
|
||||
"user_cannot_disable_self": "不能禁用或锁定自己的账号。",
|
||||
"user_cannot_remove_last_admin": "不能移除最后一个管理员。",
|
||||
"dash_user_mgmt": "用户管理",
|
||||
|
||||
// 阅读统计
|
||||
"analytics_views_title": "阅读统计",
|
||||
"analytics_views_desc": "追踪文章阅读量,识别独立访客和爬虫。",
|
||||
"analytics_stats_total": "总阅读量",
|
||||
"analytics_stats_human_views": "真人阅读",
|
||||
"analytics_stats_bot_views": "爬虫访问",
|
||||
"analytics_stats_unique_ips": "独立IP",
|
||||
"analytics_stats_unique_users": "独立用户",
|
||||
"analytics_article_stats": "文章统计(前20篇)",
|
||||
"analytics_col_article": "文章",
|
||||
"analytics_col_total_views": "总阅读量",
|
||||
"analytics_col_human_views": "真人",
|
||||
"analytics_col_bot_views": "爬虫",
|
||||
"analytics_col_unique_ips": "独立IP",
|
||||
"analytics_col_time": "时间",
|
||||
"analytics_col_user": "用户",
|
||||
"analytics_col_ip": "IP地址",
|
||||
"analytics_col_user_agent": "User Agent",
|
||||
"analytics_col_is_bot": "类型",
|
||||
"analytics_filters": "筛选条件",
|
||||
"analytics_filter_article": "文章标题",
|
||||
"analytics_filter_article_placeholder": "搜索文章标题",
|
||||
"analytics_filter_ip": "IP地址",
|
||||
"analytics_filter_ip_placeholder": "按IP搜索",
|
||||
"analytics_filter_show_bots": "显示爬虫",
|
||||
"analytics_include_bots": "包含爬虫流量",
|
||||
"analytics_apply_filters": "应用筛选",
|
||||
"analytics_recent_views": "最近访问记录",
|
||||
"analytics_bot": "爬虫",
|
||||
"analytics_human": "真人",
|
||||
"analytics_anonymous": "匿名用户",
|
||||
"analytics_article_deleted": "(已删除)",
|
||||
"analytics_no_data": "暂无数据。",
|
||||
"analytics_no_views": "未找到访问记录。",
|
||||
"analytics_showing": "显示",
|
||||
"analytics_of": "共",
|
||||
"analytics_load_more": "加载更多",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user