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 and email. A "user" is your end-user - a customer, visitor, or account - you decide what it represents. The SDK uses these identifiers to deterministically assign parameter values, ensuring each user consistently sees the same variation.

Resolve a Parameter

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

user = ABMeter::Core::User.new(user_id: 'user-123', email: '[email protected]')

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.

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::Core::User.new(
      user_id: current_user.id,
      email: current_user.email
    )

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

Next Steps