0

I'm writing a blog application in Sinatra, and I want to collect some visit statistics.

As of now, I'm only thinking of getting more or less reliable visit statistics per user (that is, page visits grouped by users). Maybe later I'll want to get some client-related information (i.e., user agent).

How do I do that?

art-solopov
  • 4,289
  • 3
  • 25
  • 44

2 Answers2

4

While you can use Sinatra to do this, the technology has already been implemented in other ways. I think the easiest solution is to put a piece of Javascript on the frontend that records this information for you. The most popular library for doing this is Google Analytics. This will give you far more information than you could easily capture yourself (screen size, device, etc..), and in a very clean format.

NolanDC
  • 1,041
  • 2
  • 12
  • 35
  • 2
    Or New Relic, which supports Sinatra. – Mark Thomas Nov 30 '14 at 00:58
  • To be honest, I don't trust Google a lot. Or any analytics service. Plus, they'll get blocked really quickly by anyone using Ghostery or another similar extension. – art-solopov Dec 01 '14 at 15:17
  • The percentage of users who have Javascript disabled is small enough to be negligible. You could roll your own JS solution that posted results to a backend API. – NolanDC Dec 02 '14 at 02:21
0

My idea to do it:

  • Use Rack sessions to determine the visitor ID;
  • Store the hits in a database table
  • Write a Thor task to unload it into something human-readable.

I'll appreciate any critique of this idea and/or any other ideas to do it.

art-solopov
  • 4,289
  • 3
  • 25
  • 44
  • 1
    I think you'll find it very difficult to get the kind of information an analytics site normally offers (geography, bounce rate, etc..) using this method. Additionally, your app now has at least 1 write to the database for every single call, which may cause some performance problems. If neither of these are issues, your proposed solution sounds like a good start! You could even write a web-frontend that displayed the statistics prettily, instead of needing a Thor task to export them. – NolanDC Dec 02 '14 at 02:22
  • @NolanDC Will it be better if I write the hits into a logfile instead of a database (I'm using PostgreSQL, if it helps). – art-solopov Dec 02 '14 at 11:09
  • 1
    I would suggest using Postgres for now to make things easier. If the performance does become a problem, you can look into other methods (log-files, asynchronous jobs, etc..). It's usually not worth planning for problems that will most likely not occur. – NolanDC Dec 02 '14 at 16:45