Skip to content

Repository files navigation


Gem Version

Experiment Ruby SDK

Amplitude Ruby Server SDK for Experiment.

⚠️Local evaluation process fork safety: When using a LocalEvaluationClient and forking the process, you must call #startafter forking to update the flag configuration state on the new process. For example, in Puma, this means calling #start in the on_worker_boot hook.

Installation

Into Gemfile from rubygems.org:

gem'amplitude-experiment'

Into environment gems from rubygems.org:

geminstall'amplitude-experiment'

To install beta versions:

geminstallamplitude-experiment --pre

Remote Evaluation Quick Start

require'amplitude-experiment'# (1) Get your deployment's API keyapiKey='YOUR-API-KEY'# (2) Initialize the experiment clientexperiment=AmplitudeExperiment.initialize_remote(api_key)# (3) Fetch variants for a useruser=AmplitudeExperiment::User.new(user_id: 'user@company.com',device_id: 'abcezas123',user_properties: {'premium'=>true})# (4) Lookup a flag's variant# # To fetch asynchronousexperiment.fetch_async(user)do |_,variants|
variant=variants['YOUR-FLAG-KEY']unlessvariant.nil?ifvariant.value == 'on'# Flag is onelse# Flag is offendendend# To fetch synchronousvariants=experiment.fetch(user)variant=variants['YOUR-FLAG-KEY']unlessvariant.nil?ifvariant.value == 'on'# Flag is onelse# Flag is offendend

Local Evaluation Quick Start

require'amplitude-experiment'# (1) Get your deployment's API keyapiKey='YOUR-API-KEY'# (2) Initialize the experiment clientexperiment=AmplitudeExperiment.initialize_local(api_key)# (3) Start the local evaluation clientexperiment.start# (4) Evaluate a useruser=AmplitudeExperiment::User.new(user_id: 'user@company.com',device_id: 'abcezas123',user_properties: {'premium'=>true})variants=experiment.evaluate(user)variant=variants['YOUR-FLAG-KEY']unlessvariant.nil?ifvariant.value == 'on'# Flag is onelse# Flag is offendend

More Information

Please visit our 💯Developer Center for more instructions on using our the SDK.

See our Experiment Ruby SDK Docs for a list and description of all available SDK methods.

See our Local Evaluation Repo for more details about local evaluation binary logic.

Need Help?

If you have any problems or issues over our SDK, feel free to create a github issue or submit a request on Amplitude Help.

About

Amplitude Experiment Ruby Server SDK

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages