{"id":28259523,"url":"https://github.com/ambersun1234/count-page-views","last_synced_at":"2026-04-05T22:37:03.440Z","repository":{"id":253565834,"uuid":"843807841","full_name":"ambersun1234/count-page-views","owner":"ambersun1234","description":"Simple backend API server for retrieving page views with Google Analytics Data API","archived":false,"fork":false,"pushed_at":"2026-03-30T12:15:21.000Z","size":695,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-04-05T22:36:54.022Z","etag":null,"topics":["docker","docker-compose","express","google-analytics","helm-chart","kubernetes","nodejs","redis","skaffold"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ambersun1234.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-08-17T13:35:54.000Z","updated_at":"2026-03-30T12:15:22.000Z","dependencies_parsed_at":"2026-02-07T12:06:36.586Z","dependency_job_id":null,"html_url":"https://github.com/ambersun1234/count-page-views","commit_stats":null,"previous_names":["ambersun1234/count-page-views"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ambersun1234/count-page-views","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ambersun1234%2Fcount-page-views","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ambersun1234%2Fcount-page-views/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ambersun1234%2Fcount-page-views/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ambersun1234%2Fcount-page-views/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ambersun1234","download_url":"https://codeload.github.com/ambersun1234/count-page-views/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ambersun1234%2Fcount-page-views/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31452899,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-05T21:22:52.476Z","status":"ssl_error","status_checked_at":"2026-04-05T21:22:51.943Z","response_time":75,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["docker","docker-compose","express","google-analytics","helm-chart","kubernetes","nodejs","redis","skaffold"],"created_at":"2025-05-20T03:12:16.717Z","updated_at":"2026-04-05T22:37:02.481Z","avatar_url":"https://github.com/ambersun1234.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Count Page Views\n![](./img/view-number.png)\n\nThis repo is a simple backend server that retrieve the page count using [Google Analytics Data API](https://developers.google.com/analytics/devguides/reporting/data/v1?hl=zh-tw)\\\nThe tool is build to integrate with **static page** by default, specifically GitHub pages([Minimal Mistakes](https://mmistakes.github.io/minimal-mistakes/))\n\n## Features\n+ Aggregate page view count (include redirect URL)\n+ Cache page view count with Redis to prevent API rate limit\n    + The http response is also cached to prevent unnecessary API call, default to `1 day`(since the view count is not updated frequently by the Google Analytics)\n+ Easy deployment with Kubernetes(Helm Chart), Docker-Compose, or standalone\n\n## Prerequisites\n+ Enable [Google Analytics Data API](https://developers.google.com/analytics/devguides/reporting/data/v1?hl=zh-tw)\n+ Enable Google Analytics and have some page view data\n\n## Environment Variables\ncopy [.env.example](./.env.example) to `.env` and fill in the following variables\n\n| Name | Description |\n|:--|:--|\n| PORT | Port number of the server |\n| LOG_LEVEL | Log level of the server |\n| CORS | Allow origin url for CORS |\n| REDIS | Redis connection string |\n| GOOGLE_APPLICATION_CREDENTIALS | Path to the Google Cloud credential file |\n| ID | Google Analytics View ID |\n| START_DATE | Start date of the query |\n\n## API\n| Method | Path | Description | Query Parameters |\n|:--|:--|:--|:--|\n| GET | `/views` | Get the page view count | `url`: URL of the page |\n| POST | `/views` | Renew page view count for page ||\n\n## Build\n```shell\n$ make build\n```\n\n## Run\n### Standalone\n```shell\n$ make dev\n```\n\n### Docker-Compose\n```shell\n$ docker-compose build --no-cache\n$ docker-compose up -d\n```\n\n### Kubernetes\n```shell\n$ make docker-build\n$ make k3d-create\n$ make k3d-import\n$ make k3d-apply\n```\n\n### Helm\n```shell\n$ make docker-build\n$ make k3d-create\n$ make k3d-import\n$ helm install cpv charts/cpv\n```\n\n#### Skaffold\n```shell\n$ make k3d-create\n$ make skaffold-dev\n```\n\n## How to Use\nAs per introduction, this tool is designed to integrate with static page, specifically GitHub pages. So the following steps are based on it(Jekyll).\n\n```html\n\u003cspan\u003e\n    \u003ci class=\"fas fa-eye\" aria-hidden=\"true\"\u003e\u003c/i\u003e\n    Views: \u003cspan id=\"view-field\"\u003e Loading...\u003c/span\u003e\n\u003c/span\u003e\n```\n\n```html\n\u003cscript\u003e\n  fetch(`http://127.0.0.1:8888/views?url={{ page.url }}`)\n    .then(response =\u003e response.json())\n    .then(data =\u003e {\n      if (isNaN(data.views)) {\n        data.views = 0;\n      }\n      \n      document.getElementById(\"view-field\").innerHTML = Intl.NumberFormat('en', { notation: 'compact' }).format(data.views);\n    })\n    .catch(error =\u003e {\n      console.error(error)\n    });\n\u003c/script\u003e\n```\n\nPlace the above code snippet in the page you want to display the view count.\\\nPlease note that the `{{ page.url }}` is the Jekyll variable(written in [liquid](https://shopify.github.io/liquid/)) that represents the page URL, for example `/git/git-hook/`, it doesn't contain the domain name.\n\nAnd call the API to get the view count(remember to replace the URL with the actual backend).\n\n\u003e To beautify the view count, `Intl.NumberFormat` will format the number to a more readable format(e.g. `1.4k`).\n\nThe final result will look something like this\n![](./img/view-number.png)\nor\n![](./img/view-loading.png)\nif the backend server is not accessible at the time.\n\n## Author\n+ [ambersun1234](https://github.com/ambersun1234)\n\n## License\nThis project is licensed under Apache 2.0. See the [LICENSE](./LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fambersun1234%2Fcount-page-views","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fambersun1234%2Fcount-page-views","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fambersun1234%2Fcount-page-views/lists"}