Skip to main content

Error tracking

The Errors tracker plugin provides two ways of tracking exceptions: manual tracking of handled exceptions using trackError and automatic tracking of unhandled exceptions using enableErrorTracking.

Error events can be manually tracked and/or automatically tracked.

Install plugin

Tracker DistributionIncluded
sp.js
sp.lite.js

Download:

Download from GitHub Releases (Recommended)Github Releases (plugins.umd.zip)
Available on jsDelivrjsDelivr (latest)
Available on unpkgunpkg (latest)

Note: The links to the CDNs above point to the current latest version. You should pin to a specific version when integrating this plugin on your website if you are using a third party CDN in production.

window.snowplow('addPlugin', 
"https://cdn.jsdelivr.net/npm/@snowplow/browser-plugin-error-tracking@latest/dist/index.umd.min.js",
["snowplowErrorTracking", "ErrorTrackingPlugin"]
);

Manual error tracking

Use the trackError method to track handled exceptions (application errors) in your JS code. This is its signature:

snowplow('trackError', {
/** The error message */
message: string;
/** The filename where the error occurred */
filename?: string;
/** The line number which the error occurred on */
lineno?: number;
/** The column number which the error occurred on */
colno?: number;
/** The error object */
error?: Error;
});
NameRequired?DescriptionType
messageYesError messagestring
filenameNoFilename or URLstring
linenoNoLine number of problem code chunknumber
colnoNoColumn number of problem code chunknumber
errorNoJS ErrorEventErrorEvent

Of these arguments, only message is required. Signature of this method defined to match window.onerror callback in modern browsers.

try {
var user = getUser()
} catch(e) {
snowplow('trackError', {
message: 'Cannot get user object',
filename: 'shop.js',
error: e
});
}

Using trackError it's assumed that developer knows where errors could happen, which is not often the case. Therefor it's recommended to use enableErrorTracking as it allows you to discover errors that weren't expected.

Automatic error tracking

Use the enableErrorTracking method to track unhandled exceptions (application errors) in your JS code. This is its signature:

snowplow('enableErrorTracking', {
/** A callback which allows on certain errors to be tracked */
filter?: (error: ErrorEvent) => boolean;
/** A callback to dynamically add extra context based on the error */
contextAdder?: (error: ErrorEvent) => Array<SelfDescribingJson>;
/** Context to be added to every error */
context?: Array<SelfDescribingJson>;
}
NameRequired?DescriptionType
filterNoPredicate to filter exceptions(ErrorEvent) => Boolean
contextAdderNoFunction to get dynamic context(ErrorEvent) => Array<SelfDescribingJson>
contextNoAdditional custom contextArray<SelfDescribingJson>

Unlike trackError you need enable error tracking only once:

snowplow('enableErrorTracking')

Application error events are implemented as Snowplow self-describing events. Here is the schema for an application_error event.