<commit_before>describe("GOVUK.Analytics", function () {
  var analytics;

  beforeEach(function() {
    window.ga = function() {};
    spyOn(window, 'ga');
    analytics = new window.GOVUK.Analytics({
      universalId: 'universal-id',
      cookieDomain: 'www.digitalmarketplace.service.gov.uk'
    });
  });

  describe('when created', function() {
    var universalSetupArguments;

    beforeEach(function() {
      universalSetupArguments = window.ga.calls.allArgs();
    });

    it('configures a universal tracker', function() {
      expect(universalSetupArguments[0]).toEqual(['create', 'universal-id', {
        'cookieDomain': 'www.digitalmarketplace.service.gov.uk',
        'allowLinker': true
      }]);
    });
  })
});
<commit_msg>Add test for preferred behaviour<commit_after>describe("GOVUK.Analytics", function () {
  var analytics;

  beforeEach(function () {
    window.ga = function() {};
    spyOn(window, 'ga');
  });

  describe('when created', function() {
    var universalSetupArguments;

    beforeEach(function() {
      analytics = new window.GOVUK.Analytics({
        universalId: 'universal-id',
        cookieDomain: 'www.digitalmarketplace.service.gov.uk'
      });
      universalSetupArguments = window.ga.calls.allArgs();
    });

    it('configures a universal tracker', function() {
      expect(universalSetupArguments[0]).toEqual(['create', 'universal-id', {
        'cookieDomain': 'www.digitalmarketplace.service.gov.uk',
        'allowLinker': true
      }]);
    });
  })

  describe('when setting up cross-domain tracking', function () {
    var sortCalls = function (calls) {
      var gaMethodCalls = {},
          callNum = calls.length;

      while (callNum--) {
        var method = calls[callNum].args.shift(),
            args = calls[callNum].args;

        if (gaMethodCalls.hasOwnProperty(method)) {
          gaMethodCalls[method].push(args);
        } else {
          gaMethodCalls[method] = [args];
        }
      }
      this._calls = gaMethodCalls;
    };
    sortCalls.prototype.callsTo = function (method) {
      if (this._calls.hasOwnProperty(method)) {
        return this._calls[method];
      }
      return [];
    }; 

    beforeEach(function() {
      window.ga.calls.reset();
      analytics = new window.GOVUK.Analytics({
        universalId: 'universal-id',
        cookieDomain: 'www.digitalmarketplace.service.gov.uk'
      });
      analytics.trackPageview();
      analytics.addLinkedTrackerDomain('universal-id', 'link', 'digitalservicesstore.service.gov.uk');
    });

    it('only sets up one tracker', function () {
      var gaMethodCalls = new sortCalls(window.ga.calls.all());
      expect(window.ga.calls.count()).toEqual(5);
      // create tracker
      expect(gaMethodCalls.callsTo('create').length).toEqual(1);
      expect(gaMethodCalls.callsTo('create')[0]).toEqual(['universal-id', { 'cookieDomain': 'www.digitalmarketplace.service.gov.uk', 'allowLinker': true }]);
      // anonymize IP
      expect(gaMethodCalls.callsTo('set').length).toEqual(1);
      expect(gaMethodCalls.callsTo('set')[0]).toEqual(['anonymizeIp', true]);
      // send pageview
      expect(gaMethodCalls.callsTo('send').length).toEqual(1);
      expect(gaMethodCalls.callsTo('send')[0]).toEqual(['pageview']);
      // require linker plugin
      expect(gaMethodCalls.callsTo('require').length).toEqual(1);
      expect(gaMethodCalls.callsTo('require')[0]).toEqual(['linker']);
      // autolink the second domain
      expect(gaMethodCalls.callsTo('linker:autoLink').length).toEqual(1);
      expect(gaMethodCalls.callsTo('linker:autoLink')[0]).toEqual([['digitalservicesstore.service.gov.uk']]);
    });
  });
});

{'fraction_non_alphanumeric': 0.16137781394087333, 'fraction_numerical': 0.003525901817195552, 'mean_word_length': 3.229357798165138, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1544646', 'n_tokens_mistral': 1116, 'n_tokens_neox': 1123, 'n_words': 163}