Sha256: 949f488a1156ddc15c9f16b2b4766cd899ceb91676e0d9483dd48fb5c950fb4e

Contents?: true

Size: 1.09 KB

Versions: 18

Compression:

Stored size: 1.09 KB

Contents

;(function (global) {
  'use strict'

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

  GOVUK.analyticsPlugins = GOVUK.analyticsPlugins || {}
  GOVUK.analyticsPlugins.externalLinkTracker = function () {
    var currentHost = GOVUK.analyticsPlugins.externalLinkTracker.getHostname()
    var externalLinkSelector = 'a[href^="http"]:not(a[href*="' + currentHost + '"])'

    $('body').on('click', externalLinkSelector, trackClickEvent)

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

      if (linkText) {
        options.label = linkText
      }

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

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

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

      return $target
    }
  }

  GOVUK.analyticsPlugins.externalLinkTracker.getHostname = function () {
    return global.location.hostname
  }

  global.GOVUK = GOVUK
})(window)

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
govuk_frontend_toolkit-7.1.0 app/assets/javascripts/govuk/analytics/external-link-tracker.js
govuk_frontend_toolkit-7.0.1 app/assets/javascripts/govuk/analytics/external-link-tracker.js
govuk_frontend_toolkit-7.0.0 app/assets/javascripts/govuk/analytics/external-link-tracker.js
govuk_frontend_toolkit-6.0.4 app/assets/javascripts/govuk/analytics/external-link-tracker.js
govuk_frontend_toolkit-6.0.3 app/assets/javascripts/govuk/analytics/external-link-tracker.js
govuk_frontend_toolkit-6.0.2 app/assets/javascripts/govuk/analytics/external-link-tracker.js
govuk_frontend_toolkit-6.0.1 app/assets/javascripts/govuk/analytics/external-link-tracker.js
govuk_frontend_toolkit-6.0.0 app/assets/javascripts/govuk/analytics/external-link-tracker.js
govuk_frontend_toolkit-5.2.0 app/assets/javascripts/govuk/analytics/external-link-tracker.js
govuk_frontend_toolkit-5.1.3 app/assets/javascripts/govuk/analytics/external-link-tracker.js
govuk_frontend_toolkit-5.1.2 app/assets/javascripts/govuk/analytics/external-link-tracker.js
govuk_frontend_toolkit-5.1.1 app/assets/javascripts/govuk/analytics/external-link-tracker.js
govuk_frontend_toolkit-5.1.0 app/assets/javascripts/govuk/analytics/external-link-tracker.js
govuk_frontend_toolkit-5.0.3 app/assets/javascripts/govuk/analytics/external-link-tracker.js
govuk_frontend_toolkit-5.0.2 app/assets/javascripts/govuk/analytics/external-link-tracker.js
govuk_frontend_toolkit-5.0.1 app/assets/javascripts/govuk/analytics/external-link-tracker.js
govuk_frontend_toolkit-5.0.0 app/assets/javascripts/govuk/analytics/external-link-tracker.js
govuk_frontend_toolkit-4.18.4 app/assets/javascripts/govuk/analytics/external-link-tracker.js