GitHub Pages visit counter

2021-09-04

You cannot get statistics such as visit count on GitHub Pages without a third-party solution, an external server/service. I wanted a rudimentary visit counter - not storing unnecessary or semiprivate data about the visitor such OS, etc., only visits and made a solution using an AWS serverless lambda storing data in a DynamoDB table. The solution is not specific to GitHub Pages, and could be used with any hosting that doesn’t allow you access to the server.

My solution saves visits this month (on which page), all-time(on which page), and the total number of visits. The data is presented in text format, either in the browser or using curl (or some other tool).

If someone would want to use it with AWS, change the value of GITHUB_PAGES_URL in src/functions/new-visit/handler.ts to your site, and add a GET-request to https://{GENERATED_AWS_URL}/dev/api/new-visit?url=${window.location.url}. View statistics from {GENERATED_AWS_URL}/dev/api/get-visits.

Data is presented in text but could you easily either go from this data or change the code to present in using a HTML table. This is how it can look:

$ curl {GENERATED_AWS_URL}/dev/api/get-visits


THIS MONTH
==========
https://bergsans.github.io/5    --      2
https://bergsans.github.io/3    --      1


ALL TIME
==========
https://bergsans.github.io/2    --      2
https://bergsans.github.io/1    --      3
https://bergsans.github.io/5    --      1


TOTAL
==========
11

AWS GitHub Pages visit counter @ GitHub.

About | Archive