Sha256: c03421881ff3b2daeea8b380d6ee7f923e298d1cba50326828990c3e2244b0b3

Contents?: true

Size: 1.01 KB

Versions: 17

Compression:

Stored size: 1.01 KB

Contents

(function() {
  "use strict";
  GOVUK.analyticsPlugins = GOVUK.analyticsPlugins || {};
  GOVUK.analyticsPlugins.externalLinkTracker = function () {

    var currentHost = GOVUK.analyticsPlugins.externalLinkTracker.getHostname(),
        externalLinkSelector = 'a[href^="http"]:not(a[href*="' + currentHost + '"])';

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

    function trackClickEvent(evt) {
      var $link = getLinkFromEvent(evt),
          options = {transport: 'beacon'},
          href = $link.attr('href'),
          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 window.location.hostname;
  }
}());

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
govuk_frontend_toolkit-4.13.0 app/assets/javascripts/govuk/analytics/external-link-tracker.js
govuk_frontend_toolkit-4.12.0 app/assets/javascripts/govuk/analytics/external-link-tracker.js
govuk_frontend_toolkit-4.11.0 app/assets/javascripts/govuk/analytics/external-link-tracker.js
govuk_frontend_toolkit-4.10.0 app/assets/javascripts/govuk/analytics/external-link-tracker.js
govuk_frontend_toolkit-4.9.1 app/assets/javascripts/govuk/analytics/external-link-tracker.js
govuk_frontend_toolkit-4.9.0 app/assets/javascripts/govuk/analytics/external-link-tracker.js
govuk_frontend_toolkit-4.8.2 app/assets/javascripts/govuk/analytics/external-link-tracker.js
govuk_frontend_toolkit-4.8.1 app/assets/javascripts/govuk/analytics/external-link-tracker.js
govuk_frontend_toolkit-4.8.0 app/assets/javascripts/govuk/analytics/external-link-tracker.js
govuk_frontend_toolkit-4.7.0 app/assets/javascripts/govuk/analytics/external-link-tracker.js
govuk_frontend_toolkit-4.6.1 app/assets/javascripts/govuk/analytics/external-link-tracker.js
govuk_frontend_toolkit-4.6.0 app/assets/javascripts/govuk/analytics/external-link-tracker.js
govuk_frontend_toolkit-4.5.0 app/assets/javascripts/govuk/analytics/external-link-tracker.js
govuk_frontend_toolkit-4.4.0 app/assets/javascripts/govuk/analytics/external-link-tracker.js
govuk_frontend_toolkit-4.3.0 app/assets/javascripts/govuk/analytics/external-link-tracker.js
govuk_frontend_toolkit-4.2.1 app/assets/javascripts/govuk/analytics/external-link-tracker.js
govuk_frontend_toolkit-4.2.0 app/assets/javascripts/govuk/analytics/external-link-tracker.js