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. Adding extra data

Adding extra data

You can configure the a tracker instance with additional information about your application’s environment or current user. This data will be attached to every event the tracker fires regarding the subject.

There are two ways to call methods from this tracker:

  • Call them on a Subject instance. They will update the data associated with that subject and return the subject.
  • Call them on the Tracker instance. They will update the data associated with the currently active subject for that tracker and return the tracker.

For example:

s0 = SnowplowTracker::Subject.new emitter = SnowplowTracker::Emitter.new("d3rkrsqld9gmqf.cloudfront.net") my_tracker = SnowplowTracker::Tracker.new(emitter, s0) # The following two lines are equivalent, except that the first returns s0 and the second returns my_tracker s0.set_platform('mob') my_tracker.set_platform('mob')

If you are using multiple subjects, you can use the set_subject tracker method to change which Subject instance is active:

s0 = SnowplowTracker::Subject.new emitter = SnowplowTracker::Emitter.new("d3rkrsqld9gmqf.cloudfront.net") my_tracker = SnowplowTracker::Tracker.new(emitter, s0) # Set the viewport for the active subject, s0 my_tracker.set_viewport(300, 500) # The data associated with s0 will be sent with this event my_tracker.track_screen_view('title page') # Create a new subject s1 = SnowplowTracker::Subject.new # Make s1 the active subject and set its viewport my_tracker.set_subject(s1).set_viewport(600,1000) # The data associated with s0 will be sent with this event my_tracker.track_screen_view('another page') # Change the subject back to s0 and track another event my_tracker.set_subject(s0).track_screen_view('final page')

Set the tracker’s platform with set_platform

The platform can be any one of 'pc''tv''mob''cnsl', or 'iot'. The default platform is 'srv'.

tracker.set_platform('mob')

Set the user ID with set_user_id

You can make the user ID a string of your choice:

tracker.set_user_id('user-000563456')

Set the screen resolution with set_screen_resolution

If your Ruby code has access to the device’s screen resolution, you can pass it into Snowplow. Both numbers should be positive integers; note the order is width followed by height. Example:

tracker.set_screen_resolution(1366, 768)

Set the viewport dimensions with set_viewport

Similarly, you can pass the viewport dimensions into Snowplow. Again, both numbers should be positive integers and the order is width followed by height. Example:

tracker.set_viewport(300, 200)

Set the color depth with set_color_depth

If your Ruby code has access to the bit depth of the device’s color palette for displaying images, you can pass it into Snowplow. The number should be a positive integer, in bits per pixel.

tracker.set_color_depth(24)

Setting the timezone with set_timezone

If your Ruby code has access to the timezone of the device, you can pass it into Snowplow:

tracker.set_timezone('Europe London')

Setting the language with set_lang

You can set the language field like this:

tracker.set_lang('en')

Setting the IP address with set_ip_address

If you have access to the user’s IP address, you can set it like this:

tracker.set_ip_address('34.633.11.139')

Setting the useragent with set_useragent

If you have access to the user’s useragent (sometimes called “browser string”), you can set it like this:

tracker.set_useragent('Mozilla/5.0 (Windows NT 5.1; rv:23.0) Gecko/20100101 Firefox/23.0')

Setting the domain user ID with set_domain_user_id

The domain_userid field of the Snowplow event model corresponds to the ID stored in the first party cookie set by the Snowplow JavaScript Tracker. If you want to match up server-side events with client-side events, you can set the domain user ID for server-side events like this:

tracker.set_domain_user_id('c7aadf5c60a5dff9')

You can extract the domain user ID from the Ruby on Rails cookies object like this:

def snowplow_cookie cookies.find { |(key, value)| key =~ /^_sp_id/ }.last end def domain_user_id if snowplow_cookie.present? snowplow_cookie.split('.').first end end

The first argument is the cookies object (see the documentation).

If you used the “cookieName” configuration option of the Snowplow JavaScript Tracker, replace “sp” with the same string you passed as the cookieName.

Setting the network user ID with set_network_user_id

The network_user_id field of the Snowplow event model corresponds to the ID stored in the third party cookie set by the Snowplow Clojure Collector. You can set the network user ID for server-side events like this:

tracker.set_network_user_id('ecdff4d0-9175-40ac-a8bb-325c49733607')

Setting the user fingerprint with set_fingerprint

The JavaScript Tracker generates a fingerprint based on browser features and attaches it to all client-side events. You can set the user fingerprint field for server-side events like this:

tracker.set_fingerprint(164502195)