Ruby SDK

Install and integrate the ABMeter Ruby SDK

Installation

Add the abmeter gem to your Gemfile:

gem 'abmeter'

Then install it:

bundle install

Configuration

Configure the SDK with your API key. In a Rails app, place this in an initializer (e.g. config/initializers/abmeter.rb):

ABMeter.configure do |config|
  config.api_key = ENV['ABMETER_API_KEY']
end

The api_key is required. You can find or create API keys on the API Keys page (available after signing in).

Core Concepts

Parameters represent feature variations - a parameter has a set of possible values assigned to users through experiments or feature flags. Use resolve_parameter to get the value for a specific user.

Events are user actions you want to measure - page views, purchases, clicks. Track them with track_event to analyze how parameter variations affect user behavior.

Users are identified by a user_id - the randomization unit the SDK hashes to assign parameter values randomly across your users but consistently for each one, so the same user_id always sees the same variation (no stored state, no network call). A "user" is your end-user - a customer, visitor, or account - and user_id can be any string you choose (a customer id, visitor id, account id). An optional email may be provided; ABMeter uses it only for audience rules that target email patterns (e.g. @acme.com), never for identity or bucketing.

Resolve a Parameter

Create a user and resolve a parameter to get the assigned value:

user = ABMeter::User.new(user_id: 'user-123')

value = ABMeter.resolve_parameter(user: user, parameter_slug: 'checkout-button-color')
# => "blue" (the assigned variant's value for this parameter)

The return value is the parameter value from the variant assigned to this user. If no experiment or feature flag controls the parameter, the method returns nil.

email is optional and safe to omit - do so for anonymous or server-side users, such as front-end visitors keyed by a cookie id. Leaving it out raises no error: a user with no email simply never matches an audience that targets email patterns, so email-predicate feature flags and experiments don't apply to them. Every other path (random experiments, user-list audiences, event tracking) uses user_id alone. Pass an email only when you use email-pattern audiences: ABMeter::User.new(user_id: 'user-123', email: '[email protected]').

Track an Event

Record user actions to measure the impact of your experiments:

ABMeter.track_event('purchase', user.user_id, { price: 49.99, currency: 'USD' })

Events are queued and submitted asynchronously in batches, so tracking calls are fast and non-blocking. The third argument is a data hash with any properties relevant to your metrics.

Full Example

A realistic Rails controller showing parameter resolution and event tracking together:

class CheckoutController < ApplicationController
  before_action :resolve_abmeter_params

  def show
    # @button_color is set by the before_action
    render :show
  end

  def complete
    order = current_user.orders.create!(order_params)

    ABMeter.track_event('purchase', current_user.id, {
      price: order.total,
      currency: order.currency
    })

    redirect_to order_path(order)
  end

  private

  def resolve_abmeter_params
    abmeter_user = ABMeter::User.new(
      user_id: current_user.id,
      email: current_user.email # optional, only used for email-predicate audiences
    )

    @button_color = ABMeter.resolve_parameter(
      user: abmeter_user,
      parameter_slug: 'checkout-button-color'
    ) || 'green' # fallback if no experiment is running
  end
end

Next Steps