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. General Parameters
  7. Setting on load callbacks

Setting on load callbacks

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

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

Or equivalently:

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

The callback function should not be a method:

// TypeError: Illegal invocation snowplow_name_here(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_name_here(console.log.bind(console), "sp.js has loaded");