From dace585020440402641db7e87a189245aa83a0a3 Mon Sep 17 00:00:00 2001 From: Mintimate Date: Mon, 16 Feb 2026 11:03:51 +0800 Subject: [PATCH] =?UTF-8?q?feat(PV/UV):=20=E9=80=82=E9=85=8D=20OpenKounter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 基于 EdgeOne Pages 适配基于 KV 的 PV 和 UV 统计,解决 LeanCloud 下线问题 --- _config.yml | 19 ++- layout/_partials/footer/statistics.ejs | 17 +++ layout/_partials/plugins/analytics.ejs | 5 + layout/_partials/post/meta-top.ejs | 8 +- source/js/openkounter.js | 173 +++++++++++++++++++++++++ 5 files changed, 218 insertions(+), 4 deletions(-) create mode 100644 source/js/openkounter.js diff --git a/_config.yml b/_config.yml index 179e73078..4889322ee 100644 --- a/_config.yml +++ b/_config.yml @@ -282,6 +282,19 @@ web_analytics: # If true, ignore localhost & 127.0.0.1 ignore_local: false + # OpenKounter 计数统计(基于 EdgeOne/Cloudflare Workers),可用于 PV UV 展示 + # OpenKounter count statistics (based on EdgeOne/Cloudflare Workers), which can be used for PV UV display + openkounter: + # OpenKounter API 服务器地址 + # OpenKounter API server URL + server_url: https://open-kounter.mintimate.cn + # 统计页面时获取路径的属性,通常使用 window.location.pathname + # Get the attribute of the page path during statistics + path: window.location.pathname + # 开启后不统计本地路径(localhost、127.0.0.1、[::1]) + # If true, ignore localhost & 127.0.0.1 & [::1] + ignore_local: false + # Umami Analytics,仅支持自部署。如果要展示 PV UV 需要填写所有配置项,否则只填写 `src` 和 `website_id` 即可 # Umami Analytics, only Self-host support. If you want to display PV UV need to set all config items, otherwise only set 'src' and 'website_id' # See: https://umami.is/docs @@ -456,9 +469,9 @@ footer: statistics: enable: false - # 统计数据来源,使用 leancloud, umami 需要设置 `web_analytics` 中对应的参数;使用 busuanzi 不需要额外设置,但是有时不稳定,另外本地运行时 busuanzi 显示统计数据很大属于正常现象,部署后会正常 - # Data source. If use leancloud, umami, you need to set the parameter in `web_analytics` - # Options: busuanzi | leancloud | umami + # 统计数据来源,使用 leancloud, umami, openkounter 需要设置 `web_analytics` 中对应的参数;使用 busuanzi 不需要额外设置,但是有时不稳定,另外本地运行时 busuanzi 显示统计数据很大属于正常现象,部署后会正常 + # Data source. If use leancloud, umami, openkounter, you need to set the parameter in `web_analytics` + # Options: busuanzi | leancloud | umami | openkounter source: "busuanzi" # 国内大陆服务器的备案信息 diff --git a/layout/_partials/footer/statistics.ejs b/layout/_partials/footer/statistics.ejs index 9f05e2dc8..f129adad7 100644 --- a/layout/_partials/footer/statistics.ejs +++ b/layout/_partials/footer/statistics.ejs @@ -19,6 +19,23 @@ <% } %> <% import_js(theme.static_prefix.internal_js, 'leancloud.js', 'defer') %> + <% } else if (theme.footer.statistics.source === 'openkounter') { %> + <% if (pv_texts.length >= 2) { %> + + <% } %> + <% if (uv_texts.length >= 2) { %> + + <% } %> + <% import_js(theme.static_prefix.internal_js, 'openkounter.js', 'defer') %> + <% } else if (theme.footer.statistics.source === 'busuanzi') { %> <% if (pv_texts.length >= 2) { %> <% import_js(theme.static_prefix.internal_js, 'leancloud.js', 'defer') %> - + <% } else if (theme.post.meta.views.source === 'openkounter') { %> + + <% import_js(theme.static_prefix.internal_js, 'openkounter.js', 'defer') %> + <% } else if (theme.post.meta.views.source === 'busuanzi') { %>