💾 Archived View for zvava.org › wiki › viewcounter.gmi captured on 2023-07-10 at 13:32:47. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-01-29)

➡️ Next capture (2023-11-04)

🚧 View Differences

-=-=-=-=-=-=-

🏡 go home...

📚 go back...

ethical view counter

thumbnail (stats.png)

created  2022/09/17
category software

an ethical website view counter i wrote to deploy on this website

📊 see it in action

source code

why?

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

how

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

preventing abuse

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*

deployment

i used to just have lighttpd providing http(s) but now i am able to use caddy[1] to not only act as the web server, but also a reverse proxy to combine both services into one website. it also provides ssl to the entire site automagically

cites

1. caddy