Impressionist Gem

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.

We're going to add Impressionist to an existing application to track how many views an Auction has. Impressionist has a very nice feature of ignoring views from over 1200 bots, all taken from this comprehensive list.

Add Gem to Gemfile.

Add the Gem to your Gemfile and run the bundle install command to install it.

gem 'impressionist'
$ bundle install

Run the Impressionist generator.

This will generate all of the fields Impressionist needs to keep track of hits.

rails g impressionist

Then run a database migration to make sure everything is run against your database.

rake db:migrate

Tie your model into the Impressionist functionality.

We're going to add the is_impressionable property to our Auction model to make sure Impressionist can track it's hits.

class Auction < ActiveRecord::Base
is_impressionable
end

Tell your controller what to keep track of.

In your controller, you can tell Impressionist what actions to count as a View.