Sha256: ac7fc70b612eeac3e9f8a3bd96d91d5b9ca0242f5be47c779b5c9770e92d0c99

Contents?: true

Size: 1.32 KB

Versions: 15

Compression:

Stored size: 1.32 KB

Contents

// Extension to track errors using google analytics as a data store.
(function() {
  "use strict";
  GOVUK.analyticsPlugins = GOVUK.analyticsPlugins || {};

  GOVUK.analyticsPlugins.error = function (options) {
    var options = options || {},
        filenameMustMatch = options.filenameMustMatch;

    var trackJavaScriptError = function (e) {
      var errorFilename = e.filename,
          errorSource = errorFilename + ': ' + e.lineno;

      if (shouldTrackThisError(errorFilename)) {
        GOVUK.analytics.trackEvent('JavaScript Error', e.message, {
          label: errorSource,
          value: 1,
          nonInteraction: true
        });
      }
    };

    function shouldTrackThisError(errorFilename) {
      // Errors in page should always be tracked
      // If there's no filename filter, everything is tracked
      if (!errorFilename || !filenameMustMatch) {
        return true;
      }

      // If there's a filter and the error matches it, track it
      if (filenameMustMatch.test(errorFilename)) {
        return true;
      }

      return false;
    }

    if (window.addEventListener) {
      window.addEventListener('error', trackJavaScriptError, false);
    } else if (window.attachEvent) {
      window.attachEvent('onerror', trackJavaScriptError);
    } else {
      window.onerror = trackJavaScriptError;
    }
  }
}());

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
govuk_frontend_toolkit-4.13.0 app/assets/javascripts/govuk/analytics/error-tracking.js
govuk_frontend_toolkit-4.12.0 app/assets/javascripts/govuk/analytics/error-tracking.js
govuk_frontend_toolkit-4.11.0 app/assets/javascripts/govuk/analytics/error-tracking.js
govuk_frontend_toolkit-4.10.0 app/assets/javascripts/govuk/analytics/error-tracking.js
govuk_frontend_toolkit-4.9.1 app/assets/javascripts/govuk/analytics/error-tracking.js
govuk_frontend_toolkit-4.9.0 app/assets/javascripts/govuk/analytics/error-tracking.js
govuk_frontend_toolkit-4.8.2 app/assets/javascripts/govuk/analytics/error-tracking.js
govuk_frontend_toolkit-4.8.1 app/assets/javascripts/govuk/analytics/error-tracking.js
govuk_frontend_toolkit-4.8.0 app/assets/javascripts/govuk/analytics/error-tracking.js
govuk_frontend_toolkit-4.7.0 app/assets/javascripts/govuk/analytics/error-tracking.js
govuk_frontend_toolkit-4.6.1 app/assets/javascripts/govuk/analytics/error-tracking.js
govuk_frontend_toolkit-4.6.0 app/assets/javascripts/govuk/analytics/error-tracking.js
govuk_frontend_toolkit-4.5.0 app/assets/javascripts/govuk/analytics/error-tracking.js
govuk_frontend_toolkit-4.4.0 app/assets/javascripts/govuk/analytics/error-tracking.js
govuk_frontend_toolkit-4.3.0 app/assets/javascripts/govuk/analytics/error-tracking.js