开发者

How do I see real-time activity of my users in Rails 3?

开发者 https://www.devze.com 2023-02-13 08:19 出处:网络
What I would like to do is have my admin user be able to see - in real time (via some AJAX/jQuery niceness) - what my user\'s are doing.

What I would like to do is have my admin user be able to see - in real time (via some AJAX/jQuery niceness) - what my user's are doing.

How do I go about doing that ?

I assume it has something to do with session activity - and I have started saving the session to the db, rather than the cookie.

But generally speaking, how do I ta开发者_Python百科ke that info and parse it in real time ?

I looked at my session table and aside from the ids (id and session_id), I see a 'data' field. That data field stores a hash - which I can't make any sense of (looks like an md5 hash).

How would I use that to see that User A just clicked on Link B, and right after that User B clicked on link A, etc. ?

Is there a gem - aside from rackamole - that might be able to help me?


You might want to check out Mixpanel. They are easy to setup and have some of what you are asking for.


The session data only contains the values stored in the session[]-hash from the user. It doesn't store which action/controller was called, so you don't know which "link was clicked".

Get the activity of your users:

Besides rackamole you have two options IMHO.

  • Use a before_filter in your ApplicationController to store the relevant info you are interested in. (Name of controller, action or URI, additional parameters and id of the logged in user for example).

  • Use an AJAX-call at the bottom of each page which posts back the info you are interested in (URI, id of logged in user, etc.) to your server. This allows faster response times from the server, as the info is stored after the page has already been delivered. Plus, you don't have to use a Rails-request to store it. The AJAX-request could also be calling a simple PHP-script writing the data to disk. This is much faster.

Storing this activity:

Store this data/info either in the database or in a logfile. The database will give your more flexibility like showing all actions from one user, or all visitors for one page, etc. The logfile solution will give you better performance.

Realtime vs. Oldschool:

As for pulling out your collected data in realtime, you have to build your own solution. To do this elegantly (without querying your server once a second to look if new data has arrived) you'll need another server process. Search for AJAX Push for more info.

Depending on your application I'd ask myself if realtime notifications for this are really necessary (because of all the hassles of setting this up).

To monitor the activity on your site, it should be enough to have a page listing the latest actions and manually refresh it (or refresh it automatically every ten seconds).


Maybe you can test https://github.com/raid5/acts_as_scribe#readme It works with Rails 3 too.

0

精彩评论

暂无评论...
验证码 换一张
取 消