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. JavaScript Trackers (Web and Node.js)
  6. Browser Tracker
  7. Browser Tracker v3 Reference
  8. Advanced Usage
  9. Tracker Information

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();
Code language: JavaScript (javascript)

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);
Code language: JavaScript (javascript)

getDomainUserInfo

The getDomainUserInfo method returns all the information stored in first-party cookie in an array:

const domainUserInfo = sp.getDomainUserInfo(); console.log(domainUserInfo);
Code language: JavaScript (javascript)

The domainUserInfo variable will contain an array with 7 elements:

  1. A string set to '1' if this is the user’s first session and '0' otherwise
  2. The domain user ID
  3. The timestamp at which the cookie was created
  4. The number of times the user has visited the site
  5. The timestamp for the current visit
  6. The timestamp of the last visit
  7. The session id

getUserId

The getUserId method returns the user ID which you configured using setUserId():

const userId = sp.getUserId(); console.log(userId);
Code language: JavaScript (javascript)

getCookieName

The getCookieName method returns the complete cookie name for the domain or session cookie:

const cookieName = sp.getCookieName('id'); console.log(cookieName);
Code language: JavaScript (javascript)

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);
Code language: JavaScript (javascript)

If you’d like to learn more about Snowplow Insights you can book a demo with our team, or if you’d prefer, you can try Snowplow technology for yourself quickly and easily.