Sha256: 0d713800256b0cf87f986b01c58aeff41fdf7914312cf1b56510d3a78d2ebda3

Contents?: true

Size: 969 Bytes

Versions: 131

Compression:

Stored size: 969 Bytes

Contents

;(function (global) {
  'use strict'

  var $ = global.jQuery
  var GOVUK = global.GOVUK || {}

  GOVUK.analyticsPlugins = GOVUK.analyticsPlugins || {}
  GOVUK.analyticsPlugins.downloadLinkTracker = function (options) {
    options = options || {}
    var downloadLinkSelector = options.selector

    if (downloadLinkSelector) {
      $('body').on('click', downloadLinkSelector, trackDownload)
    }

    function trackDownload (evt) {
      var $link = getLinkFromEvent(evt)
      var href = $link.attr('href')
      var evtOptions = { transport: 'beacon' }
      var linkText = $.trim($link.text())

      if (linkText) {
        evtOptions.label = linkText
      }

      GOVUK.analytics.trackEvent('Download Link Clicked', href, evtOptions)
    }

    function getLinkFromEvent (evt) {
      var $target = $(evt.target)

      if (!$target.is('a')) {
        $target = $target.parents('a')
      }

      return $target
    }
  }

  global.GOVUK = GOVUK
})(window)

Version data entries

131 entries across 131 versions & 1 rubygems

Version Path
govuk_publishing_components-25.2.3 app/assets/javascripts/govuk_publishing_components/analytics/download-link-tracker.js
govuk_publishing_components-25.2.2 app/assets/javascripts/govuk_publishing_components/analytics/download-link-tracker.js
govuk_publishing_components-25.2.1 app/assets/javascripts/govuk_publishing_components/analytics/download-link-tracker.js
govuk_publishing_components-25.2.0 app/assets/javascripts/govuk_publishing_components/analytics/download-link-tracker.js
govuk_publishing_components-25.1.0 app/assets/javascripts/govuk_publishing_components/analytics/download-link-tracker.js
govuk_publishing_components-25.0.0 app/assets/javascripts/govuk_publishing_components/analytics/download-link-tracker.js
govuk_publishing_components-24.21.1 app/assets/javascripts/govuk_publishing_components/analytics/download-link-tracker.js
govuk_publishing_components-24.21.0 app/assets/javascripts/govuk_publishing_components/analytics/download-link-tracker.js
govuk_publishing_components-24.20.0 app/assets/javascripts/govuk_publishing_components/analytics/download-link-tracker.js
govuk_publishing_components-24.19.0 app/assets/javascripts/govuk_publishing_components/analytics/download-link-tracker.js
govuk_publishing_components-24.18.5 app/assets/javascripts/govuk_publishing_components/analytics/download-link-tracker.js
govuk_publishing_components-24.18.4 app/assets/javascripts/govuk_publishing_components/analytics/download-link-tracker.js
govuk_publishing_components-24.18.3 app/assets/javascripts/govuk_publishing_components/analytics/download-link-tracker.js
govuk_publishing_components-24.18.2 app/assets/javascripts/govuk_publishing_components/analytics/download-link-tracker.js
govuk_publishing_components-24.18.1 app/assets/javascripts/govuk_publishing_components/analytics/download-link-tracker.js
govuk_publishing_components-24.18.0 app/assets/javascripts/govuk_publishing_components/analytics/download-link-tracker.js
govuk_publishing_components-24.17.0 app/assets/javascripts/govuk_publishing_components/analytics/download-link-tracker.js
govuk_publishing_components-24.16.1 app/assets/javascripts/govuk_publishing_components/analytics/download-link-tracker.js
govuk_publishing_components-24.16.0 app/assets/javascripts/govuk_publishing_components/analytics/download-link-tracker.js
govuk_publishing_components-24.15.3 app/assets/javascripts/govuk_publishing_components/analytics/download-link-tracker.js