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. Java 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.

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

Here are some examples:

// Init an empty Subject and add some values Subject s1 = new Subject.SubjectBuilder().build(); s1.setUserId("Kevin Gleason"); s1.setLanguage("en-gb"); s1.setScreenResolution(1920, 1080); // Init all values at build time Subject s1 = new Subject.SubjectBuilder() .userId("Kevin Gleason") .language("en-gb") .screenResolution(1920, 1080) .build();

After that, you can add your Subject to your Tracker like so:

Tracker t1 = new Tracker.TrackerBuilder( ... ) .subject(s1) .build(); // OR t1.setSubject(s1);

Set user ID with setUserId

You can set the user ID to any string:

s1.setUserId( "{{USER ID}}" )

Example:

s1.setUserId("alexd")

Set screen resolution with setScreenResolution

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

t1.setScreenResolution( {{WIDTH}}, {{HEIGHT}} )

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

t1.setScreenResolution(1366, 768)

Set viewport dimensions with setViewport

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

s.setViewport( {{WIDTH}}, {{HEIGHT}} )

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

s.setViewport(300, 200)

Set color depth with setColorDepth

If your Java 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.setColorDepth( {{BITS PER PIXEL}} )

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

s.setColorDepth(32)

Set timezone with setTimezone

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

s.setTimezone( {{TIMEZONE}} )

The timezone should be a string:

s.setTimezone("Europe/London")

Set the language with setLanguage

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

s.setLanguage( {{LANGUAGE}} )

The language should be a string:

s.setLanguage('en')

setIpAddress

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

setIpAddress( {{IP ADDRESS}} )

The IP address should be a string:

subj.setIpAddress("127.0.0.1");

setUseragent

This method lets you pass a useragent in to Snowplow:

setUseragent( {{USERAGENT}} )

The useragent should be a string:

subj.setUseragent("Agent Smith");

setNetworkUserId

This method lets you pass a Network User ID in to Snowplow:

setNetworkUserId( {{NUID}} )

The network user id should be a string:

subj.setNetworkUserId("network-id");

setDomainUserId

This method lets you pass a Domain User ID in to Snowplow:

setDomainUserId( {{DUID}} )

The domain user id should be a string:

subj.setDomainUserId("domain-id");