# Error Tracking

Track JavaScript errors, capturing the error message, file and line number.
These events don’t affect bounce rate. Errors can be filtered to include only
files of interest by passing in an options argument with a regexp matcher (to
avoid tracking errors generated by browser plugins).

Expects an instance of `govuk/analytics/analytics` bound to
`window.GOVUK.analytics`.

Source: [govuk_frontend_toolkit/javascripts/govuk/analytics/error-tracking.js](https://github.com/alphagov/govuk_frontend_toolkit/blob/master/javascripts/govuk/analytics/error-tracking.js)

## Usage

**main.js**

```javascript
import $ from 'jquery';
import errorTracking from 'govuk/analytics/error-tracking';
import Analytics from 'govuk/analytics/analytics';

$(document).ready(() => {
  Analytics.load();

  const cookieDomain = (document.domain === 'www.gov.uk') ? '.www.gov.uk' : document.domain;
  window.GOVUK.analytics = new Analytics({
    universalId: 'UA-XXXXXXXX-X',
    cookieDomain
  });

  errorTracking({ filenameMustMatch: /gov\.uk/ });
});
```
