💾 Archived View for zvava.org › wiki › viewcounter.gmi captured on 2024-05-10 at 11:15:55. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2024-03-21)
-=-=-=-=-=-=-
created 2022/09/17 modified 2024/02/06 category software views 31
an ethical website view counter i wrote to deploy on this website
TODO: rewrite viewcounter in wren w/ wren-web
TODO: generate statistics table for gemini too
i wanted to have really basic analytics (if you can even call it that) on my website that A. don't track you and B. can be easily disabled by just disabling javascript
in about 130 lines of vanilla node.js, viewcounter listens to requests on a single path
if it is a GET request, a summary of all the page view counts are returned
if it is a POST request with a page path as a body, that page's view count is incremented
there are two mechanisms in place to prevent abuse of the system
firstly, the url is validated to make sure it's an actual url on the website and not idk a slur or something, of which the result is cached so further requests to the same url can be quickly processed
there is also a 24h ratelimit in place to prevent spam. each ip has a "profile" of when it has last visited a page, if that date is today* then their view is not counted, otherwise the view count is incremented and the date is set to today*
i use caddy to not only act as the web server, but also a reverse proxy to expose viewcounter at /api/viewcounter. it also automagically provisions ssl certificates the site and its subdomains!