The Customer Data Platform for Developers
Website · Documentation · Community Slack
The RudderStack Ruby SDK lets you send customer event data from your Ruby applications to your specified destinations.
- Set up a RudderStack open source account.
- Set up a Ruby source in the dashboard.
- Copy the write key and the data plane URL. For more information, refer to the Ruby SDK documentation.
To install the RudderStack Ruby SDK, add this line to your application's Gem file:
gem 'rudder-sdk-ruby'
You can also install the SDK into your environment gems by running the following command:
gem install 'rudder-sdk-ruby'
To use the Ruby SDK, create a client instance as shown:
require 'rudder-sdk-ruby'
analytics = Rudder::Analytics.new(
:write_key => 'WRITE_KEY',
:data_plane_url => 'DATA_PLANE_URL',
:gzip => true
)
Make sure to replace WRITE_KEY and DATA_PLANE_URL in the above snippet with the actual values from your RudderStack dashboard. |
---|
You can then use this client to send the events. A sample track
call sent using the client is shown below:
analytics.track(
:user_id => '1hKOmRA4GRlm',
:event => 'Item Sold',
:properties => { :revenue => 9.95, :shipping => 'Free' }
)
The Gzip feature is enabled by default in the Ruby SDK. However, you can disable this feature by setting the gzip
parameter to false while initializing the SDK:
analytics = Rudder::Analytics.new(
:write_key => 'WRITE_KEY', # required
:data_plane_url => 'DATA_PLANE_URL',
:gzip => false, // Set to true to enable Gzip compression
:on_error => proc { |error_code, error_body, exception, response|
# defaults to an empty proc
}
)
Note: Gzip requires rudder-server version 1.4 or later. Otherwise, your events might fail. |
---|
Refer to the RudderStack Ruby SDK documentation for more information on the supported event types.
Enable the stub
option while initializing the SDK to stub all the requests, making it easier for you to test with this library.
The RudderStack Ruby SDK is released under the MIT license.