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. C++ tracker
  6. Adding extra data: the Subject class

Adding extra data: the Subject class

You may have additional information about your application’s environment, current user and so on, which you want to send to Snowplow with each event.

Create a subject like this:

Subject subject;

The Subject class has a set of set...() methods to attach extra data relating to the user to all tracked events:

  • set_user_id
  • set_screen_resolution
  • set_viewport
  • set_color_depth
  • set_timezone
  • set_language

We will discuss each of these in turn below:

Set user ID with set_user_id

You can set the user ID to any string:

s.set_user_id( "{{USER ID}}" );

Example:

s.set_user_id("alexd");

Set screen resolution with set_screen_resolution

If your code has access to the device’s screen resolution, then you can pass this in to Snowplow too:

s.set_screen_resolution( {{WIDTH}}, {{HEIGHT}} );

Both numbers should be positive integers; note the order is width followed by height. Example:

s.set_screen_resolution(1366, 768);

Set viewport dimensions with set_viewport

If your code has access to the viewport dimensions, then you can pass this in to Snowplow too:

s.set_viewport( {{WIDTH}}, {{HEIGHT}} );

Both numbers should be positive integers; note the order is width followed by height. Example:

s.set_viewport(300, 200);

Set color depth with set_color_depth

If your code has access to the bit depth of the device’s color palette for displaying images, then you can pass this in to Snowplow too:

s.set_color_depth( {{BITS PER PIXEL}} );

The number should be a positive integer, in bits per pixel. Example:

s.set_color_depth(32);

Set timezone with set_timezone

This method lets you pass a user’s timezone in to Snowplow:

s.set_timezone( {{TIMEZONE}} );

The timezone should be a string:

s.set_timezone("Europe/London");

Set the language with set_language

This method lets you pass a user’s language in to Snowplow:

s.set_language( {{LANGUAGE}} );

The language should be a string:

s.set_language('en');