{"id":30188756,"url":"https://github.com/brown9804/github-visitor-counter","last_synced_at":"2025-10-04T23:32:51.836Z","repository":{"id":303491892,"uuid":"1015669790","full_name":"brown9804/github-visitor-counter","owner":"brown9804","description":"This repository provides a customizable GitHub visitor counter that tracks and displays the number of visits to your GitHub profile or repository. The counter updates daily using the GitHub Traffic API and writes the total views directly into the README file.","archived":false,"fork":false,"pushed_at":"2025-08-09T00:50:21.000Z","size":301,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-09T02:36:46.065Z","etag":null,"topics":["automation","from-api","github-counter","github-traffic-api"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/brown9804.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}},"created_at":"2025-07-07T21:29:09.000Z","updated_at":"2025-07-16T16:00:54.000Z","dependencies_parsed_at":"2025-08-01T03:04:38.137Z","dependency_job_id":null,"html_url":"https://github.com/brown9804/github-visitor-counter","commit_stats":null,"previous_names":["brown9804/github-visitor-counter"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/brown9804/github-visitor-counter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brown9804%2Fgithub-visitor-counter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brown9804%2Fgithub-visitor-counter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brown9804%2Fgithub-visitor-counter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brown9804%2Fgithub-visitor-counter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brown9804","download_url":"https://codeload.github.com/brown9804/github-visitor-counter/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brown9804%2Fgithub-visitor-counter/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270109033,"owners_count":24528775,"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","status":"online","status_checked_at":"2025-08-12T02:00:09.011Z","response_time":80,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["automation","from-api","github-counter","github-traffic-api"],"created_at":"2025-08-12T17:49:52.881Z","updated_at":"2025-10-04T23:32:51.740Z","avatar_url":"https://github.com/brown9804.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Open Source Visitor Counter\n\nCosta Rica\n\n[![GitHub](https://badgen.net/badge/icon/github?icon=github\u0026label)](https://github.com)\n[![GitHub](https://img.shields.io/badge/--181717?logo=github\u0026logoColor=ffffff)](https://github.com/)\n[brown9804](https://github.com/brown9804)\n\nLast updated: 2025-07-10\n\n----------\n\n\u003e This repository provides a customizable GitHub visitor counter that tracks and displays the number of visits to your GitHub profile or repository. The counter updates daily using the GitHub Traffic API and writes the total views directly into the README file.\n\n\u003e [!IMPORTANT]\n\u003e The GitHub Traffic API only provides traffic data for the last 14 days. This project is designed to persist and aggregate daily view counts, allowing you to maintain a historical visitor total beyond GitHub's 14-day window.\n\n## Features\n\n- **Daily-updated visitor counting**: Fetches real visitor data from the GitHub Traffic API.\n- **Markdown-based display**: Updates the README file with the total visitor count.\n- **Open source and customizable**.\n\n## How it works\n\n\u003e [!IMPORTANT]\n\u003e This counter is updated once per day (not real-time) and shows the total number of visits (including repeat visits) as reported by GitHub.\n\n- A GitHub Action workflow runs daily to fetch visitor data from the GitHub Traffic API.\n- The action updates the `README.md` file with the total visitor count and the refresh timestamp.\n\n## How to use it\n\n1. **Add the Badge to Your Repository**: Include the following markdown in your `README.md` file, between the `START BADGE` and `END BADGE` (included), as shown in the bottom.\n2. **Create a Personal Access Token**:\n   - Go to **GitHub Settings** \u003e **Developer Settings** \u003e **Personal Access Tokens**.\n   - Generate a new token with `repo` access.\n3. **Save the Token as a Secret**:\n   - In your repository, navigate to **Settings** \u003e **Secrets and Variables** \u003e **Actions**.\n   - Add a new secret named `TRAFFIC_TOKEN` and paste the generated token.\n4. **Add the Pipeline**: This single pipeline will fetch the visitor count, update the badge in the `README.md` file, and push the changes back to the repository.\n   - Create a GitHub Actions workflow (`use-visitor-counter.yml`) in your repository to handle the visitor counter logic.\n   - Use the following content for the workflow, you can use [this pipeline as refence](https://github.com/brown9804/Cloud-DevOps-Overview/blob/main/.github/workflows/use-visitor-counter.yml).\n\n   ```yaml\n   name: Use Visitor Counter Logic\n   \n   on:\n     pull_request:\n       branches:\n         - main\n     schedule:\n       - cron: '0 0 * * *' # Runs daily at midnight\n     workflow_dispatch:  # Allows manual triggering\n   \n   permissions:\n     contents: write\n     pull-requests: write\n   \n   jobs:\n     update-visitor-count:\n       runs-on: ubuntu-latest\n   \n       steps:\n         - name: Checkout current repository\n           uses: actions/checkout@v4\n           with:\n             fetch-depth: 0\n   \n         - name: Shallow clone visitor counter logic\n           run: git clone --depth=1 https://github.com/brown9804/github-visitor-counter.git\n   \n         - name: Set up Node.js\n           uses: actions/setup-node@v4\n           with:\n             node-version: '20'\n   \n         - name: Install dependencies for github-visitor-counter\n           run: |\n             cd github-visitor-counter\n             npm ci\n   \n         - name: Run visitor counter logic (updates markdown badges and metrics.json)\n           run: node github-visitor-counter/update_repo_views_counter.js\n           env:\n             TRAFFIC_TOKEN: ${{ secrets.TRAFFIC_TOKEN }}\n             REPO: ${{ github.repository }}\n   \n         - name: Move generated metrics.json to root\n           run: mv github-visitor-counter/metrics.json .\n   \n         - name: List files for debugging\n           run: |\n             ls -l\n             ls -l github-visitor-counter\n   \n         - name: Clean up visitor counter logic\n           run: rm -rf github-visitor-counter\n   \n         - name: Configure Git author\n           run: |\n             git config --global user.name \"github-actions[bot]\"\n             git config --global user.email \"github-actions[bot]@users.noreply.github.com\"\n   \n         - name: Commit and push changes (PR)\n           if: github.event_name == 'pull_request'\n           env:\n             TOKEN: ${{ secrets.GITHUB_TOKEN }}\n           run: |\n             git fetch origin\n             git checkout -b ${{ github.event.pull_request.head.ref }} origin/${{ github.event.pull_request.head.ref }}\n             git add \"*.md\" metrics.json\n             git commit -m \"Update visitor count\" || echo \"No changes to commit\"\n             git remote set-url origin https://x-access-token:${TOKEN}@github.com/${{ github.repository }}\n             git pull --rebase origin ${{ github.event.pull_request.head.ref }} || echo \"No rebase needed\"\n             git push origin HEAD:${{ github.event.pull_request.head.ref }}\n   \n         - name: Commit and push changes (non-PR)\n           if: github.event_name != 'pull_request'\n           env:\n             TOKEN: ${{ secrets.GITHUB_TOKEN }}\n           run: |\n             git fetch origin\n             git checkout ${{ github.event.pull_request.head.ref }} || git checkout -b ${{ github.event.pull_request.head.ref }} origin/${{ github.event.pull_request.head.ref }}\n             git add \"*.md\" metrics.json\n             git commit -m \"Update visitor count\" || echo \"No changes to commit\"\n             git remote set-url origin https://x-access-token:${TOKEN}@github.com/${{ github.repository }}\n             git pull --rebase origin ${{ github.event.pull_request.head.ref }} || echo \"No rebase needed\"\n             git push origin HEAD:${{ github.event.pull_request.head.ref }}\n   \n         - name: Create Pull Request (non-PR)\n           if: github.event_name != 'pull_request'\n           uses: peter-evans/create-pull-request@v6\n           with:\n             token: ${{ secrets.GITHUB_TOKEN }}\n             branch: update-visitor-count\n             title: \"Update visitor count\"\n             body: \"Automated update of visitor count\"\n             base: main\n   ```\n\n## Files structure\n\n- `README.md`: Contains instructions and displays the visitor count badge.\n- `update_repo_views_counter.js`: Script to fetch visitor count data from the GitHub Traffic API and update the `README.md` file.\n- `package.json`: Defines dependencies and scripts for the project.\n- `LICENSE`: Specifies the license for the project.\n\n\u003e [!IMPORTANT]\n\u003e\n\u003e - Replace `\u003cmain-repo-owner\u003e` and `\u003cmain-repo-name\u003e` with your actual values.\n\u003e - Use a Personal Access Token (PAT) with `repo` access as `TRAFFIC_TOKEN` secret in each target repository.\n\u003e - The action will trigger the visitor counter logic in the main repository and update the badge dynamically.\n\n\u003c!-- START BADGE --\u003e\n\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"https://img.shields.io/badge/Total%20views-1280-limegreen\" alt=\"Total views\"\u003e\n  \u003cp\u003eRefresh Date: 2025-07-16\u003c/p\u003e\n\u003c/div\u003e\n\u003c!-- END BADGE --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrown9804%2Fgithub-visitor-counter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrown9804%2Fgithub-visitor-counter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrown9804%2Fgithub-visitor-counter/lists"}