(function() {
  "use strict";
  GOVUK.Tracker.load();
  var cookieDomain = (document.domain === 'www.beta.digitalmarketplace.service.gov.uk') ? '.digitalmarketplace.service.gov.uk' : document.domain;
  var property = (document.domain === 'www.digitalmarketplace.service.gov.uk') ? 'UA-49258698-1' : 'UA-49258698-3';
  GOVUK.analytics = new GOVUK.Tracker({
    universalId: property,
    cookieDomain: cookieDomain
  });
  GOVUK.analytics.trackPageview();

  // Tracking for declaration pages
  declarationPages = {
    'firstPage': '/suppliers/frameworks/g-cloud-7/declaration/g_cloud_7_essentials',
    'lastPage': '/suppliers/frameworks/g-cloud-7/declaration/grounds_for_discretionary_exclusion'
  };
  declarationVirtualPageViews = {
    'firstQuestion': declarationPages.firstPage + '/interactions/accept-terms-of-participation',
    'makeDeclarationButton': declarationPages.lastPage + '/interactions/make-declaration'
  };

  var registerFirstQuestionInteraction = function (e) {
    var $target;

    $target = $(e.target);

    // if the click target is a child node of the label, get the label instead
    if ($target.prop('nodeName').toLowerCase() !== 'label') {
      $target = $target.closest('label');
    }

    GOVUK.analytics.trackPageview(declarationVirtualPageViews.firstQuestion + '/yes');
    GOVUK.analytics.trackPageview(declarationVirtualPageViews.firstQuestion + '/no');
  };

  var registerDeclarationMade = function (e) {
    if (window.location.pathname === declarationPages.lastPage) {
      GOVUK.analytics.trackPageview(declarationVirtualPageViews.makeDeclarationButton);
    }
  }

  if (window.location.pathname === declarationPages.firstPage) {
    $('body').on('click', 'form.supplier-declaration fieldset:eq(0) label.selection-button', registerFirstQuestionInteraction);
  }
  if (window.location.pathname === declarationPages.lastPage) {
    $('form.supplier-declaration .button-save').on('click', registerDeclarationMade);
  }
})();

@@ -487,16 +487,20 @@
 pages%0A  
+var 
 declarat
@@ -508,24 +508,24 @@
 onPages = %7B%0A
-
     'firstPa
@@ -702,16 +702,20 @@
 %0A  %7D;%0A  
+var 
 declarat
@@ -925,24 +925,151 @@
 ration'%0A  %7D;
+%0A  var externalLinkSelector = 'a%5Bhref%5E=%22https%22%5D:not(a%5Bhref*=%22' + currentHost + '%22%5D)';%0A  var pathName = window.location.pathname
 %0A%0A  var regi
@@ -1584,37 +1584,21 @@
     if (
-window.location.
 path
-n
+N
 ame === 
@@ -1731,33 +1731,711 @@
 %0A%0A  
-if (window.location.
+var registerLinkClick = function (e) %7B%0A    var $target = $(e.target),%0A        href = $target.prop('href'),%0A        category = 'internal-link',%0A        action = $target.text(),%0A        fileTypesRegExp = /%5C.(pdf%7Cpda%7Codt%7Cods%7Codp)$/;%0A%0A    /* %0A       File type matching based on those in:%0A       https://github.com/alphagov/digitalmarketplace-utils/blob/8251d45f47593bd73c5e3b993e1734b5ee505b4b/dmutils/documents.py#L105%0A    */%0A    if (href.match(fileTypesRegExp) !== null) %7B // download link%0A      category = 'download';%0A    %7D%0A    else if (href.match(/%5E(https%7Chttp)%7B1%7D/) !== null) %7B // external link%0A      category = 'external-link';%0A    %7D%0A    GOVUK.analytics.trackEvent(category, action);%0A  %7D;%0A%0A  if (
 path
-n
+N
 ame 
@@ -2606,37 +2606,21 @@
 %7D%0A  if (
-window.location.
 path
-n
+N
 ame === 
@@ -2734,18 +2734,68 @@
 nMade);%0A
-
   %7D
+%0A%0A  $('body').on('click', 'a', registerLinkClick);
 %0A%7D)();%0A

Add link tracking (by event)