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