Collecting data with Trackers and Webhooks

  1. Home
  2. Docs
  3. Collecting data with Trackers and Webhooks
  4. Trackers – collecting data from your own applications
  5. Ruby Tracker
  6. Initialization


Assuming you have completed the Ruby Tracker Setup for your Ruby project, you are ready to initialize the Ruby Tracker.

Requiring the module

Require the Ruby Tracker into your code like this:

require 'snowplow-tracker'
Code language: JavaScript (javascript)

You can now initialize tracker instances.

Creating a tracker

Initialize a tracker instance like this:

emitter ="") tracker =
Code language: PHP (php)

If you wish to send events to more than one emitter, you can provide an array of emitters to the tracker constructor.

This tracker will log events to There are four other optional parameters:

def initialize(endpoint, subject=nil, namespace=nil, app_id=nil, encode_base64=true)
Code language: JavaScript (javascript)

subject is a subject with which the tracker is initialized.

namespace is a name for the tracker which will be added to every event the tracker fires. This is useful if you have initialized more than one tracker. app_id is the unique ID for the Ruby application. encode_base64 determines whether JSONs in the querystring for an event will be base64-encoded.

So a more complete tracker initialization example might look like this:

initial_subject = emitter ="") tracker =, initial_subject, 'cf', 'ID-ap00035', false)
Code language: PHP (php)

Creating multiple trackers

Each tracker instance is completely sandboxed, so you can create multiple trackers as you see fit.

Here is an example of instantiating two separate trackers:

t1 =""), nil, "t1") t1.set_platform("cnsl") t1.track_page_view("") t2 =""), nil, "t2") t2.set_platform("cnsl") t2.track_screen_view("Game HUD", "23") t1.track_screen_view("Test", "23") # Back to first tracker
Code language: PHP (php)