You install TrackJS by including a script on your website. That script listens for errors and other events and sends actionable data back to your account. The script is lightweight and dependency free. You can download the most recent version here.
If you navigate to the installation page, you’ll see a script snippet you can copy and paste in to your site to get TrackJS up and running right away. It will look something like this:
Of course, there are many other ways to integrate our script with your site. We support many modern build tools like Gulp, Webpack, Browserify and many more.
The first script on the page
TrackJS works best as the first script on your page. To faciliate this, our script is dependency free and quite small. We see a very high percentage of errors occur during page load as other scripts are evaluating and loading, so it’s important for TrackJS to be initialized and monitoring as soon as possible.
The tracker script works on all modern browsers. Additionally, it supports IE 8 and up. If the script is loaded on an unsupported browser, it deactivates itself without causing issue. (Our goal is to track the errors, not cause them!) See How It Works for more details.
The tracker script will not work without a token. The token is how we know which account to send errors to. You can always find your token by going to the installation page.
If TrackJS can’t find a token, or some kind of other configuration error occurs, we will print a warning in the console.
TrackJS comes out of the box with sensible defaults. Many customers only include a token and our script, and they get great context to find and fix errors. By default we add a
window.onerror handler, and we also watch all network and console events. Additionally, we wrap
setTimeout and trap any errors that occur from callbacks passed to those functions.
Whitelisting for Content Security Policy (CSP)
If you’re applying content security rules, here are a couple of quick directives you can add to ensure TrackJS functions correctly.
If you’re hosting the tracker script on our CDN, you’ll want to allow our cloudfront domain.
We send errors to https://capture.trackjs.com via AJAX POST.
We send page view pings to https://usage.trackjs.com using a 1x1 pixel GIF image.
Putting it all together
We understand that each web application is different, and that a single configuration won’t work for everyone. If you’re looking for something more than the defaults, we offer numerous configuration options that allow you to customize the behavior of TrackJS.
TrackJS will automatically track many kinds of errors, but there are times when you know a lot more about what constitutes an error in your application than we do. To that end we expose a top level api that you can use to manually track events or wrap certain critical functions.