Install our Ruby Gem in order to send events and traits to Replay.io from your server using Ruby.
Add this line to your application’s Gemfile:
And then execute:
$ bundle install
Or install it yourself as:
$ gem install replay_api
See GitHub for more detailed information on configuring the library and its usage.
First, configure the library with your
replay_key. In Rails this is best done
in an initializer. Outside of Rails, it just needs to happen before you start
sending events and traits.
ReplayApi.configure do |config| config.replay_key = 'xxx-xxx-xxx-xxx' end
You may opt to create a globally accessible instance of the client or you can create a new one for each event. In either case, the mechanism for sending events and traits is the same.
Send an Event
client = ReplayApi::Client.new client.event do |event| event.event_name = 'Purchase' event.distinct_id = user.id event.properties.amount = 100 end
Send a Trait
client = ReplayApi::Client.new client.trait do |trait| trait.distinct_id = user.id trait.properties.email = user.email end