Skip to content

Commit 7becc5b

Browse files
authored
Merge pull request #54 from calderbuild/feat/multi-dimension-optimization
feat: multi-dimension optimization (analytics, CRO, schema, UI)
2 parents b57c62d + 54c3c20 commit 7becc5b

File tree

7 files changed

+108
-5
lines changed

7 files changed

+108
-5
lines changed

api/index.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,14 @@ async def _process_meetspot_request(request: MeetSpotRequest, start_time: float)
841841
}
842842

843843
print(f"📤 返回响应: success={response_data['success']}, html_url={response_data['html_url']}")
844+
logger.info(
845+
"recommendation_completed",
846+
location_count=len(request.locations),
847+
venue_type=request.keywords or "咖啡馆",
848+
has_html=html_url is not None,
849+
processing_time_ms=int(processing_time * 1000),
850+
mode="rule_llm",
851+
)
844852
# 主动释放内存
845853
gc.collect()
846854
return response_data
@@ -998,6 +1006,12 @@ async def get_amap_config():
9981006
}
9991007

10001008

1009+
@app.get("/api/config/analytics")
1010+
async def get_analytics_config():
1011+
"""返回分析追踪配置(百度统计 ID)"""
1012+
return {"baidu_tongji_id": os.getenv("BAIDU_TONGJI_ID", "")}
1013+
1014+
10011015
@app.get("/api/status")
10021016
async def api_status():
10031017
"""API状态检查"""

api/routers/seo_pages.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
router = APIRouter()
1919
templates = Jinja2Templates(directory="templates")
20+
templates.env.globals["baidu_tongji_id"] = os.getenv("BAIDU_TONGJI_ID", "")
2021
limiter = Limiter(key_func=get_remote_address)
2122

2223

api/services/seo_content.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ def generate_schema_org(self, page_type: str, data: Dict) -> Dict:
124124
"@context": "https://schema.org",
125125
"@type": "WebApplication",
126126
"name": "MeetSpot",
127+
"url": base_url + "/",
127128
"description": "Find the perfect meeting location midpoint for groups",
128129
"applicationCategory": "UtilitiesApplication",
129130
"operatingSystem": "Web",
@@ -153,6 +154,7 @@ def generate_schema_org(self, page_type: str, data: Dict) -> Dict:
153154
"@type": "Organization",
154155
"name": "MeetSpot",
155156
"url": base_url,
157+
"logo": base_url + "/public/favicon.svg",
156158
"contactPoint": [
157159
{
158160
"@type": "ContactPoint",
@@ -391,7 +393,7 @@ def generate_city_content(self, city_data: Dict) -> Dict[str, str]:
391393
<section class="cta-section">
392394
<h2>开始规划{city}聚会</h2>
393395
<p>无需注册,输入地址即可获取推荐</p>
394-
<a href="/" class="cta-button">立即使用 MeetSpot</a>
396+
<a href="/public/meetspot_finder.html" class="cta-button" data-track="cta_click" data-track-label="city_page">立即使用 MeetSpot</a>
395397
</section>''',
396398
}
397399

app/tool/meetspot_recommender.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2548,6 +2548,21 @@ async def _generate_html_content(
25482548
--venue-icon-bg: {cfg.get("theme_primary", "#0A4D68")};
25492549
}}"""
25502550

2551+
baidu_tongji_id = os.getenv("BAIDU_TONGJI_ID", "")
2552+
analytics_script = ""
2553+
if baidu_tongji_id:
2554+
analytics_script = (
2555+
"\n <script>"
2556+
"\n var _hmt = _hmt || [];"
2557+
"\n (function() {"
2558+
'\n var hm = document.createElement("script");'
2559+
f'\n hm.src = "https://hm.baidu.com/hm.js?{baidu_tongji_id}";'
2560+
'\n var s = document.getElementsByTagName("script")[0];'
2561+
"\n s.parentNode.insertBefore(hm, s);"
2562+
"\n })();"
2563+
"\n </script>"
2564+
)
2565+
25512566
html_content = f"""<!DOCTYPE html>
25522567
<html lang="zh-CN">
25532568
<head>
@@ -2576,7 +2591,7 @@ async def _generate_html_content(
25762591
<!-- Modern UI Components -->
25772592
<link rel="stylesheet" href="/public/css/components.css">
25782593
2579-
{schema_script}
2594+
{schema_script}{analytics_script}
25802595
<style>
25812596
{dynamic_style} /* Inject dynamic theme colors here */
25822597
@@ -2991,6 +3006,13 @@ async def _generate_html_content(
29913006
</style>
29923007
</head>
29933008
<body>
3009+
<nav style="background:#001524;padding:10px 20px;display:flex;justify-content:space-between;align-items:center;position:sticky;top:0;z-index:1000;">
3010+
<a href="/" style="color:white;text-decoration:none;font-family:'Outfit',sans-serif;font-weight:700;font-size:1.1rem;">MeetSpot</a>
3011+
<div style="display:flex;gap:16px;align-items:center;">
3012+
<a href="/public/meetspot_finder.html" style="color:#06D6A0;text-decoration:none;font-size:0.9rem;">重新搜索</a>
3013+
<button onclick="navigator.clipboard.writeText(location.href).then(function(){{this.textContent='已复制!'}}.bind(this))" data-track="result_share" data-track-label="copy_link" style="background:#FF6B35;color:white;border:none;padding:6px 14px;border-radius:8px;cursor:pointer;font-size:0.85rem;">复制链接</button>
3014+
</div>
3015+
</nav>
29943016
<header>
29953017
<div class="container">
29963018
<div class="header-logo">
@@ -3184,6 +3206,20 @@ async def _generate_html_content(
31843206
31853207
<!-- Modern Toast Notification System -->
31863208
<script src="/public/js/toast.js"></script>
3209+
3210+
<script>
3211+
if (typeof _hmt !== "undefined") {{
3212+
_hmt.push(["_trackEvent", "meetspot", "result_page_view",
3213+
"{primary_keyword}", {len(places)}]);
3214+
}}
3215+
document.addEventListener("click", function(e) {{
3216+
var el = e.target.closest("[data-track]");
3217+
if (el && typeof _hmt !== "undefined") {{
3218+
_hmt.push(["_trackEvent", "meetspot", el.dataset.track,
3219+
el.dataset.trackLabel || ""]);
3220+
}}
3221+
}});
3222+
</script>
31873223
</body>
31883224
</html>"""
31893225
return html_content

public/meetspot_finder.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,8 +1456,24 @@
14561456
right: 12px;
14571457
}
14581458
</style>
1459+
1460+
<script>
1461+
var _hmt = _hmt || [];
1462+
fetch("/api/config/analytics").then(function(r) { return r.json(); }).then(function(cfg) {
1463+
if (cfg.baidu_tongji_id) {
1464+
var hm = document.createElement("script");
1465+
hm.src = "https://hm.baidu.com/hm.js?" + cfg.baidu_tongji_id;
1466+
document.head.appendChild(hm);
1467+
}
1468+
}).catch(function() {});
1469+
</script>
14591470
</head>
14601471
<body>
1472+
<nav style="background:#001524;padding:8px 20px;display:flex;justify-content:space-between;align-items:center;">
1473+
<a href="/" style="color:white;text-decoration:none;font-family:'Outfit',sans-serif;font-weight:700;font-size:1rem;">MeetSpot</a>
1474+
<a href="/how-it-works" style="color:#06D6A0;text-decoration:none;font-size:0.85rem;">使用指南</a>
1475+
</nav>
1476+
14611477
<!-- Floating Particles Background -->
14621478
<div class="particles">
14631479
<div class="particle"></div>
@@ -2365,6 +2381,12 @@ <h4 id="loadingTitle">智能分析中</h4>
23652381
requestBody.location_coords = location_coords;
23662382
}
23672383

2384+
if (typeof _hmt !== "undefined") {
2385+
_hmt.push(["_trackEvent", "meetspot", "tool_submit",
2386+
keywords, locations.length]);
2387+
}
2388+
2389+
const _submitTime = Date.now();
23682390
const response = await fetch('/api/find_meetspot', {
23692391
method: 'POST',
23702392
headers: { 'Content-Type': 'application/json' },
@@ -2383,6 +2405,10 @@ <h4 id="loadingTitle">智能分析中</h4>
23832405
ThinkingAnimator.complete(mode);
23842406

23852407
if (result.success && result.html_url) {
2408+
if (typeof _hmt !== "undefined") {
2409+
_hmt.push(["_trackEvent", "meetspot", "recommendation_result",
2410+
mode, Date.now() - _submitTime]);
2411+
}
23862412
// Show mode-aware success message
23872413
const modeText = mode === 'agent' ? 'Agent 深度分析' : '快速推荐';
23882414
showSuccess(`${modeText}完成`, `${keywords}推荐已生成,正在跳转...`);

templates/base.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,18 @@
676676
</style>
677677

678678
{% block extra_head %}{% endblock %}
679+
680+
{% if baidu_tongji_id %}
681+
<script>
682+
var _hmt = _hmt || [];
683+
(function() {
684+
var hm = document.createElement("script");
685+
hm.src = "https://hm.baidu.com/hm.js?" + "{{ baidu_tongji_id }}";
686+
var s = document.getElementsByTagName("script")[0];
687+
s.parentNode.insertBefore(hm, s);
688+
})();
689+
</script>
690+
{% endif %}
679691
</head>
680692
<body>
681693
<a href="#main" class="sr-only">跳转到主内容</a>
@@ -846,5 +858,17 @@ <h3>感谢你的支持</h3>
846858

847859
<!-- AI Chat Widget -->
848860
{% include 'components/ai_chat.html' %}
861+
862+
{% if baidu_tongji_id %}
863+
<script>
864+
document.addEventListener("click", function(e) {
865+
var el = e.target.closest("[data-track]");
866+
if (el && typeof _hmt !== "undefined") {
867+
_hmt.push(["_trackEvent", "meetspot", el.dataset.track,
868+
el.dataset.trackLabel || ""]);
869+
}
870+
});
871+
</script>
872+
{% endif %}
849873
</body>
850874
</html>

templates/pages/home.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,7 @@ <h1>
10591059
<span class="divider"></span>
10601060
<span>5步推理</span>
10611061
</div>
1062-
<a href="/public/meetspot_finder.html" class="hero-cta">
1062+
<a href="/public/meetspot_finder.html" class="hero-cta" data-track="cta_click" data-track-label="hero">
10631063
立即免费使用
10641064
</a>
10651065

@@ -1178,7 +1178,7 @@ <h2 class="main-heading">多人聚会,一键找到最公平的中点位置</h2
11781178
MeetSpot(聚点)是一个智能会面地点推荐AI Agent。无论是咖啡馆商务会谈、餐厅朋友聚餐、还是图书馆学习讨论,都能根据多人位置快速计算最佳中点,推荐附近高评分场所。
11791179
</p>
11801180
<div class="btn-group">
1181-
<a class="btn-primary btn-primary-filled" href="/public/meetspot_finder.html">
1181+
<a class="btn-primary btn-primary-filled" href="/public/meetspot_finder.html" data-track="cta_click" data-track-label="main_content">
11821182
<i class='bx bx-rocket'></i>
11831183
立即免费使用
11841184
</a>
@@ -1310,7 +1310,7 @@ <h2>开始规划你的下一次聚会</h2>
13101310
有问题或建议?欢迎通过 <a href="https://github.com/calderbuild/MeetSpot/issues">GitHub Issues</a> 反馈。
13111311
</p>
13121312
<div class="cta-buttons">
1313-
<a href="/public/meetspot_finder.html" class="cta-btn cta-btn-primary">立即创建聚会计划</a>
1313+
<a href="/public/meetspot_finder.html" class="cta-btn cta-btn-primary" data-track="cta_click" data-track-label="bottom">立即创建聚会计划</a>
13141314
<a href="/about" class="cta-btn cta-btn-secondary">了解更多</a>
13151315
</div>
13161316
</div>

0 commit comments

Comments
 (0)