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();
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.
setPlatform
setUserId
setScreenRes
setViewport
setColorDepth
setTimezone
[setLanguage](#set-lang)
setIpAddress
setUseragent
setNetworkUserId
setSessionId
setSessionIndex
These set methods can be called either directly onto a subject object:
$subject = new Subject();
$subject->setPlatform("tv");
Or they can be called through the tracker object:
$tracker->returnSubject()->setPlatform("tv");
setPlatform
β
The default platform is "srv". You can change the platform of the subject by calling:
$subject->setPlatform($platform);
For example:
$subject->setPlatform("tv") # Running on a Connected TV
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);
Example:
$subject->setUserId("jbeem");
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);
Both numbers should be positive integers; note the order is width followed by height. Example:
$subject->setScreenResolution(1366, 768);
setViewport
β
If your PHP code has access to the viewport dimensions, then you can pass this in to Snowplow too:
$subject->setViewport($width, $height);
Both numbers should be positive integers; note the order is width followed by height. Example:
$subject->setViewport(300, 200);
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);
The number should be a positive integer, in bits per pixel. Example:
$subject->setColorDepth(32);
setTimezone
β
This method lets you pass a user's timezone in to Snowplow:
$subject->setTimezone($timezone);
The timezone should be a string:
$subject->setTimezone("Europe/London");
setLanguage
β
This method lets you pass a user's language in to Snowplow:
$subject->setLanguage($language);
The language should be a string:
$subject->setLanguage('en');
setIpAddress
β
This method lets you pass a user's IP Address in to Snowplow:
$subject->setIpAddress($ip);
The IP Address should be a string:
$subject->setIpAddress('127.0.0.1');
setUseragent
β
This method lets you pass a useragent in to Snowplow:
$subject->setUseragent($useragent);
The useragent should be a string:
$subject->setUseragent('Agent Smith');
setNetworkUserId
β
This method lets you pass a Network User ID in to Snowplow:
$subject->setNetworkUserId($networkUserId);
The network user id should be a string:
$subject->setNetworkUserId("network-id");
setDomainUserId
β
This method lets you pass a Domain User ID in to Snowplow:
$subject->setDomainUserId($domainUserId);
The domain user id should be a string:
$subject->setDomainUserId("domain-id");
setSessionId
β
This method lets you pass a session ID in to Snowplow:
$subject->setSessionId($sessionId);
The session ID should be a string:
$subject->setSessionId("759e1c9a-6b74-403c-8b6f-18eb9f0c2f02");
setSessionIndex
β
This method lets you pass a session index in to Snowplow:
$subject->setSessionIndex($sessionIndex);
The session index should be a number:
$subject->setSessionIndex(1);