Skip to main content

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:

  • setUserId
  • setScreenResolution
  • setViewport
  • setColorDepth
  • setTimezone
  • setLanguage

Here are some examples:

s1.setUserID("Kevin Gleason");
s1.setLanguage("en-gb");
s1.setScreenResolution(1920, 1080);

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

Tracker(emitter, namespace, appId, s1);
// 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 you wish to track 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)

You can get these values by referencing flash.system.Capabilities.screenResolutionX and flash.system.Capabilities.screenResolutionY, although they will only reflect the dimensions of the main screen.

Alternatively, if your AS3 code has script access via ExternalInterface, you can use Javascript to query these values from the browser or another player context.

Set viewport dimensions with setViewport

If your AS3 code has access to the viewport dimensions (by calling Javascript code through ExternalInterface), 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 AS3 code has access to the bit depth of the device's color palette for displaying images (by calling Javascript's screen.colorDepth via ExternalInterface), 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')
Was this page helpful?