public
Description: Simple logging of user events for later reporting
Homepage:
Clone URL: git://github.com/ffmike/user_event_logger.git
name age message
file MIT-LICENSE Fri Jul 25 17:38:37 -0700 2008 Initial project creation [ffmike]
file README Sun Sep 07 09:29:45 -0700 2008 Added ability to handle extra columns in the ev... [ffmike]
file Rakefile Fri Jul 25 17:38:37 -0700 2008 Initial project creation [ffmike]
directory generators/ Sun Jul 27 05:49:14 -0700 2008 Reasonably working code. Still needs tests. Bad... [ffmike]
file init.rb Sat Aug 16 06:35:29 -0700 2008 Gem-ified plugin [ffmike]
file install.rb Fri Jul 25 17:38:37 -0700 2008 Initial project creation [ffmike]
directory lib/ Sun Sep 07 09:29:45 -0700 2008 Added ability to handle extra columns in the ev... [ffmike]
directory rails/ Sat Aug 16 06:35:29 -0700 2008 Gem-ified plugin [ffmike]
directory tasks/ Fri Jul 25 17:38:37 -0700 2008 Initial project creation [ffmike]
directory test/ Fri Sep 12 06:23:24 -0700 2008 Fix tests so they actually run from the command... [ffmike]
file uninstall.rb Fri Jul 25 17:38:37 -0700 2008 Initial project creation [ffmike]
file user_event_logger.gemspec Sun Sep 07 09:29:45 -0700 2008 Added ability to handle extra columns in the ev... [ffmike]
README
UserEventLogger
===============

This plugin is extracted from several applications where I had similar problems:
tracking various things that users did within the application. For example, I've
used this to be able to log outgoing clicks without hooking up an analytics package,
to count the number of times an ad was displayed, or to keep track of how often
a particular page was visited.

To use the plugin, you must first create the table that it uses:

./script/generate user_event_logger add_event_table
rake db:migrate

After that, you can add information to the table from either your controllers or
your views:

log_user_event "In controller", "http://example.com", "27"
<%= log_user_event "In view", "http://example.com", "27" %>

The first argument is the event name, which is required. The second is the
destination URL, which is optional. The third is arbitrary extra data, which is
optional. The extra data is stored in a text column, so you can add as much
as you want here.

Reporting is left as an exercise for the user. The events table has these columns:

create_table :events do |t|
  t.column  :source_url, :string
  t.column  :destination_url, :string
  t.column  :remote_ip, :string
  t.column  :logged_at, :datetime
  t.column  :extra_data, :text
  t.column  :event_type, :string
end

Example
=======

To do outgoing link tracking, you can set up a controller method similar to this one:

def send_to 
    @advertiser = Advertiser.find(params[:id])
    destination_url = @advertiser.website.sub(/^www/, "http://www")
    log_user_event "Clicked through", destination_url, params[:id]
    redirect_to destination_url
end 

Extra columns
=============
You can add extra application-specific columns to the events table if you like. To do so, modify
the migration to include the columns after you run the add_event_table rake task and before you
run the migration. Then you can pass a hash of extra options as part of the call to log_user_event:

log_user_event "In controller", "http://example.com", "27", {:user_id => 13, :product_id => 7}
<%= log_user_event "In view", "http://example.com", "27", {:user_id => 13, :product_id => 7} %>

Gem installation
================
If you are running rails 2.1 or above you can choose between a standard plugin install and a gem install. To
install as a gem, add this to your environment.rb file:
    
    config.gem 'ffmike-user_event_logger', :source => 'http://gems.github.com'
    
and then run:

    rake gems:install


Copyright (c) 2008 Michael A. Gunderloy, released under the MIT license