{"id":13453372,"url":"https://github.com/yestool/analytics_with_cloudflare","last_synced_at":"2025-07-04T20:37:48.572Z","repository":{"id":210615649,"uuid":"726792704","full_name":"yestool/analytics_with_cloudflare","owner":"yestool","description":"a simple web analytics use Cloudflare workers + D1 + Huno. 👉 https://webviso.yestool.org","archived":false,"fork":false,"pushed_at":"2024-10-23T14:27:52.000Z","size":17,"stargazers_count":124,"open_issues_count":0,"forks_count":29,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-29T07:05:50.691Z","etag":null,"topics":["analytics","cloudflare-d1","cloudflare-workers","huno"],"latest_commit_sha":null,"homepage":"https://webviso.yestool.org","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yestool.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-12-03T12:23:10.000Z","updated_at":"2025-03-18T02:58:24.000Z","dependencies_parsed_at":null,"dependency_job_id":"c07205f0-fe4f-4158-aee3-ac204fa48dcb","html_url":"https://github.com/yestool/analytics_with_cloudflare","commit_stats":null,"previous_names":["yestool/analytics_with_cloudflare"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yestool%2Fanalytics_with_cloudflare","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yestool%2Fanalytics_with_cloudflare/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yestool%2Fanalytics_with_cloudflare/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yestool%2Fanalytics_with_cloudflare/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yestool","download_url":"https://codeload.github.com/yestool/analytics_with_cloudflare/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247305932,"owners_count":20917208,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["analytics","cloudflare-d1","cloudflare-workers","huno"],"created_at":"2024-07-31T08:00:38.948Z","updated_at":"2025-04-05T08:03:54.499Z","avatar_url":"https://github.com/yestool.png","language":"TypeScript","funding_links":[],"categories":["网站分析","📊 网站分析"],"sub_categories":[],"readme":"[简体中文](./README.zh-CN.md) · **English**\n\n# Web Visitor Analytics Service Based on Cloudflare + Huno + D1\n\n[Demo Site](https://webviso.yestool.org/)\n\n## Deployment Steps\n\n### Install Dependencies\n\n```bash\nnpm install -g wrangler\nnpm install hono\n```\n\n### Login\n\nRedirect to the Cloudflare web authorization page.\n\n```bash\nnpx wrangler login\n```\n\n### Create D1 Database: [web_analytics]\n\n\u003e The database name should be `web_analytics`, consistent with the name in `package.json`.\n\n```bash\nnpx wrangler d1 create web_analytics\n```\n\nAfter successful creation, it will display:\n\n```\n✅ Successfully created DB web_analytics\n\n[[d1_databases]]\nbinding = \"DB\" # available in your Worker on env.DB\ndatabase_name = \"web_analytics\"\ndatabase_id = \"\u003cunique-ID-for-your-database\u003e\"\n```\n\n### Configure Worker and Bind D1 Database\n\nWrite the `unique-ID-for-your-database` returned from the previous step into `wrangler.toml`.\n\n```toml\nname = \"analytics_with_cloudflare\"\nmain = \"src/index.ts\"\ncompatibility_date = \"2024-06-14\"\n\n[[d1_databases]]\nbinding = \"DB\" # available in your Worker on env.DB\ndatabase_name = \"web_analytics\"\ndatabase_id = \"\u003cunique-ID-for-your-database\u003e\"\n```\n\n### Initialize the D1 Database Schema\n\n```bash\nnpm run initSql\n```\n\n### Deploy\n\n```bash\nnpm run deploy\n```\n\nAfter successful deployment, it will display:\n\n```\n\u003e analytics_with_cloudflare@0.0.0 deploy\n\u003e wrangler deploy\n\nProxy environment variables detected. We'll use your proxy for fetch requests.\n ⛅️ wrangler 3.18.0\n-------------------\nYour worker has access to the following bindings:\n- D1 Databases:\n  - DB: web_analytics (\u003cunique-ID-for-your-database\u003e)\nTotal Upload: 50.28 KiB / gzip: 12.23 KiB\nUploaded analytics_with_cloudflare (1.29 sec)\nPublished analytics_with_cloudflare (4.03 sec)\n  https://analytics_with_cloudflare.xxxxx.workers.dev\nCurrent Deployment ID: xxxxxxxxxxxxxxxxxxxxxxxxxxxx\n```\n\n## How to Use\n\n\u003e - `data-base-url` default value: `https://webviso.yestool.org`\n\u003e - `data-page-pv-id` default value: `page_pv`\n\u003e - `data-page-uv-id` default value: `page_uv`\n\n### 1. Include the Script\n\nAdd the following `\u003cscript\u003e...\u003c/script\u003e` segment before the closing `\u003c/body\u003e` tag in your HTML.\n\n- Using the online JS file:\n\u003e With the defer attribute, the browser will execute these scripts after all content is loaded.\n\n```html\n\u003cscript defer src=\"//webviso.yestool.org/js/index.min.js\"\u003e\u003c/script\u003e\n```\n\n- Using a local JS file:\n\n```html\n\u003cscript src=\"/front/dist/index.min.js\"\u003e\u003c/script\u003e\n```\n\n- If you have deployed your backend, use your service address to send requests to your own service.\n\u003e Change `your-url` to your worker address, like `https://analytics_with_cloudflare.workers.dev`, and ensure there is no trailing `/`.\n\n```html\n\u003cscript defer src=\"//webviso.yestool.org/js/index.min.js\" data-base-url=\"your-url\"\u003e\u003c/script\u003e\n```\n\n### 2. Display Data\n\n- Add tags with the ID `page_pv` or `page_uv` to show `Page Views (pv)` or `Unique Visitors (uv)` respectively.\n\n```html\nPage Views on this page:\u003cspan id=\"page_pv\"\u003e\u003c/span\u003e\n\nUnique Visitors on this page:\u003cspan id=\"page_uv\"\u003e\u003c/span\u003e\n```\n\n- You can edit the script parameters to adjust the tag IDs.\n\n```html\n\u003cscript defer src=\"//webviso.yestool.org/js/index.min.js\" data-base-url=\"your-url\" data-page-pv-id=\"page_pv\" data-page-uv-id=\"page_uv\"\u003e\u003c/script\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyestool%2Fanalytics_with_cloudflare","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyestool%2Fanalytics_with_cloudflare","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyestool%2Fanalytics_with_cloudflare/lists"}