Sha256: ea7a10ecac554d9f1dfcf856ab95ecba3d080dcf8b6c4f03c0e9a4394c69ae1d

Contents?: true

Size: 987 Bytes

Versions: 168

Compression:

Stored size: 987 Bytes

Contents

//= require ../vendor/polyfills/closest.js
;(function (global) {
  'use strict'

  var GOVUK = global.GOVUK || {}

  GOVUK.analyticsPlugins = GOVUK.analyticsPlugins || {}
  GOVUK.analyticsPlugins.mailtoLinkTracker = function () {
    document.querySelector('body').addEventListener('click', function (event) {
      var element = event.target
      if (element.tagName !== 'A') {
        element = element.closest('a')
      }

      if (!element) {
        return
      }

      var href = element.getAttribute('href')

      if (!href) {
        return
      }

      if (href.substring(0, 7) === 'mailto:') {
        trackClickEvent(element, href)
      }
    })

    function trackClickEvent (element, href) {
      var options = { transport: 'beacon' }
      var linkText = element.textContent

      if (linkText) {
        options.label = linkText.trim()
      }

      GOVUK.analytics.trackEvent('Mailto Link Clicked', href, options)
    }
  }

  global.GOVUK = GOVUK
})(window)

Version data entries

168 entries across 168 versions & 1 rubygems

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