Sha256: 0040d0d02541f94f5ecbeafd5be60dd5d34e253779eba42c02c0a459e9528303

Contents?: true

Size: 1.4 KB

Versions: 10

Compression:

Stored size: 1.4 KB

Contents

// Extension to track errors using google analytics as a data store.
(function(global) {
  "use strict";

  var GOVUK = global.GOVUK || {};

  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 (global.addEventListener) {
      global.addEventListener('error', trackJavaScriptError, false);
    } else if (global.attachEvent) {
      global.attachEvent('onerror', trackJavaScriptError);
    } else {
      global.onerror = trackJavaScriptError;
    }
  }

  global.GOVUK = GOVUK;
})(window);

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
govuk_frontend_toolkit-4.18.3 app/assets/javascripts/govuk/analytics/error-tracking.js
govuk_frontend_toolkit-4.18.2 app/assets/javascripts/govuk/analytics/error-tracking.js
govuk_frontend_toolkit-4.18.1 app/assets/javascripts/govuk/analytics/error-tracking.js
govuk_frontend_toolkit-4.18.0 app/assets/javascripts/govuk/analytics/error-tracking.js
govuk_frontend_toolkit-4.17.0 app/assets/javascripts/govuk/analytics/error-tracking.js
govuk_frontend_toolkit-4.16.1 app/assets/javascripts/govuk/analytics/error-tracking.js
govuk_frontend_toolkit-4.16.0 app/assets/javascripts/govuk/analytics/error-tracking.js
govuk_frontend_toolkit-4.15.0 app/assets/javascripts/govuk/analytics/error-tracking.js
govuk_frontend_toolkit-4.14.1 app/assets/javascripts/govuk/analytics/error-tracking.js
govuk_frontend_toolkit-4.14.0 app/assets/javascripts/govuk/analytics/error-tracking.js