2011-05-20 02:57:22 +00:00
|
|
|
![Impressionist Logo](https://github.com/charlotte-ruby/impressionist/raw/master/logo.png)
|
2011-02-04 04:13:41 +00:00
|
|
|
|
2012-03-12 17:03:45 +00:00
|
|
|
[![Build Status](https://secure.travis-ci.org/charlotte-ruby/impressionist.png?branch=master)](http://travis-ci.org/charlotte-ruby/impressionist)
|
|
|
|
|
2011-03-08 18:23:42 +00:00
|
|
|
impressionist
|
|
|
|
=============
|
2011-02-04 04:13:41 +00:00
|
|
|
|
2011-03-08 18:23:42 +00:00
|
|
|
A lightweight plugin that logs impressions per action or manually per model
|
2011-02-04 04:13:41 +00:00
|
|
|
|
2012-03-07 00:00:58 +00:00
|
|
|
--------------------------------------------------------------------------------
|
2011-02-04 04:13:41 +00:00
|
|
|
|
2011-03-08 18:23:42 +00:00
|
|
|
What does this thing do?
|
|
|
|
------------------------
|
2012-03-07 00:00:58 +00:00
|
|
|
Logs an impression... and I use that term loosely. It can log page impressions
|
|
|
|
(technically action impressions), but it is not limited to that. You can log
|
|
|
|
impressions multiple times per request. And you can also attach it to a model.
|
|
|
|
The goal of this project is to provide customizable stats that are immediately
|
|
|
|
accessible in your application as opposed to using Google Analytics and pulling
|
|
|
|
data using their API. You can attach custom messages to impressions. No
|
|
|
|
reporting yet.. this thingy just creates the data.
|
2011-02-12 00:56:49 +00:00
|
|
|
|
2011-03-08 18:23:42 +00:00
|
|
|
What about bots?
|
|
|
|
----------------
|
2012-03-07 00:00:58 +00:00
|
|
|
They are ignored. 1200 known bots have been added to the ignore list as of
|
|
|
|
February 1, 2011. Impressionist uses this list:
|
2011-02-12 00:56:49 +00:00
|
|
|
http://www.user-agents.org/allagents.xml
|
|
|
|
|
2011-03-08 18:23:42 +00:00
|
|
|
Installation
|
|
|
|
------------
|
2011-02-04 04:13:41 +00:00
|
|
|
Add it to your Gemfile
|
|
|
|
|
2011-03-08 18:23:42 +00:00
|
|
|
gem 'impressionist'
|
2011-02-04 04:13:41 +00:00
|
|
|
|
|
|
|
Install with Bundler
|
|
|
|
|
2011-03-08 18:23:42 +00:00
|
|
|
bundle install
|
2011-02-04 04:13:41 +00:00
|
|
|
|
|
|
|
Generate the impressions table migration
|
|
|
|
|
2011-03-08 18:23:42 +00:00
|
|
|
rails g impressionist
|
2011-02-04 04:13:41 +00:00
|
|
|
|
|
|
|
Run the migration
|
|
|
|
|
2011-03-08 18:23:42 +00:00
|
|
|
rake db:migrate
|
2011-02-04 04:13:41 +00:00
|
|
|
|
|
|
|
The following fields are provided in the migration:
|
|
|
|
|
2011-03-08 18:23:42 +00:00
|
|
|
t.string "impressionable_type" # model type: Widget
|
|
|
|
t.integer "impressionable_id" # model instance ID: @widget.id
|
|
|
|
t.integer "user_id" # automatically logs @current_user.id
|
|
|
|
t.string "controller_name" # logs the controller name
|
|
|
|
t.string "action_name" # logs the action_name
|
|
|
|
t.string "view_name" # TODO: log individual views (as well as partials and nested partials)
|
2011-03-08 18:28:09 +00:00
|
|
|
t.string "request_hash" # unique ID per request, in case you want to log multiple impressions and group them
|
|
|
|
t.string "session_hash" # logs the rails session
|
2011-03-08 18:23:42 +00:00
|
|
|
t.string "ip_address" # request.remote_ip
|
2011-06-03 16:08:24 +00:00
|
|
|
t.string "referrer" # request.referer
|
2011-03-08 18:23:42 +00:00
|
|
|
t.string "message" # custom message you can add
|
|
|
|
t.datetime "created_at" # I am not sure what this is.... Any clue?
|
|
|
|
t.datetime "updated_at" # never seen this one before either.... Your guess is as good as mine??
|
|
|
|
|
|
|
|
Usage
|
|
|
|
-----
|
2011-02-12 14:50:42 +00:00
|
|
|
|
|
|
|
1. Log all actions in a controller
|
2011-02-04 04:13:41 +00:00
|
|
|
|
2011-03-08 18:23:42 +00:00
|
|
|
WidgetsController < ApplicationController
|
|
|
|
impressionist
|
|
|
|
end
|
2011-02-04 04:13:41 +00:00
|
|
|
|
2011-02-12 14:50:42 +00:00
|
|
|
2. Specify actions you want logged in a controller
|
2011-02-04 04:13:41 +00:00
|
|
|
|
2011-03-08 18:23:42 +00:00
|
|
|
WidgetsController < ApplicationController
|
|
|
|
impressionist :actions=>[:show,:index]
|
|
|
|
end
|
2011-02-04 04:13:41 +00:00
|
|
|
|
2012-03-07 00:00:58 +00:00
|
|
|
3. Make your models impressionable. This allows you to attach impressions to
|
|
|
|
an AR model instance. Impressionist will automatically log the Model name
|
|
|
|
(based on action_name) and the id (based on params[:id]), but in order to
|
|
|
|
get the count of impressions (example: @widget.impression_count), you will
|
|
|
|
need to make your model impressionalble
|
2011-02-04 04:13:41 +00:00
|
|
|
|
2011-03-08 18:23:42 +00:00
|
|
|
class Widget < ActiveRecord::Base
|
|
|
|
is_impressionable
|
|
|
|
end
|
2011-02-04 04:13:41 +00:00
|
|
|
|
2012-03-07 00:00:58 +00:00
|
|
|
4. Log an impression per model instance in your controller. Note that it is
|
|
|
|
not necessary to specify "impressionist" (usage #1) in the top of you
|
|
|
|
controller if you are using this method. If you add "impressionist" to the
|
|
|
|
top of your controller and also use this method in your action, it will
|
|
|
|
result in 2 impressions being logged (but associated with one request_hash)
|
2011-02-04 04:13:41 +00:00
|
|
|
|
2011-03-08 18:23:42 +00:00
|
|
|
def show
|
|
|
|
@widget = Widget.find
|
|
|
|
impressionist(@widget,message:"wtf is a widget?") #message is optional
|
|
|
|
end
|
2011-02-04 04:13:41 +00:00
|
|
|
|
2012-03-07 00:00:58 +00:00
|
|
|
5. Get unique impression count from a model. This groups impressions by
|
|
|
|
request_hash, so if you logged multiple impressions per request, it will
|
|
|
|
only count them one time. This unique impression count will not filter out
|
|
|
|
unique users, only unique requests
|
2011-05-31 13:36:34 +00:00
|
|
|
|
2011-06-03 16:08:24 +00:00
|
|
|
@widget.impressionist_count
|
|
|
|
@widget.impressionist_count(:start_date=>"2011-01-01",:end_date=>"2011-01-05")
|
|
|
|
@widget.impressionist_count(:start_date=>"2011-01-01") #specify start date only, end date = now
|
2011-02-17 14:55:15 +00:00
|
|
|
|
2012-03-07 00:00:58 +00:00
|
|
|
6. Get the unique impression count from a model filtered by IP address. This
|
|
|
|
in turn will give you impressions with unique request_hash, since rows with
|
|
|
|
the same request_hash will have the same IP address.
|
2011-05-31 13:36:34 +00:00
|
|
|
|
2011-06-03 16:08:24 +00:00
|
|
|
@widget.impressionist_count(:filter=>:ip_address)
|
2011-10-29 22:24:57 +00:00
|
|
|
|
2012-03-07 00:00:58 +00:00
|
|
|
7. Get the unique impression count from a model filtered by session hash. Same
|
|
|
|
as #6 regarding request hash. This may be more desirable than filtering by
|
|
|
|
IP address depending on your situation, since filtering by IP may ignore
|
|
|
|
visitors that use the same IP. The downside to this filtering is that a
|
|
|
|
user could clear session data in their browser and skew the results.
|
2011-05-31 13:36:34 +00:00
|
|
|
|
2011-06-03 16:08:24 +00:00
|
|
|
@widget.impressionist_count(:filter=>:session_hash)
|
2011-10-29 22:24:57 +00:00
|
|
|
|
2012-03-07 00:00:58 +00:00
|
|
|
8. Get total impression count. This may return more than 1 impression per http
|
|
|
|
request, depending on how you are logging impressions
|
2011-05-31 13:36:34 +00:00
|
|
|
|
2011-06-03 16:08:24 +00:00
|
|
|
@widget.impressionist_count(:filter=>:all)
|
2011-02-04 04:13:41 +00:00
|
|
|
|
2012-03-07 00:00:58 +00:00
|
|
|
Logging impressions for authenticated users happens automatically. If you have
|
|
|
|
a current_user helper or use @current_user in your before_filter to set your
|
|
|
|
authenticated user, current_user.id will be written to the user_id field in the
|
|
|
|
impressions table.
|
2011-02-10 21:20:51 +00:00
|
|
|
|
2011-10-29 22:24:57 +00:00
|
|
|
Adding a counter cache
|
|
|
|
----------------------
|
2012-03-07 00:00:58 +00:00
|
|
|
Impressionist makes it easy to add a `counter_cache` column to your model. The
|
|
|
|
most basic configuration looks like:
|
2011-10-29 22:24:57 +00:00
|
|
|
|
2011-11-28 04:43:30 +00:00
|
|
|
is_impressionable :counter_cache => true
|
2011-10-29 22:24:57 +00:00
|
|
|
|
2012-03-07 00:00:58 +00:00
|
|
|
This will automatically increment the `impressions_count` column in the
|
|
|
|
included model. Note: You'll need to add that column to your model. If you'd
|
|
|
|
like specific a different column name, you can:
|
2011-10-29 22:24:57 +00:00
|
|
|
|
2011-11-28 04:43:30 +00:00
|
|
|
is_impressionable :counter_cache => { :column_name => :my_column }
|
2011-10-29 22:24:57 +00:00
|
|
|
|
|
|
|
If you'd like to include only unique impressions in your count:
|
|
|
|
|
2011-11-28 04:43:30 +00:00
|
|
|
is_impressionable :counter_cache => { :column_name => :my_column, :unique => true }
|
2011-02-10 21:20:51 +00:00
|
|
|
|
2011-11-27 19:39:29 +00:00
|
|
|
What if I only want to record unique impressions?
|
|
|
|
-------------------------------------------------
|
2012-03-07 00:00:58 +00:00
|
|
|
Maybe you only care about unique impressions and would like to avoid
|
|
|
|
unnecessary database records. You can specify conditions for recording
|
|
|
|
impressions in your controller:
|
2011-11-27 19:39:29 +00:00
|
|
|
|
2011-11-27 19:51:51 +00:00
|
|
|
# only record impression if the request has a unique combination of type, id, and session
|
|
|
|
impressionist :unique => [:impressionable_type, :impressionable_id, :session_hash]
|
2011-11-27 19:39:29 +00:00
|
|
|
|
2011-11-27 19:51:51 +00:00
|
|
|
# only record impression if the request has a unique combination of controller, action, and session
|
|
|
|
impressionist :unique => [:controller_name, :action_name, :session_hash]
|
2011-11-27 19:39:29 +00:00
|
|
|
|
2011-11-27 19:51:51 +00:00
|
|
|
# only record impression if session is unique
|
|
|
|
impressionist :unique => [:session_hash]
|
2011-11-27 19:39:29 +00:00
|
|
|
|
|
|
|
Or you can use the `impressionist` method directly:
|
|
|
|
|
2011-11-27 19:51:51 +00:00
|
|
|
impressionist(impressionable, "some message", :unique => [:session_hash])
|
2011-11-27 19:39:29 +00:00
|
|
|
|
2011-03-08 18:23:42 +00:00
|
|
|
Development Roadmap
|
|
|
|
-------------------
|
2012-03-07 00:00:58 +00:00
|
|
|
* Automatic impression logging in views. For example, log initial view, and
|
|
|
|
any partials called from initial view
|
|
|
|
* Customizable black list for user-agents or IP addresses. Impressions will be
|
|
|
|
ignored. Web admin as part of the Engine.
|
2011-02-04 04:13:41 +00:00
|
|
|
* Reporting engine
|
|
|
|
* AB testing integration
|
|
|
|
|
2011-03-08 18:23:42 +00:00
|
|
|
Contributing to impressionist
|
2011-10-29 22:24:57 +00:00
|
|
|
-----------------------------
|
2012-03-07 00:00:58 +00:00
|
|
|
* Check out the latest master to make sure the feature hasn't been implemented
|
|
|
|
or the bug hasn't been fixed yet
|
|
|
|
* Check out the issue tracker to make sure someone already hasn't requested it
|
|
|
|
and/or contributed it
|
2011-02-04 04:13:41 +00:00
|
|
|
* Fork the project
|
|
|
|
* Start a feature/bugfix branch
|
|
|
|
* Commit and push until you are happy with your contribution
|
2012-03-07 00:00:58 +00:00
|
|
|
* Make sure to add rpsec tests for it. Patches or features without tests will
|
|
|
|
be ignored. Also, try to write better tests than I do ;-)
|
|
|
|
* If adding engine controller or view functionality, use HAML and Inherited
|
|
|
|
Resources.
|
|
|
|
* All testing is done inside a small Rails app (test_app). You will find specs
|
|
|
|
within this app.
|
2011-02-04 04:13:41 +00:00
|
|
|
|
2011-11-28 04:47:33 +00:00
|
|
|
Contributors
|
|
|
|
------------
|
2012-03-07 00:02:57 +00:00
|
|
|
* [johnmcaliley](https://github.com/johnmcaliley)
|
|
|
|
* [coryschires](https://github.com/coryschires)
|
|
|
|
* [georgmittendorfer](https://github.com/georgmittendorfer)
|
2011-11-28 04:47:33 +00:00
|
|
|
|
2011-06-03 16:08:24 +00:00
|
|
|
Copyright (c) 2011 John McAliley. See LICENSE.txt for further details.
|