Configuring the Playground
Vanity will work out of the box on a default configuration. Assuming you’re using Redis on localhost, post 6379, there’s nothing special to do.
Database connection information is loaded from config/vanity.yml
, based on the current environment (RACK_ENV
or RAILS_ENV
). Example:
development: adapter: redis connection: redis://localhost:6379/0 test: collecting: false production: adapter: mongodb database: analytics
If there’s no configuration file and the application does not create a connection explicitly, Vanity will default to the Redis instance running on localhost
at port 6379.
The available database adapters are:
- redis — This adapter is used by default. Available options are connection and password. host, port, database (defaults to 0) options are available, but deprecated.
- mongodb — Available options are host, port, database (defaults to “vanity”), username and password.
- active_record — Uses existing ActiveRecord configuration, by you can over-ride by supplying different options. To pick different underlying adapter, set active_record_adapter.
Configuration Options
Available configuration options are:
name | Is all about … | Default |
---|---|---|
add_participant_route | URL to use to add participants via JS | /vanity/add_participant |
collecting | False if you won’t want data collected | true |
config_file | File name to use to configure vanity | vanity.yml |
config_path | Path to the config_file | ./config/ |
environment | What environment use for configuration | development |
experiments_path | Directory containing experiment files | ./experiments |
failover_on_datastore_error | Whether to pass errors to on_datastore_error | false |
locales_path | Path to locales for translations | in the gem |
logger | This should be obvious | default/Rails |
on_datastore_error | A proc that handles datastore errors | logs to logger |
request_filter | A proc that returns whether to to ignore the request for the add JS participant route | Ignore requests with a HTTP_USER_AGENT that contain a URL |
templates_path | Path to templates for Vanity admin | the templates in the gem |
use_js | Whether to use JS to add particpants, useful to ignore bots | false |
experiments_start_enabled | Whether new experiments start in the enabled or disabled state | true |
cookie_name | The name of the anonymous tracking cookie | vanity_id |
cookie_expires | The duration of the cookie | 20 years |
cookie_domain | The domain for the cookie. Rails.application.config.session_options[:domain] will be substituted if nil . |
nil |
cookie_path | The path of the cookie | nil |
cookie_secure | The secure (ssl-only) parameter of the cookie. | false |
cookie_httponly | The httponly parameter of the cookie | false |
When running under Rails, Vanity defaults to using the Rails logger, locates the load_path relative to Rails root, uses the config/vanity.yml
configuration file (if present) and turns collection on only in production mode.
Use the playground object to configure Vanity. For example:
Vanity.configure do |config| config.use_js = true config.experiments_path = 'config/ab_tests' config.add_participant_route = '/vanity/participant/new' # ... end
Using metrics from Google Analytics
If you want to use Vanity with metrics from Google Analytics, you must require the garb
gem, and login for a new session. You’ll want to do that for production, not for development if you like developing offline. For example in Rails, in the config/:
config.after_initialize do require "garb" Garb::Session.login('..ga email..', '..ga pwd..', account_type: "GOOGLE") end