@@ -0,0 +1,80 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// attachTrackerPage 为所有 HTML 页面补齐稳定的 pageKey/pageName,避免事件落入 unknown。
|
||||
func attachTrackerPage(path string, code int, data map[string]any) {
|
||||
if data == nil {
|
||||
return
|
||||
}
|
||||
key, name := trackerPageFromRequest(path, code)
|
||||
if current, _ := data["pageKey"].(string); strings.TrimSpace(current) == "" {
|
||||
data["pageKey"] = key
|
||||
}
|
||||
if current, _ := data["pageName"].(string); strings.TrimSpace(current) == "" {
|
||||
data["pageName"] = name
|
||||
}
|
||||
}
|
||||
|
||||
func trackerPageFromRequest(path string, code int) (string, string) {
|
||||
if code >= http.StatusInternalServerError {
|
||||
return "server_error", "服务异常页面"
|
||||
}
|
||||
if code >= http.StatusBadRequest {
|
||||
return "not_found", "404页面"
|
||||
}
|
||||
return trackerPageFromPath(path)
|
||||
}
|
||||
|
||||
func trackerPageFromPath(path string) (string, string) {
|
||||
p := strings.TrimSuffix(strings.TrimSpace(path), "/")
|
||||
if p == "" {
|
||||
return "home", "首页"
|
||||
}
|
||||
rules := []struct {
|
||||
prefix string
|
||||
key string
|
||||
name string
|
||||
}{
|
||||
{"/series-play", "series_play", "AI成人剧集播放页"},
|
||||
{"/series", "series", "AI成人剧集"},
|
||||
{"/play", "play", "短剧播放页"},
|
||||
{"/detail", "detail", "短剧详情"},
|
||||
{"/list", "list", "短剧列表"},
|
||||
{"/recently-added", "recently_added", "最新短剧"},
|
||||
{"/popular-recommend", "popular_recommend", "热门推荐"},
|
||||
{"/rank", "rank", "排行榜"},
|
||||
{"/topic-detail", "topic_detail", "专题详情"},
|
||||
{"/topic", "topic", "专题列表"},
|
||||
{"/tags", "tags", "标签详情"},
|
||||
{"/more-series-list", "more_series_list", "成人剧集列表"},
|
||||
{"/more-list", "more_list", "短剧扩展列表"},
|
||||
{"/search-mobile", "search", "搜索结果页"},
|
||||
{"/search", "search", "搜索结果页"},
|
||||
{"/history", "history", "观看历史"},
|
||||
{"/favorites", "favorites", "我的收藏"},
|
||||
{"/purchased", "purchased", "已购剧集"},
|
||||
{"/profile", "profile", "个人中心"},
|
||||
{"/setting", "setting", "设置"},
|
||||
{"/recharge", "recharge", "充值中心"},
|
||||
{"/download-app", "download_app", "下载APP"},
|
||||
{"/feedback", "feedback", "问题反馈"},
|
||||
{"/help", "help", "帮助中心"},
|
||||
{"/about", "about", "关于我们"},
|
||||
{"/terms", "terms", "用户协议"},
|
||||
{"/privacy", "privacy", "隐私政策"},
|
||||
{"/2257", "compliance_2257", "2257合规声明"},
|
||||
{"/dmca", "dmca", "DMCA版权声明"},
|
||||
{"/login", "login", "登录"},
|
||||
{"/register", "register", "注册"},
|
||||
}
|
||||
for _, rule := range rules {
|
||||
if p == rule.prefix || strings.HasPrefix(p, rule.prefix+"/") {
|
||||
return rule.key, rule.name
|
||||
}
|
||||
}
|
||||
return "internal_other", "站内其他页面"
|
||||
}
|
||||
Reference in New Issue
Block a user