Red
Red

Reputation: 2246

Statistics gathering in Rails 3.1 (Analytics)

I am building an analytics system for my rails application and I want to monitor every time I pull a certain object from the database, and I'd like to put the in the model file. I have objects that are being displayed on the page and I need to see the amount of views and clicks that they get. I assume the views can be handled by just figuring out when the object is pulled from the database (if someone could tell me how to do that) and I figured javascript to monitor the clicks. Would you all agree with this? Or is there a better way. I am using Rails 3.1 with MongoMapper and MongoDB

Upvotes: 0

Views: 215

Answers (1)

Tyler Brock
Tyler Brock

Reputation: 30136

To store the data simply send an ajax request from the browser with the information you want to store in a POST request to a rails resource like :click#create. Be sure to include the relevant data attributes within the request.

You may want to collect the requests and then send them all in a batch based on time or a use clicking a "done" button or something of that sort.

Recording the fact that someone clicked (from javascript) is different than recording when an object is retrieved from the database. You could write a before filter for each of the methods in the class or possibly implement an active record callback for something of that sort.

Upvotes: 1

Related Questions