The guy of the DontTrustThisGuy blog wanted to share his code of a basic statistics application he built for a client that offers a website affiliate program. So he wrote a post entitled "I’m on Rails: Coding Statistics" where he shows a good illustration of how to tackle a cumbersome project relatively easily. He gave 3 functions:

1- send_to: logs the click through information and sends the user off on their happy way
2- index: Logging unique visitor information as well as the page impression itself
3- report: Display user stats.
4- stats: to pull the hits, clicks, and visits for a specific time length and return them in a hash

The full article is here: http://www.donttrustthisguy.com/2006/02/05/im-on-rails-coding-statistics/