Sunday, 6 December 2009

A Click Heat Map plugin for ruby on rails applications

Hi Rubysts,

I've just finished my first contribution to the Ruby on Rails community this evening.
This contribution is actually the repackaging of the click heat map generator included within cannoli into an easy-to-install and deploy ruby on rails plugin.

If you take a look at cannoli you observe that it is based on ruwa web analytic ruby on rails app. I didn't need all of these together.
So... Did I manage to do something better? I believe that it is only rarely the case for something to be in every aspects better than something different. In this particular case I would say that I have made a piece of ruby on rails building block which is less than cannoli but it can be extremely easily incorporated in your Rails ( >2.3.2 ) application.

It has it's own requirements:
  • you need Rmagick installed
  • you must have Rails 2.3.2

Maybe you want to improve your sites web usability.
In order to install the plugin:
  • ./script/plugin install git://github.com/orbanbotond/click_heat_map.git
From the click_heat_map plugin directory (not from rails root)
  • rake db:migrate:click_heat_map
Then you need to put and adapt this code into your templates:
< src="'/javascripts/overlay.js'" type="'text/javascript'">
< src="'/javascripts/clickmap.js'" type="'text/javascript'">


put this html code into your templates you want to measure:
< id="prova" style="margin:auto;width:800px;height:1px;">

And finally, you reached the point where you want to deploy your rails app using capistrano.
Maybe you ask yourself how capistrano knows how to migrate your plugin to the remote server.
Well...
In my case I put the installed plugin under version control and Capistrano just copied to the remote server.
I also created a file named
20091130000000_create_heat_map_clicks.rb:
require 'vendor/plugins/click_heat_map/lib/db/migrate/20091130000000_create_heat_map_clicks.rb'
This way capistrano creates the tables needed by the plugin on the remote server by running "cap deploy:migrations".

Finally the result makes me happy :)