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 }
};);
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 }
};);
<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>
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 });
import { TrackJS } from "trackjs"; TrackJS.console.log("something interesting happened"); TrackJS.console.log({ type: "event", data: myStateObject });
window.trackJs && trackJs.console.log("something interesting happened"); window.trackJs && trackJs.console.log({ type: "event", data: myStateObject });
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. });
Use watch to wrap individual functions that you might use in a callback.
function something() { // do your work. }; document.addEventListener("click", TrackJS.watch(something));
Or use your own try
catch
wrapping and forward the errors to TrackJS.
try { // do your work. } catch(e) { TrackJS.track(e); }