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

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'

You can now initialize tracker instances.

Creating a tracker

Initialize a tracker instance like this:

emitter = SnowplowTracker::Emitter.new("d3rkrsqld9gmqf.cloudfront.net") tracker = SnowplowTracker::Tracker.new(emitter)

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 http://d3rkrsqld9gmqf.cloudfront.net/i. There are four other optional parameters:

def initialize(endpoint, subject=nil, namespace=nil, app_id=nil, encode_base64=true)

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 = SnowplowTracker::Subject.new emitter = SnowplowTracker::Emitter.new("d3rkrsqld9gmqf.cloudfront.net") tracker = SnowplowTracker::Tracker.new(emitter, initial_subject, 'cf', 'ID-ap00035', false)

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 = SnowplowTracker::Tracker.new(SnowplowTracker::AsyncEmitter.new("d3rkrsqld9gmqf.cloudfront.net"), nil, "t1") t1.set_platform("cnsl") t1.track_page_view("http://www.example.com") t2 = SnowplowTracker::Tracker.new(SnowplowTracker::AsyncEmitter.new("my-company.c.snplow.com"), nil, "t2") t2.set_platform("cnsl") t2.track_screen_view("Game HUD", "23") t1.track_screen_view("Test", "23") # Back to first tracker