Passive Tracking

This example shows how to configure TrackJS for a passive tracking environment, such as a third-party plugin or chrome module. In this case, you do not want to track everything on the page, as most events are not relevant to you. You only want to track events that you directly send into TrackJS.

This disables all automatic tracking and collection of Telemetry events.

window.TrackJS && TrackJS.install({
    token: "YOUR_TOKEN",
    callback: { enabled: false },
    console: { enabled: false },
    network: { enabled: false },
    visitor: { enabled: false },
    window: { enabled: false, promise: false }
};);
Passive Agent Tracking
import { TrackJS } from "trackjs";
TrackJS.install({
    token: "YOUR_TOKEN",
    callback: { enabled: false },
    console: { enabled: false },
    network: { enabled: false },
    visitor: { enabled: false },
    window: { enabled: false, promise: false }
};);
Passive Agent Tracking
<script>
window._trackJs = {
    token: "YOUR_TOKEN",
    callback: { enabled: false },
    console: { enabled: false },
    network: { enabled: false },
    visitor: { enabled: false },
    window: { enabled: false, promise: false }
};;
</script>
<script src="https://cdn.trackjs.com/releases/current/tracker.js"></script>
Passive Agent Tracking

To record your own Telemetry events, use the TrackJS console:

window.TrackJS && TrackJS.console.log("something interesting happened");
window.TrackJS && TrackJS.console.log({
    type: "event",
    data: myStateObject
});
Adding telemetry events
import { TrackJS } from "trackjs";

TrackJS.console.log("something interesting happened");
TrackJS.console.log({
    type: "event",
    data: myStateObject
});
Adding telemetry events
window.trackJs && trackJs.console.log("something interesting happened");
window.trackJs && trackJs.console.log({
    type: "event",
    data: myStateObject
});
Adding telemetry events

And to catch errors from your code, you’ll want to use the helper functions attempt and watch, or surround your code in try/catch blocks.

Use attempt if your code is synchronous and contained in a single function.

TrackJS.attempt(function your_main_function() {
    // do your work.
});
Adding explicit tracking to your code with attempt

Use watch to wrap individual functions that you might use in a callback.

function something() {
    // do your work.
};
document.addEventListener("click", TrackJS.watch(something));
Adding explicit tracking to your code with watch

Or use your own try catch wrapping and forward the errors to TrackJS.

try {
    // do your work.
} catch(e) {
    TrackJS.track(e);
}
Adding explicit tracking to your code with try/catch