Split::Counters
August 29, 2014 ยท View on GitHub
An extension to Split to add counters per experiment and alternative.
Requirements
The split gem and its dependencies.
Setup
If you are using bundler add split to your Gemfile:
gem 'split-counters', :require => 'split/counters'
and if you want to use the separate 'counters' dashboard:
gem 'split-counters', :require => ['split/counters', 'split/countersdashboard']
Then run:
bundle install
Otherwise install the gem:
gem install split-counters
and require it in your project:
require 'split/counters'
Usage
A simple example in a Rails app could be:
def index
the_ab_test = ab_test("exp", "alt1", "alt2")
if !exclude_visitor?
ab_counter_inc("IndexViews", "exp", the_ab_test)
ab_counter_inc("PageViews", "exp", ab_test("exp", "alt1", "alt2"))
end
end
def other
the_ab_test = ab_test("exp", "alt1", "alt2")
if !exclude_visitor?
ab_counter_inc("OtherViews", "exp", the_ab_test)
ab_counter_inc("PageViews", "exp", ab_test("exp", "alt1", "alt2"))
end
end
Counter Dashboard

To enable the 'counters' dashboard (and the Split dashboard), add this to your routes:
class Whitelist
def matches?(request)
(request.remote_ip == '127.0.0.1') || (Rails.env == 'development')
end
end
mount Split::Dashboard, :at => 'split', :constraints => Whitelist.new
mount Split::Countersdashboard, :at => 'splitcounters', :constraints => Whitelist.new
This will make the counters dashboard available at /splitcounters (in development mode or from 127.0.0.1).
Development
Source hosted at GitHub. Report Issues/Feature requests on GitHub Issues.
Tests can be run with rake spec
Note on Patches/Pull Requests
- Fork the project.
- Make your feature addition or bug fix.
- Add tests for it. This is important so I don't break it in a future version unintentionally.
- Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
- Send me a pull request. Bonus points for topic branches.
Copyright
Copyright (c) 2014 Bernard Kroes. See LICENSE for details.