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 := sp.InitSubject()
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
SetIpAddress
SetUseragent
SetDomainUserId
SetNetworkUserId
Tracking the Subject
The Subject
can be used into two ways.
When initialising the Tracker
:
tracker := sp.InitTracker( sp.RequireEmitter(emitter), sp.OptionSubject(subject) )
Or when you track an event:
tracker.TrackPageView(sp.PageViewEvent{
PageUrl: sp.NewString("acme.com"),
Subject: subject
})
Code language: CSS (css)
When setting the Subject
as you track as event, you will override the Tracker
level Subject
for that specific event.
Set user ID with SetUserId
You can set the user ID to any string:
s.SetUserId( "{{USER ID}}" );
Code language: JavaScript (javascript)
Example:
s.SetUserId("alexd");
Code language: JavaScript (javascript)
Set screen resolution with SetScreenResolution
If your code has access to the device’s screen resolution, then you can pass this in to Snowplow too:
s.SetScreenResolution( {{WIDTH}}, {{HEIGHT}} );
Both numbers should be positive integers; note the order is width followed by height. Example:
s.SetScreenResolution(1366, 768);
Code language: CSS (css)
Set viewport dimensions with SetViewport
If your 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);
Code language: CSS (css)
Set color depth with SetColorDepth
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.SetColorDepth( {{BITS PER PIXEL}} );
The number should be a positive integer, in bits per pixel. Example:
s.SetColorDepth(32);
Code language: CSS (css)
Set timezone with SetTimezone
This method lets you pass a user’s timezone in to Snowplow:
s.timezone( {{TIMEZONE}} );
The timezone should be a string:
s.SetColorDepth("Europe/London");
Code language: JavaScript (javascript)
Set the language with SetLang
This method lets you pass a user’s language in to Snowplow:
s.SetLang( {{LANGUAGE}} );
The language should be a string:
s.SetLang('en');
Code language: JavaScript (javascript)
Set the IP Address with SetIpAddress
This method lets you pass a user’s IP Address in to Snowplow:
s.SetIpAddress( {{IP ADDRESS}} );
The IP Address should be a string:
s.SetIpAddress('127.0.0.1');
Code language: JavaScript (javascript)
Set the useragent with SetUseragent
This method lets you pass a user’s useragent string in to Snowplow:
s.SetUseragent( {{USERAGENT}} );
The useragent should be a string:
s.SetUseragent('some useragent');
Code language: JavaScript (javascript)
Set the Domain User ID with SetDomainUserId
This method lets you pass a user’s Domain User ID string in to Snowplow:
s.SetDomainUserId( {{DOMAIN USER ID}} );
The Domain User ID should be a string:
s.SetDomainUserId('domain-uid-12');
Code language: JavaScript (javascript)
Set the Domain User ID with SetNetworkUserId
This method lets you pass a user’s Network User ID string in to Snowplow:
s.SetNetworkUserId( {{NETWORK USER ID}} );
The Network User ID should be a string:
s.SetNetworkUserId('network-uid-12');
Code language: JavaScript (javascript)