This quick start guide will get you up and running with the click_track plugin in just a few minutes.
Installing the Plugin
You would normally use the script/plugin utility that comes with Rails to install a plugin. However, that script assumes a repository layout that is different than the one used for the click_track plugin.
Therefore, you can export the plugin from its Subversion repository, check it out, or add it as a svn:externals.
svn export \
Once you have the click_track plugin installed in your vendor/plugins directory, you’ll want to generate the migration for the database changes:
script/generate click_track add_clicks
Tracking a Controller
For each controller you want tracked do this:
class FoobarController < ApplicationController
The click_track call takes the same arguments as a before_filter.
All actions called on this controller will be tracked. Views for this controller can now use click_track(..) in place of link_to(..) for tracking when an external link is followed.
How to Use the Data
Here is the table behind the Click model:
create_table :clicks do |t|
t.column :controller, :string, :null=>false
t.column :action, :string, :null=>false
t.column :param_id, :integer
t.column :ssl, :boolean, :null=>false
t.column :http_method, :string, :null=>false
t.column :remote_ip, :string, :null=>false
t.column :request_uri, :string, :null=>false
t.column :user_agent, :string
t.column :browser, :string
t.column :browser_version, :string
t.column :created_at, :datetime, :null=>false
Here are some examples of how one might use the data. These are taken from the statistics page of the crookedhidout.com site.
class StatisticsController < ApplicationController
@clicks = (Click.in_last(7.days) || )[0..12]
@popular_clicks = (Click.bucket_simple_uri_in_last(7.days) || )[0..8]
@fan_clicks = (Click.bucket_remote_ip_in_last(30.days) || )[0..8]
@last_24_count = Click.total_in_last 24.hours
This is going to grow my database forever!
Every one in ActionController::ClickTrack.chance times (default is 10,000) the DB will be cleared of all clicks older then ActionController::ClickTrack.oldest_click (default is 90.days). You can change these values in your config/environment.rb file. For example:
ActionController::ClickTrack.chance = 50000
ActionController::ClickTrack.oldest_click = 40.weeks
Monday, April 02, 2007