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. PHP Tracker
  6. Subjects

Subjects

The Subject object lets you send any additional information about your application’s environment, current user etc to Snowplow.

To create a new subject:

$subject = new Subject();
Code language: PHP (php)

By default the subject has one piece information in it already, the platform [“p” => “srv”].

The Subject class contains a variety of ‘set’ methods to attach extra data to your event.

These set methods can be called either directly onto a subject object:

$subject = new Subject(); $subject->setPlatform("tv");
Code language: PHP (php)

Or they can be called through the tracker object:

$tracker->returnSubject()->setPlatform("tv");
Code language: PHP (php)

setPlatform

The default platform is “srv”. You can change the platform of the subject by calling:

$subject->setPlatform($platform);
Code language: PHP (php)

For example:

$subject->setPlatform("tv") # Running on a Connected TV
Code language: PHP (php)

For a full list of supported platforms, please see the Snowplow Tracker Protocol.

setUserId

You can set the user ID to any string:

$subject->setUserId($id);
Code language: PHP (php)

Example:

$subject->setUserId("jbeem");
Code language: PHP (php)

setScreenResolution

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

$subject->setScreenResolution($width, $height);
Code language: PHP (php)

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

$subject->setScreenResolution(1366, 768);
Code language: PHP (php)

setViewport

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

$subject->setViewport($width, $height);
Code language: PHP (php)

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

$subject->setViewport(300, 200);
Code language: PHP (php)

setColorDepth

If your PHP 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:

$subject->setColorDepth($depth);
Code language: PHP (php)

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

$subject->setColorDepth(32);
Code language: PHP (php)

setTimezone

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

$subject->setTimezone($timezone);
Code language: PHP (php)

The timezone should be a string:

$subject->setTimezone("Europe/London");
Code language: PHP (php)

setLanguage

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

$subject->setLanguage($language);
Code language: PHP (php)

The language should be a string:

$subject->setLanguage('en');
Code language: PHP (php)

setIpAddress

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

$subject->setIpAddress($ip);
Code language: PHP (php)

The IP Address should be a string:

$subject->setIpAddress('127.0.0.1');
Code language: PHP (php)

setUseragent

This method lets you pass a useragent in to Snowplow:

$subject->setUseragent($useragent);
Code language: PHP (php)

The useragent should be a string:

$subject->setUseragent('Agent Smith');
Code language: PHP (php)

setNetworkUserId

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

$subject->setNetworkUserId($networkUserId);
Code language: PHP (php)

The network user id should be a string:

$subject->setNetworkUserId("network-id");
Code language: PHP (php)

setDomainUserId

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

$subject->setDomainUserId($domainUserId);
Code language: PHP (php)

The domain user id should be a string:

$subject->setDomainUserId("domain-id");
Code language: PHP (php)