Pathways allows you to see the pathways that users are using within your application. When we can see the flows through the app then we can pave the cowpaths and validate the features that we build.
Pathways uses your default Rails logger to store the information from a successful response so it doesn't slow our request/response cycle. We can then parse the logfile and store the results in a MongoDB database at a later date.
It has been created by those delightful fellows at Mint Digital.
Pathways was created so that we can understand the impact of our development on the behaviour of our users. Metrics shouldn't just be about page view counters it should understand where the user has been within that viewing session. By using a non relational database like MongoDB we can map_reduce all the pages that a user visits in a session so that we can truly analyse what is going on within our applications.
For the backstory, philosophy, and history of why we created Pathways, please see the blog post.
Pathways allows you to track the flow users take within your application. Each successful request is logged into your Rails.logger which can then be asynchronously parsed and stored in a MongoDB table later.
We store a user session (Pathways::Session) which has many visits (Pathways:Visit), these are MongoMapper documents which can be queried accordingly.
To start tracking the paths your users are taking all you need to do is add this to your controllers.
class ApplicationController
include Pathways::Tracker
after_filter :log_visit
end
This will create an entry in your default logfile that is later collected and parsed by Pathways.
You can also track the iteration/deployment that is currently running so that we can easily track the impact of each deployment.
class ApplicationController
include Pathways::Tracker
after_filter :log_visit
Pathways::Tracker.iteration = "iteration-001"
end
Now that we're tracking the paths our users take we need to parse these so that we can mine this like a mofo (note you might need to require 'pathways/parser').
Pathways::Parser.execute
This will run ever 5 seconds and create records for Pathways::Session and Pathways::Visits. By default this will look at the development.log using Rails.root.
If you want to specify the name of the logfile then you can pass it as the first parameter.
Pathways::Parser.execute("production")
You can also control the interval (in seconds) that parser will check your logfile, the default is set to 60 seconds.
Pathways::Parser.execute("production",10)
Pathways has a huge crush on Resque, so like Resque it comes with a Sinatra-based front end for seeing the sessions users are creating in your app.
If you've installed Pathways as a gem running the front end standalone is easy:
$ pathways-web
It's a thin layer around rackup
so it's configurable as well:
$ pathways-web -p 8282
Using Passenger? Pathways ships with a config.ru
you can use. See
Phusion's guide:
Apache: http://www.modrails.com/documentation/Users%20guide%20Apache.html#_deploying_a_rack_based_ruby_application Nginx: http://www.modrails.com/documentation/Users%20guide%20Nginx.html#deploying_a_rack_app
If you want to load Pathways on a subpath, possibly alongside other
apps, it's easy to do with Rack's URLMap
:
require 'pathways/server'
run Rack::URLMap.new \
"/" => Your::App.new,
"/pathways" => Pathways::Server.new
You can also easily mount Pathways on a subpath in your existing Rails 3 app by adding this to your routes.rb
:
require 'pathways/server'
mount Pathways::Server.new, :at => "/pathways"
Pathways requires MongoDB.
If you're on OS X, Homebrew is the simplest way to install MongoDB:
$ brew install mongodb
$ mongod run --config /usr/local/Cellar/mongodb/1.8.1-x86_64/mongod.conf
You now have a MongoDB instance running on 27017.
$ gem install bundler
$ bundle install
First install the gem.
$ gem install pathways
Next include it in your application.
$ cat config/initializers/load_pathways.rb
require 'pathways'
Now start your application:
$ ./script/server
Ta da! Your application is now logging the pathways your users make.
First include it in your Gemfile.
$ cat Gemfile
...
gem 'pathways'
...
Next install it with Bundler.
$ bundle install
Now start your application:
$ rails server
Ta da! Your application is now logging the pathways your users make.
Once you've made your great commits:
- Fork Pathways
- Create a topic branch -
git checkout -b my_branch
- Push to your branch -
git push origin my_branch
- Create a Pull Request from your branch
- That's it!
- Code:
git clone git://github.com/simonreed/pathways.git
- Bugs: http://github.com/simonreed/pathways/issues
Simon Reed :: [email protected] :: @simonreed