Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yestool/analytics_with_cloudflare
a simple web analytics use Cloudflare workers + D1 + Huno
https://github.com/yestool/analytics_with_cloudflare
analytics cloudflare-d1 cloudflare-workers huno
Last synced: about 1 month ago
JSON representation
a simple web analytics use Cloudflare workers + D1 + Huno
- Host: GitHub
- URL: https://github.com/yestool/analytics_with_cloudflare
- Owner: yestool
- License: mit
- Created: 2023-12-03T12:23:10.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-07-03T05:29:12.000Z (5 months ago)
- Last Synced: 2024-08-01T08:08:05.552Z (4 months ago)
- Topics: analytics, cloudflare-d1, cloudflare-workers, huno
- Language: TypeScript
- Homepage: https://webviso.yestool.org
- Size: 14.6 KB
- Stars: 88
- Watchers: 1
- Forks: 15
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-cloudflare - analytics_with_cloudflare - 极简网页计数器 相同。Webviso完全开源,你可以实现自定义需求。 基于Cloudflare的微服务架构可快速自行部署上线。 | <https://webviso.yestool.org/> |维护中| (网站分析)
README
[简体中文](./README.zh-CN.md) · **English**
# Web Visitor Analytics Service Based on Cloudflare + Huno + D1
[Demo Site](https://webviso.yestool.org/)
## Deployment Steps
### Install Dependencies
```bash
npm install -g wrangler
npm install hono
```### Login
Redirect to the Cloudflare web authorization page.
```bash
npx wrangler login
```### Create D1 Database: [web_analytics]
> The database name should be `web_analytics`, consistent with the name in `package.json`.
```bash
npx wrangler d1 create web_analytics
```After successful creation, it will display:
```
✅ Successfully created DB web_analytics[[d1_databases]]
binding = "DB" # available in your Worker on env.DB
database_name = "web_analytics"
database_id = ""
```### Configure Worker and Bind D1 Database
Write the `unique-ID-for-your-database` returned from the previous step into `wrangler.toml`.
```toml
name = "analytics_with_cloudflare"
main = "src/index.ts"
compatibility_date = "2024-06-14"[[d1_databases]]
binding = "DB" # available in your Worker on env.DB
database_name = "web_analytics"
database_id = ""
```### Initialize the D1 Database Schema
```bash
npm run initSql
```### Deploy
```bash
npm run deploy
```After successful deployment, it will display:
```
> [email protected] deploy
> wrangler deployProxy environment variables detected. We'll use your proxy for fetch requests.
⛅️ wrangler 3.18.0
-------------------
Your worker has access to the following bindings:
- D1 Databases:
- DB: web_analytics ()
Total Upload: 50.28 KiB / gzip: 12.23 KiB
Uploaded analytics_with_cloudflare (1.29 sec)
Published analytics_with_cloudflare (4.03 sec)
https://analytics_with_cloudflare.xxxxx.workers.dev
Current Deployment ID: xxxxxxxxxxxxxxxxxxxxxxxxxxxx
```## How to Use
> - `data-base-url` default value: `https://webviso.yestool.org`
> - `data-page-pv-id` default value: `page_pv`
> - `data-page-uv-id` default value: `page_uv`### 1. Include the Script
Add the following `...` segment before the closing `