Ruby
1. Add Dependency
gem install hackle-ruby-sdk -v '~> 2.0.0'2. Initialize SDK
Hackle::Client must be a singleton.
Hackle::Client manages state internally to distribute A/B test and Feature Flag results without making network calls. This requires additional resources. Instead of creating a new instance for every request, it must be managed as a single instance throughout the application lifecycle.
To use the SDK, you need to initialize Hackle::Client.
Hackle::Clientis the class that provides methods for using the SDK's features.You can find your SDK Key in the SDK Integration Info section of the Hackle Dashboard.
require 'hackle-ruby-sdk'
hackle_client = Hackle::Client.create(sdk_key: 'YOUR_SERVER_SDK_KEY')Using the SDK with Rails
In Rails, initialize and shut down the SDK as follows.
# config/initializers/hackle_client.rb
$hackle_client = Hackle::Client.create(sdk_key: 'YOUR_SERVER_SDK_KEY')
at_exit { $hackle_client.close }Cluster Mode
When the application starts, the SDK creates multiple threads. Each thread has an infinite loop in the background that batch-processes and delivers events, and fetches A/B test information.
When using the SDK in a web server that spawns multiple child processes (e.g., Puma, Unicorn / workers > 0), the application server creates child processes but does not recreate threads that exist in the parent process.
Therefore, when running in cluster mode with Unicorn, Puma, etc., you need to create an additional SDK instance after child processes or workers are spawned.
Unicorn
Puma
3. Event Tracking
You can send user actions as events. Tracked events are used for A/B test analysis, data analytics, and more. For example, if a user makes a purchase, you can track the event as shown below.
Verifying Tracked Events
You can check tracked events in the Event Management menu on the Dashboard. It generally takes ~60 seconds for events to appear on the Dashboard after being tracked.
4. A/B Test
Distribute users into variations and implement logic based on the assigned variation to run A/B Tests. Call variation with the Experiment Key to receive the distribution result.
Experiment Key: A unique number assigned to each A/B test. It is automatically issued when you create an A/B test.
Cohort targeting is not supported in Server SDKs. If targeting includes a cohort, perform the test using a Client SDK.
5. Feature Flag
A Feature Flag has an on state and an off state. Implement different logic based on the state to use Feature Flags. Call is_feature_on with the Feature Key to receive the on/off status.
[Feature Key](../../기능 플래그/ff-manage/ff-detail.md): A unique number assigned to each Feature Flag. It is automatically issued when you create a Feature Flag.
6. Shutdown
When the application shuts down, call hackle_client.close to shut down the hackle_client.
This releases the resources in use by the client and sends any remaining events.
If the application exits without calling hackle_client.close, events may be lost.
Last updated