Wednesday 16 March 2016

Implementing an effective view/hit counter with node.

Firstly I am using the express framework to handle the back end. I've been in a bit of a stretch lately trying to come up with a scheme for a view counter that doesn't bloat the DB (using MongoDB).Ideally, what I would like is to have a day by day view counter of a certain sub domain. Think of say the individual github project pages with view counters. A view here counts as a first-time, unique page visit from an IP. Recurring visits will not increment the view counter.My non-ideal approach was to create a new collection say 'views' and the individual documents within views would have the following schema.{ "name" : String, "views" : [ { "day" : Date, "count" : Number, } ], "ips" : [String] } This is a sort of appropriate schema since I would like an easy way to check whether the IP has already requested this page, and I could log the views on a per day basis, but it just seems that in the long run traversing through the "views" array to obtain a particular day would become slower and slower. And not to mention the IP array, say if you were to accumulate 1 M views string comparison per visit would take a devastating toll on performance. Also remember this will be done on a per subdomain/entry basis which at this point it was best to reconsider my approach.So I come to you guys, any suggestions from prior experience are appreciated or better yet if you know of a module written to do this at a production scale that would be a gift, thanks.

Submitted March 17, 2016 at 03:10AM by markt5000

No comments:

Post a Comment