Sha256: e6ac56367950d79f4f8ce293b6d45bed53b001143e4e107e364d48653b8fa45d

Contents?: true

Size: 1.38 KB

Versions: 331

Compression:

Stored size: 1.38 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) {
    options = options || {}
    var filenameMustMatch = options.filenameMustMatch

    var trackJavaScriptError = function (e) {
      var errorFilename = e.filename
      var 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

331 entries across 331 versions & 3 rubygems

Version Path
govuk_publishing_components-40.1.0 app/assets/javascripts/govuk_publishing_components/analytics/error-tracking.js
govuk_publishing_components-40.0.0 app/assets/javascripts/govuk_publishing_components/analytics/error-tracking.js
govuk_publishing_components-39.2.5 app/assets/javascripts/govuk_publishing_components/analytics/error-tracking.js
govuk_publishing_components-39.2.4 app/assets/javascripts/govuk_publishing_components/analytics/error-tracking.js
govuk_publishing_components-39.2.3 app/assets/javascripts/govuk_publishing_components/analytics/error-tracking.js
govuk_publishing_components-39.2.2 app/assets/javascripts/govuk_publishing_components/analytics/error-tracking.js
govuk_publishing_components-39.2.1 app/assets/javascripts/govuk_publishing_components/analytics/error-tracking.js
govuk_publishing_components-39.2.0 app/assets/javascripts/govuk_publishing_components/analytics/error-tracking.js
govuk_publishing_components-39.1.0 app/assets/javascripts/govuk_publishing_components/analytics/error-tracking.js
govuk_publishing_components-39.0.0 app/assets/javascripts/govuk_publishing_components/analytics/error-tracking.js
govuk_publishing_components-38.4.2 app/assets/javascripts/govuk_publishing_components/analytics/error-tracking.js
govuk_publishing_components-38.1.1 app/assets/javascripts/govuk_publishing_components/analytics/error-tracking.js
govuk_publishing_components-38.1.0 app/assets/javascripts/govuk_publishing_components/analytics/error-tracking.js
govuk_publishing_components-38.0.1 app/assets/javascripts/govuk_publishing_components/analytics/error-tracking.js
govuk_publishing_components-38.0.0 app/assets/javascripts/govuk_publishing_components/analytics/error-tracking.js
govuk_publishing_components-37.10.0 app/assets/javascripts/govuk_publishing_components/analytics/error-tracking.js
govuk_publishing_components-37.9.1 app/assets/javascripts/govuk_publishing_components/analytics/error-tracking.js
govuk_publishing_components-37.9.0 app/assets/javascripts/govuk_publishing_components/analytics/error-tracking.js
govuk_publishing_components-37.8.1 app/assets/javascripts/govuk_publishing_components/analytics/error-tracking.js
govuk_publishing_components-37.8.0 app/assets/javascripts/govuk_publishing_components/analytics/error-tracking.js