(function() {
  "use strict";
  GOVUK.Tracker.load();
  var cookieDomain = (document.domain === 'www.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.Analytics({
    universalId: property,
    cookieDomain: cookieDomain
  });
  GOVUK.analytics.trackPageview();
})();

(function() {
  "use strict";
  GOVUK.Analytics.load();
  var cookieDomain = (document.domain === 'www.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';

  // wrapper function for calls to window.ga, used by all Google Analytics trackers
  function sendToGa() {
    if (typeof window.ga === "function") {
      ga.apply(window, arguments);
    }
  }
  // Rewritten universal tracker to allow setting of the autoLinker property
  var DMGoogleAnalyticsUniversalTracker = function(id, cookieDomain) {
    configureProfile(id, cookieDomain);
    anonymizeIp();

    function configureProfile(id, cookieDomain) {
      sendToGa('create', id, {'cookieDomain': cookieDomain, 'allowLinker': true });
    }

    function anonymizeIp() {
      // https://developers.google.com/analytics/devguides/collection/analyticsjs/advanced#anonymizeip
      sendToGa('set', 'anonymizeIp', true);
    }
  };
  DMGoogleAnalyticsUniversalTracker.prototype = GOVUK.GoogleAnalyticsUniversalTracker.prototype;
  GOVUK.GoogleAnalyticsUniversalTracker = DMGoogleAnalyticsUniversalTracker;
  GOVUK.analytics = new GOVUK.Analytics({
    universalId: property,
    cookieDomain: cookieDomain
  });
  GOVUK.analytics.trackPageview();
  GOVUK.analytics.addLinkedTrackerDomain(property, 'link', 'digitalservicesstore.service.gov.uk');
})();

Patch GOVUK.Analytics to add 'allowLinker' option
Patch GOVUK.Analytics to add 'allowLinker' option

The GOVUK.Analytics interface doesn't set the
'allowLinker' option when creating a ga tracker.

In order to preserve a vendor-agnostic
interface it also doesn't allow this to be sent
through when creating a new GOVUK.Analytics
instance.

This commit patches
GOVUK.GoogleAnalyticsUniversalTracker to include
'autoLinker' as a default option for all ga
trackers.
