Hacker News new | past | comments | ask | show | jobs | submit login
How I built ghit.me, hit count badges for GitHub (benwilber.github.io)
55 points by benwilber0 on Dec 29, 2015 | hide | past | favorite | 18 comments



How does this deal with GitHub's caching of images?

https://github.com/blog/1766-proxying-user-images

They refer to it as "proxying", but they also call out that it proxies using their CDN, which seems to imply there isn't a 1:1 relationship between user requests and hits on the backend server


Github's proxy[1] respects Cache-Control headers, so it will just pass through since we use Etags and Cache-Control: no-cache.

[1]https://github.com/atmos/camo


Heh, someone should tell BitDeli[1]. They had to effectively shut down due to this, but if the fix is a simple as that then they will be hitting themselves.

Edit: Would it not be possible/better to just serve the SVG image direct from nginx? There is a LUA plugin, or even some direct redis stuff you could use.

1. https://bitdeli.com/


their analytics service still won't work since Github's camo proxy scrubs all cookies, referers, remote addrs, etc.

edit: and regarding lua or nginx redis2, yes you could certainly do that. I happen to like the asynchronous nature of incrementing hit counters outside of the request cycle and just using nginx to serve the static badge files. But yeah there are a bunch of ways to do this.


Interesting find!


I was about to post the exact same question as parent. I made a similar application to keep track of who was looking at my github repos. This is very helpful info! Thanks!


Back to geocities websites with hit counters! I like how it was implemented though, I simply hope I won't start seeing this everywhere from now on because it doesn't add anything to a repo to have that badge.


The only thing missing here is some tacky, irritating animation, but I've even seen that being rediscovered in some recently posted articles...


For anyone that is unaware, "hit count" functionality has been present in GitHub for at least several months. If you're the owner of a repository, you can view it at https://github.com/<username>/<repo>/graphs/traffic which gives you a breakdown of visitors, clones, referring sites, and which pages within your repository are popular.


Is there a way to make this cover a period of >2 weeks? I can only see 2 weeks of traffic for my repos.


If you ever wanted to filter by IP so you don't end up with tons of duplicates, it would be a nice usecase for the native hyperloglog support in Redis:

http://antirez.com/news/75

http://redis.io/commands/pfadd

http://redis.io/commands/pfcount


You can't, image urls on github are rewritten to be fetched trough a proxy.


If people fork/clone the repo, then wouldn't it also update the count on the main repo?


If anyone's trying to use ghit.me - beware that api rate limit from github is preventing the tool from working. May be, try again:

  {
    "message": "API rate limit exceeded for 107.170.25.70. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)",
    "documentation_url": "https://developer.github.com/v3/#rate-limiting"
  }


This got rate limited by github's API...


nice. I just added it to my hackernews chrome extension repo: https://github.com/boomeasy/hnlinks perhaps it will reach double digits by next year :-)


Cron? Syslog? Seriously? This could, in real-time and fewer lines of code, just directly get and increment a counter...


yep it's a pretty trivial task and there are a lot of ways to do it. i like just serving static files and incrementing hit counts outside of the request.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: