fix(widget): 修复页面访问量获取失败的问题

- 前端 trackVisit 现在传递 siteId 参数
- 后端 getPagePv 查询时处理 site_id 为空或 NULL 的情况
This commit is contained in:
anghunk
2026-03-16 14:09:59 +08:00
parent e2db5daecb
commit 2ad9c90d18
2 changed files with 26 additions and 10 deletions

View File

@@ -122,16 +122,20 @@ export function createApiClient(config) {
async function trackVisit() {
try {
const body = {
postSlug: config.postUrl || config.postSlug,
postTitle: config.postTitle,
postUrl: config.postUrl
};
if (config.siteId) {
body.siteId = config.siteId;
}
await fetch(`${baseUrl}/api/analytics/visit`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
postSlug: config.postUrl || config.postSlug,
postTitle: config.postTitle,
postUrl: config.postUrl
})
body: JSON.stringify(body)
});
} catch (e) {
}