This is a Ruby gem that allows you to integrate with the Mida platform for server-side A/B testing and feature flags.
gem install mida-sdk
To use the server-side A/B testing and feature flags code, follow these steps:
- Require the
Mida
class in your code:
require 'mida-sdk'
- Create an instance of the
Mida
class by providing your Mida project key:
mida = Mida.new('YOUR_PROJECT_KEY')
- Use the
get_experiment
method to retrieve the current version of an experiment for a user:
experiment_key = 'EXPERIMENT_KEY'
distinct_id = 'USER_DISTINCT_ID'
version = mida.get_experiment(experiment_key, distinct_id)
if version == 'Control'
# Handle Control logic
elsif version == 'Variant 1'
# Handle Variant 1 logic
elsif version == 'Variant 2'
# Handle Variant 2 logic
end
- Use the
set_event
method to log an event for a user:
event_name = 'EVENT_NAME'
distinct_id = 'USER_DISTINCT_ID'
mida.set_event(event_name, distinct_id)
For revenue tracking, you can use the set_event
method with the event name as 'Purchase' and include additional attributes:
event_name = 'Purchase'
distinct_id = 'USER_DISTINCT_ID'
properties = {
revenue: 99.99,
quantity: 1,
currency: 'USD'
}
mida.set_event(event_name, distinct_id, properties)
- Use the
set_attribute
method to set user attributes for a specific user:
distinct_id = 'USER_DISTINCT_ID'
attributes = {
gender: 'male',
company_name: 'Apple Inc'
}
mida.set_attribute(distinct_id, attributes)
- Use the
feature_enabled?
method to check if a feature flag is enabled for the current user:
feature_flag_key = 'FEATURE_FLAG_KEY'
is_enabled = mida.feature_enabled?(feature_flag_key)
if is_enabled
# Feature flag is enabled, perform corresponding actions
else
# Feature flag is disabled, perform alternative actions
end
- Use the
on_feature_flags
method to reload the feature flags for the current user:
mida.on_feature_flags
project_key
: (required) Your Mida project key.options
: (optional) A hash of additional options.
experiment_key
: (required) The key of the experiment you want to get the version of.distinct_id
: (required) The distinct ID of the user.
Returns the version of the experiment.
event_name
: (required) The name of the event you want to log.distinct_id
: (required) The distinct ID of the user.properties
: (optional) A hash containing additional event properties.
distinct_id
: (required) The distinct ID of the user.properties
: (required) A hash containing the attribute key-value pairs.
key
: (required) The key of the feature flag you want to check.
Returns a boolean indicating whether the feature flag is enabled or not.
distinct_id
: (optional) The distinct ID of the user.
Reloads the feature flags for the current user.
Bug reports and pull requests are welcome on GitHub at https://github.com/yourusername/mida-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
The gem is available as open source under the terms of the MIT License.