Vanity 1.3 adds support for Google Analytics thanks to Garb (the GA Ruby API) and much help from Tony Pitale.
You’ll need to include the garb gem in your configuration and establish a session (using username/password or OAuth token), like this:
Rails::Initializer.run do |config| gems.config "vanity" gems.config "garb" . . . config.after_initialize do require "garb" ga = YAML.load_file(Rails.root + "config/ga.yml") Garb::Session.login(ga['email'], ga['password'], account_type: "GOOGLE") end end
The rest is just a matter of figure out what metric you want to use:
metric "Acquisition: Visitors" do description "Unique visitors on any given page, as tracked by Google Analytics" google_analytics "UA-1828623-6", :visitors end
You can even use filters and much more, see the site for more details.
To use Vanity on a forking server (Passenger, Unicorn, etc), each child process must establish its own connection. When you use Vanity 1.3 with Passenger it would do the right thing, but other servers need a helping hand. Here, for example, is a portion of config/unicorn.rb that reconnects ActiveRecord and Vanity.
after_fork do |server, worker| ActiveRecord::Base.establish_connection Vanity.playground.reconnect! end
Other worthy fixes and improvements:
- New documentation page that covers everything you need to know setting up Vanity for Rails (http://vanity.labnotes.org/rails.html)
- Vanity query parameter (_vanity=?) that you can use to choose a particular alternative, e.g. to tie an advertisement banner with content of the site.
- Command line “vanity list” catalogs all ongoing experiments, their alternatives (and fingerprints) and all metrics.
- Vanity loads Redis configuration from config/redis.yml (if you have such a file).
- New way to specify connection configuration: Vanity.playground.redis = “localhost:6379″. Use this instead of the separate host/port/db attribute.
- Explicit vanity_context_filter and vanity_reload_filter so you can skip them, or order filters relative to them.
- If metric cannot be loaded (e.g. offline, no db access) show error message for that metric but don’t break dashboard.
- AbTest incorrectly calls identify method instead of identity (issue #2)
- Running vanity command, automatically detects and loads Rails.
- Vanity now picks up on load_path set from within config/environment.rb (issue #4)
- Vanity.playground.define is deprecated. Bad choice for a method name. If you need this feature, make a suggestion and let’s create a better API.