Top Level API
TrackJS will automatically track many errors. Often the default settings and behavior are good enough. However, there may be times when you wish to manually track errors or wrap certain critical functions. For these use cases, we provide a top-level API.
If you’re using our CDN to host the tracker script (as opposed to bundling), please check for the existence of the global
trackJs object before invoking API calls. Networks are not reliable so there’s always a small chance of load failure. Additionally, some aggressive ad blockers will prevent our script from loading off the CDN. The easiest way to prevent issues is to bundle our script with yours.
You may certainly continue to use our CDN, but please use the following test for the
trackJs global object before invoking API calls:
- trackJs.addMetadata(key, value) - (Available in v2.2.0 or later)
- trackJs.removeMetadata(key) - (Available in v2.2.0 or later)
Directly invoke TrackJS to transmit an error with the provided message. The message can be of any type. If it is not a string, it will be passed through the serialize function before transmission. If it is an
Error, the details and stacktrace will be recorded.
The resulting error will include any logs that may have been captured from console, network, or visitor.
Invoke a function within a try/catch wrapper to automatically capture any errors that may arise. Context and arguments to the function can be passed as additional parameters.
Add a key-value pair of data that will describe errors captured in this page view. You can use this to track any arbitrary data that is interesting for you, such as whether it is a paying customer, their transaction id, or anything else.
These metadata key-values are sent with each error and the UI will give you tools to group and filter them.
You can also remove a key from the metadata, in case the user takes some action during the session that invalidates it.
Update the TrackJS configuration after initialization. Not all parameters are available to be updated after initialization.
Record an event into the Telemetry Timeline log with appropriate severity. Any objects passed into the function will be serialized. These will honor any custom serializer setup in the configuration.
Record an event into the Telemetry Timeline log with error severity. This will also fire an error to our servers in the default case. This can be customized. Any objects passed into the function will be serialized.
Return a wrapped and watched version of a function that will automatically capture any errors that may arise. Context for the function can be passed as additional argument.
Replace all of the functions on an object with watched versions of the functions that will automatically capture any errors that may arise. Context for the functions will be bound to the object.
Get the current version of the TrackJS script.