diff --git a/_config.yml b/_config.yml index c63610fe..1b9f786b 100644 --- a/_config.yml +++ b/_config.yml @@ -260,8 +260,8 @@ web_analytics: # 网页访问统计 google: measurement_id: - # Umami Analytics,src 和 data-website-id 是必填项,其他可选 - # Umami Analytics, src and data-website-id are required, others are optional + # Umami Analytics 仅支持自部署。src 和 data-website-id 是必填项,其他可选 + # Umami Analytics, only Self-host support, src and data-website-id are required, others are optional umami: # umami js 文件地址,需要在 umami 后台创建站点后获取 # umami js file url, get after create website in umami diff --git a/source/js/umami-view.js b/source/js/umami-view.js index e62bbb1a..3203997e 100644 --- a/source/js/umami-view.js +++ b/source/js/umami-view.js @@ -38,6 +38,7 @@ const request_header = { }, }; +// 获取站点统计数据 async function siteStats() { try { const response = await fetch(`${request_url}?${params}`, request_header); @@ -68,14 +69,13 @@ async function siteStats() { } } +// 获取页面浏览量 async function pageStats(path) { try { const response = await fetch(`${request_url}?${params}&url=${path}`, request_header); const data = await response.json(); const pageViews = data.pageviews.value; - console.log(data) - let viewCtn = document.querySelector("#umami-page-views-container"); if (viewCtn) { let ele = document.querySelector("#umami-page-views"); @@ -92,7 +92,9 @@ async function pageStats(path) { siteStats(); +// 获取页面容器 let viewCtn = document.querySelector("#umami-page-views-container"); +// 如果页面容器存在,则获取页面浏览量 if (viewCtn) { let path = window.location.pathname; let target = decodeURI(path.replace(/\/*(index.html)?$/, "/"));