Integrating with RequireJS

RequireJS enables you to asynchronously load JavaScript modules from a browser. TrackJS supports this method of module loading as of version 3.0.0. The TrackJS browser agent can be “required” from either the npm package or the cdn distribution.

Loading from Local NPM Modules

// npm install trackjs --save-exact
require(["node_modules/trackjs/index.umd.js"], function(TrackJS) {
  TrackJS.install({
    token: "YOUR_TOKEN"
  });
});
Loading TrackJS with RequireJS from local modules

Loading from CDN

// npm install trackjs --save-exact
require(["https://cdn.trackjs.com/agent/v3/latest/index.umd.js"], function(TrackJS) {
  TrackJS.install({
    token: "YOUR_TOKEN"
  });
});
Loading TrackJS with RequireJS from local modules