Please reach out to MetaRouter before testing or implementing this library.


This library lets you record analytics data from your Ruby app's code. Once installed, the requests will be sent to the MetaRouter platform and then sent to the integrations you have configured for your pipeline that is connected to your Ruby events. The library is built for high performance and uses and internal queue to make all calls non-blocking and fast. It will batch messages and flush asynchronously to the MetaRouter platform.

Install the Gem

Install the Gem by either of these two methods:

  • Directly into a Gemfile
gem 'analytics-ruby', '~> 2.0.0', :require => 'metarouter/analytics'
  • Directly into environment gems
gem install analytics-ruby

Set Your writeKey

Inside your Ruby application, you'll want to set your pipeline's writeKey inside an instance of the Analytics object:

require 'metarouter/analytics'

analytics ={
  app_id: 'YOUR_WRITEKEY',
  host: 'YOUR_HOST_URL'

Required SDK Edits

In the above SDK, you will need to include your custom Host URL. Instructions for setting up your DNS, which includes the Host URL that you will insert into your SDK setup, can be found here. Your writeKey will indicate the specific pipeline you would like to feed your events into.

Event Methods in Ruby

Check out the below event methods and their use cases to determine the events that you need to trigger. We have also included examples of how you'd call specific objects in Ruby. More information on event methods can be found here.


The identify method helps you associate your users and their actions to a unique and recognizable userID and any optional traits that you know about them. We recommend calling an identify a single time - when the user's account is first created and only again when their traits change.

    user_id: '1234qwerty',
    traits: { email: "#{} user,email }", fingers: 10 },
    context: {ip: ''})



To get to a more complete event tracking analytics setup, you can add a track call to your website. This will tell MetaRouter which actions you are performing on your site. With track, each user action triggers an event, which can also have associated properties.

    user_id: `1234qwerty`,
    event: 'Add to cart'
    properties: {price: 50.00, color, 'Medium'}


The page method allows you to record page views on your website. It also allows you to pass addtional information about the pages people are viewing.
    user_id: user_id,
    category: Prod site
    name: 'Landing page'
    properties: { url: ''}


The group method associates an identified user with a company, organization, project, etc.
    user_id: '1234qwerty'
    group_id: '10'
    traits: { name: 'MetaRouter', description: 'Data Engineering Platform'}