Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to go about creating in-house analytics for my Rails 3 app?

I have a Rails 3 app that I'm looking to create in-house analytics for. The items I need to track are impressions (and unique impressions), clicks that come from those impressions, and conversions that come from those clicks. And these are all user-specific so each user can see how many impressions, clicks, and conversions they've received.

What is the best way to go about this? Should I create a separate rails app and call it with pixels? Or should I include all the analytics code in the same app?

Also, are there any analytics platforms already out there that I can customize to meet my needs?

Thanks!

Tim

like image 587
Tim Avatar asked Jun 01 '11 23:06

Tim


2 Answers

Before you start re-inventing the wheel, Google Analytics provide a developer API (via OAuth, among other choices) that may provide you with the ability to do what you need (provide each user with a view of their own data).

http://code.google.com/apis/analytics/docs/gdata/home.html

Building your own, while it may seem like an initially basic thing to do, could have serious performance implications further down the line, and Google provide a very detailed view of the the data.

If you really want to write your own, I would strongly urge you not to hit the database for each request you want to track. Keep the data in Redis, or one of the alternatives and periodically persist it to the database via a background task.

like image 86
d11wtq Avatar answered Oct 02 '22 05:10

d11wtq


If, however, you don't want to put your data into the clutches of our Google Overlord :) then you might indeed consider rolling your own. I have twice before - and I'm doing it again right now: better this time, of course!

If your traffic is not very high and you're running on any decent server platform then adding a tracking system is not going to tax your Rails app noticeably (I know that depends on what 'decent server platform' means but this stuff is pretty cheap these days). Writing to a database is typically very fast - you'd have to have shedloads of clicks to not want to do this straightaway. You can probably bypass most if not all of your before_filters and so on to get a lightning response. One app that runs 2.3.9 uses Metal to do this, for example.

In my new tracking system I have an STI table that goes with models derived from an Activity model; in here you can record both impressions and clicks. Impressions are recorded as the page is built and clicks are recorded using AJAX.

I'm not going to bother with fancy graphs and so on - I'm happy with raw numbers - but these could be added, of course.

At the moment my system is just in the usual app/ folder but I'll probably move it to an engine so I can re-use it more easily.

Hope that helps!

BTW I use Google Analytics as well for a range of sites and it's OK - I just like to do this bit myself.

like image 33
qryss Avatar answered Oct 02 '22 06:10

qryss