Tracker Information
When initialising a tracker, you can use the returned tracker
instance to access various properties from this tracker instance.
// Configure a tracker instance named "sp"
const sp = newTracker('sp', '{{COLLECTOR_URL}', {
appId: 'snowplowExampleApp'
});
// Access the tracker properties
const domainUserId = sp.getDomainUserId();
Available methods on the Tracker
getDomainUserId
The getDomainUserId
method returns the user ID stored in the first-party cookie:
const domainUserId = sp.getDomainUserId();
console.log(domainUserId);
getDomainUserInfo
The getDomainUserInfo
method returns all the information stored in first-party cookie in an array:
const domainUserInfo = sp.getDomainUserInfo();
console.log(domainUserInfo);
The domainUserInfo
variable will contain an array with 11 elements:
- A string set to
'1'
if this is the user's first session and'0'
otherwise - The domain user ID
- The timestamp at which the cookie was created
- The number of times the user has visited the site
- The timestamp for the current visit
- The timestamp of the last visit
- The session id
- ID of the previous session (since version 3.5)
- ID of the first event in the current session (since version 3.5)
- Device created timestamp of the first event in the current session (since version 3.5)
- Index of the last event in the session (used to inspect order of events) (since version 3.5)
getUserId
The getUserId
method returns the user ID which you configured using setUserId()
:
const userId = sp.getUserId();
console.log(userId);
getCookieName
The getCookieName
method returns the complete cookie name for the domain or session cookie:
const cookieName = sp.getCookieName('id');
console.log(cookieName);
The argument corresponds to the basename of the cookie: 'id' for the domain cookie, 'ses' for the session cookie.
getPageViewId
The getPageViewId
method returns the page view id:
const pageViewId = sp.getPageViewId();
console.log(pageViewId);