feat: 来源组合显示——徽章/识别卡拼装落地页·国家·语言(搜索意图线索)

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
浅念
2026-09-16 17:43:37 +08:00
parent f9c8c354ae
commit 008d9277d8
5 changed files with 49 additions and 8 deletions
+6 -4
View File
@@ -57,8 +57,8 @@ def test_list_fields_and_default_bot_excluded(client, member_user):
site = Site.objects.create(name="s", domains=["a.com"])
v1 = _visitor(site, "v1", country="中国", province="上海", city="上海",
device_type="desktop", os="Windows", browser="Chrome", language="zh-CN",
first_referrer_domain="google.com", visit_count=2, active_days=1,
last_seen=timezone.now())
first_referrer_domain="google.com", first_landing_path="/from-google",
visit_count=2, active_days=1, last_seen=timezone.now())
v2 = _visitor(site, "v2", first_utm={"utm_source": "baidu"},
last_seen=timezone.now() - timedelta(hours=1))
bot = _visitor(site, "bot-v")
@@ -77,16 +77,18 @@ def test_list_fields_and_default_bot_excluded(client, member_user):
assert set(row) == {"visitor_id", "site_id", "site_name", "country", "province", "city",
"device_type", "os", "browser", "language", "first_seen_at",
"last_seen_at", "visit_count", "active_days", "session_count",
"total_stay_ms", "first_source", "last_source", "online",
"channel", "platform", "variant", "search_term", "resolution"}
"total_stay_ms", "first_source", "last_source", "first_landing_path",
"online", "channel", "platform", "variant", "search_term", "resolution"}
assert row["country"] == "中国" and row["os"] == "Windows" and row["browser"] == "Chrome"
assert row["session_count"] == 2
assert row["total_stay_ms"] == 150000 # 120000+30000,有效停留口径
assert row["first_source"] == "google.com"
assert row["last_source"] == "bing.com" # 最近会话 s2 的 referrer
assert row["first_landing_path"] == "/from-google"
assert row["online"] is True
row2 = d["list"][1]
assert row2["first_source"] == "baidu" # first_referrer 空 → first_utm 兜底
assert row2["first_landing_path"] == "" # 未采集 → 空串(前端显示 —)
assert row2["last_source"] == "直接访问" # 会话无来源 → 兜底
assert row2["total_stay_ms"] == 5000 and row2["online"] is False