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 Tracker
  6. Advanced Usage
  7. Callbacks


If you call snowplow with a function as the argument, the function will be executed when sp.js loads:

snowplow(function () { console.log("sp.js has loaded"); });

Or equivalently:

snowplow(function (x) { console.log(x); }, "sp.js has loaded");

The callback you provide is executed as a method on the internal trackerDictionary object. This means that you can access the trackerDictionary using this:

// Configure a tracker instance named "cf" snowplow('newTracker', 'cf', '', { appId: 'snowplowExampleApp', platform: 'web' }); // Access the tracker instance inside a callback snowplow(function () { var cf =; var userFingerprint = cf.getUserFingerprint(); doSomethingWith(userFingerprint); })

The callback function should not be a method:

// TypeError: Illegal invocation snowplow(console.log, "sp.js has loaded");

will not work, because the value of this in the console.log function will be trackerDictionary rather than console.

You can get around this problem using Function.prototoype.bind as follows:

snowplow(console.log.bind(console), "sp.js has loaded");

For more on execution context in JavaScript, see the MDN page.