Sha256: 9308fabb576e4221d8ceeb10a3210b07755cfe7534ce07a589c8cba9d9203e13

Contents?: true

Size: 799 Bytes

Versions: 10

Compression:

Stored size: 799 Bytes

Contents

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

    var mailtoLinkSelector = 'a[href^="mailto:"]';

    $('body').on('click', mailtoLinkSelector, 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('Mailto Link Clicked', href, options);
    }

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

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

      return $target;
    }
  }
}());

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
govuk_frontend_toolkit-4.13.0 app/assets/javascripts/govuk/analytics/mailto-link-tracker.js
govuk_frontend_toolkit-4.12.0 app/assets/javascripts/govuk/analytics/mailto-link-tracker.js
govuk_frontend_toolkit-4.11.0 app/assets/javascripts/govuk/analytics/mailto-link-tracker.js
govuk_frontend_toolkit-4.10.0 app/assets/javascripts/govuk/analytics/mailto-link-tracker.js
govuk_frontend_toolkit-4.9.1 app/assets/javascripts/govuk/analytics/mailto-link-tracker.js
govuk_frontend_toolkit-4.9.0 app/assets/javascripts/govuk/analytics/mailto-link-tracker.js
govuk_frontend_toolkit-4.8.2 app/assets/javascripts/govuk/analytics/mailto-link-tracker.js
govuk_frontend_toolkit-4.8.1 app/assets/javascripts/govuk/analytics/mailto-link-tracker.js
govuk_frontend_toolkit-4.8.0 app/assets/javascripts/govuk/analytics/mailto-link-tracker.js
govuk_frontend_toolkit-4.7.0 app/assets/javascripts/govuk/analytics/mailto-link-tracker.js