EventLogger
EventLogger allows you to log events from anywhere in your Rails application. Once logged, these events can be used to run statistics on the types of events logged. Each event can store a serialized ruby object so you have access to detailed information regarding your event.
Installation
Add this line to your application's Gemfile:
gem 'event_logger'
And then execute:
$ bundle
Generate the event_logs table migration
$ rails g event_logger
Run the migration
$ rake db:migrate
Usage
All controllers have access to the log_event method. This method takes two arguments
- event (string)
- object (ruby object)
Anytime you wish to track an event use this method. For example, if we want to track failed user signups we would do this:
class RegistrationsController < ApplicationController
  def create
    ...
    log_event('user_signup_failed', current_user)
    ...
  end
endThis will later allow us to run analytics on these events. If we want to know the number of failed signups we just need to ask:
EventLogger::EventLog.where(:event => 'user_signup_failed').countWe also have full access to the objects within the event:
event = EventLogger::EventLog.where(:event => 'user_signup_failed').last
event.object
=> #<User first_name: "Ryan", last_name: "Howard">
event.object.first_name
=> "Ryan"Contributing
- Fork it
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create new Pull Request