Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement a basic page view counter for a GitHub-Pages-powered site? [closed]

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?

like image 493
lkbaerenfaenger Avatar asked Sep 01 '19 16:09

lkbaerenfaenger


People also ask

How do I see page views on GitHub?

On GitHub.com, navigate to the main page of the repository. Under your repository name, click Insights. In the left sidebar, click Traffic.

How do I see other peoples pages on GitHub?

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.


2 Answers

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/

like image 170
Douglas Medeiros Avatar answered Sep 20 '22 12:09

Douglas Medeiros


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.

like image 26
Sean-Roberts Avatar answered Sep 18 '22 12:09

Sean-Roberts