I want to host a Jekyll blog using GitHub Pages. I have purchased a license to display a web font for up to 50.000 page views/month. I order to not violate this agreement, I need to implement some kind of mechanism to count page views, so that I can take action whenever I reached 50,000 page views.
I have some rather complicated ideas in my head. On the one hand, I was thinking about performing a call to some AWS Lambda function that counts each page view, and takes action if it is one too many. On the other hand, I learned that MyFonts, Linotype and other font shops offer some of their web fonts using a licensing model called "pay-as-you-go", in which case they do mandate their customers to use a page view counter they provide, so that they can charge continuously, whenever certain quotas are hit. Their customers add those page view counters to their web sites by linking to a unique CSS file hosted by the respective font shop.
However, since I am probably not the only one having to deal with this, I wonder how other people solve this. My ideas seem to be a little over the top for what really is just a page view counter.
Is there an easier way? How is it commonly done?
On GitHub.com, navigate to the main page of the repository. Under your repository name, click Insights. In the left sidebar, click Traffic.
Under your repository name, click Settings. In the "Code and automation" section of the sidebar, click Pages. Under "GitHub Pages", select the GitHub Pages visibility drop-down menu, then click a visibility. To see your published site, under "GitHub Pages", click your site's URL.
There is a free API you can use with Javascript to do this. I wear it and it works like a glove.
Basically you create a key (namespace) and each post for this route it increments 1. Then you can restore this count for display.
https://javascript.plainenglish.io/how-to-count-page-views-with-the-count-api-afc9369c1f8f
https://countapi.xyz/
Another thought might be to use CloudFlare Worker to front the site and use Worker KV to track page views. Or, if you want to go further, that could also be your endpoint to count.
But assuming those vendors only count uncached requests, you could put your worker counter on the path of the font file to track how often the server is hit for those files. Then if you match the same cache-control policy as the vendor, you should have the same measuring system set up.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With