在cloudflare上构建免费的网站统计
没有自己的云服务器,可以在cloudflare上构建应用或网站。本文记录了构建网站统计的过程中遇到的坑和解决方法。
Han-Analytics 是一个简单的网络分析跟踪器和仪表板,托管在 Cloudflare 上,可无成本稳定运行,每天可达 10 万次免费统计。无需域名、服务器、数据库,托管在 Cloudflare Pages 上即可快速部署网站分析仪表板。
详细部署步骤见*使用Cloudflare部署你的免费网站统计 – Web-Analytics*
这里只记录关键步骤。
Github操作-Fork 仓库
Cloudflare操作
记录帐号ID
找到左侧的“计算-Workers和Pages”,记录帐号ID。创建 Cloudflare API token
进入“域名-概述”,右下“获取您的 API 令牌”,创建自定义令牌,权限为:“帐户,帐户分析,读取”,记录令牌字符串。开启分析引擎
进入“存储和数据库-分析引擎”,

创建 Pages 项目
添加环境变量:
CLOUDFLARE_ACCOUNT_ID,CLOUDFLARE_API_TOKEN,值为前面记录的值。
CLOUDFLARE_WEBSITE_WHITELIST = 域名1,WebSite1|域名2,WebSite2 ,设置要统计的网站,不设置在仪表板上会显示Hello-HanAnalytics。
完成后部署项目(会失败)。配置-绑定
添加 “Analytics Engine”,变量名称填写 “AnalyticsBinding”,数据集填写 “AnalyticsDataset” 并保存,然后重新部署(再次失败)。
输出:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
472026-08-09T07:50:28.164066Z Cloning repository...
2026-08-09T07:50:29.414949Z From https://github.com/qs100371/HanAnalytics
2026-08-09T07:50:29.415248Z * branch 531c3edfce19a3ab31e5571ddf02b1ef6f2bef78 -> FETCH_HEAD
2026-08-09T07:50:29.415313Z
2026-08-09T07:50:29.475182Z HEAD is now at 531c3ed ✅
2026-08-09T07:50:29.475444Z
2026-08-09T07:50:29.515196Z
2026-08-09T07:50:29.515592Z Using v2 root directory strategy
2026-08-09T07:50:29.529925Z Success: Finished cloning repository files
2026-08-09T07:50:30.734558Z Checking for configuration in a Wrangler configuration file (BETA)
2026-08-09T07:50:30.735009Z
2026-08-09T07:50:30.881189Z No Wrangler configuration file found. Continuing.
2026-08-09T07:50:32.86083Z Detected the following tools from environment: npm@10.9.2, nodejs@22.16.0
2026-08-09T07:50:32.8613Z Installing project dependencies: npm install --progress=false
2026-08-09T07:50:50.412258Z npm warn deprecated lucide-vue-next@0.475.0: Package deprecated. Please use @lucide/vue instead.
2026-08-09T07:50:50.788966Z
2026-08-09T07:50:50.789221Z added 343 packages, and audited 344 packages in 17s
2026-08-09T07:50:50.789287Z
2026-08-09T07:50:50.789391Z 97 packages are looking for funding
2026-08-09T07:50:50.789452Z run `npm fund` for details
2026-08-09T07:50:50.791828Z
2026-08-09T07:50:50.792032Z 4 vulnerabilities (3 moderate, 1 high)
2026-08-09T07:50:50.792271Z
2026-08-09T07:50:50.792318Z To address all issues (including breaking changes), run:
2026-08-09T07:50:50.79235Z npm audit fix --force
2026-08-09T07:50:50.792378Z
2026-08-09T07:50:50.792406Z Run `npm audit` for details.
2026-08-09T07:50:50.852934Z Executing user command: npm run build
2026-08-09T07:50:51.12833Z
2026-08-09T07:50:51.128604Z > shadcn-vue@0.0.0 build
2026-08-09T07:50:51.12868Z > run-p type-check "build-only {@}" --
2026-08-09T07:50:51.128715Z
2026-08-09T07:50:51.318075Z
2026-08-09T07:50:51.318329Z > shadcn-vue@0.0.0 build-only
2026-08-09T07:50:51.318377Z > vite build
2026-08-09T07:50:51.318418Z
2026-08-09T07:50:51.33144Z
2026-08-09T07:50:51.331671Z > shadcn-vue@0.0.0 type-check
2026-08-09T07:50:51.331734Z > vue-tsc --build --force
2026-08-09T07:50:51.331821Z
2026-08-09T07:50:51.93918Z [36mvite v6.4.3 [32mbuilding for production...[36m[39m
2026-08-09T07:50:52.061136Z transforming...
2026-08-09T07:50:56.025987Z src/components/ui/toast/use-toast.ts(82,28): error TS2589: Type instantiation is excessively deep and possibly infinite.
2026-08-09T07:50:57.018681Z ERROR: "type-check" exited with 2.
2026-08-09T07:50:57.035043Z Failed: Error while executing user command. Exited with error code: 1
2026-08-09T07:50:57.042103Z Failed: build command exited with code: 1
2026-08-09T07:50:57.642178Z Failed: error occurred while running build command
询问deepseek,给出的解决方法:
在 Cloudflare Pages 设置中跳过 TypeScript 检查:
1 进入 Cloudflare Pages 项目设置
2 找到 “Build settings”(构建设置)
3 修改构建命令为:npm run build-only
再次部署,成功!
仪表板
在https://xxx.pages.dev ,无梯子无法访问,需要绑定自己的域名来直接访问。
集成到网站
1 | <script defer src="https://xxxxxx.pages.dev/tracker.min.js" data-website-id="自定义网站唯一标识"></script> |
xxxxxx.pages.dev改成自定义的域名。






