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. Tracker Setup
  7. Setting on load callbacks

Setting on load 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 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 window rather than console.

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

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