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

  beforeEach(function() {
    window.ga = function() {};
    spyOn(window, 'ga');
    spyOn(GOVUK.analyticsPlugins, 'printIntent');
    spyOn(GOVUK.analyticsPlugins, 'error');
    analytics = new GOVUK.StaticAnalytics({
      universalId: 'universal-id',
      cookieDomain: '.www.gov.uk'
    });
  });

  describe('when created', function() {
    // The number of setup arguments which are set before the dimensions
    const numberOfDimensionsWithDefaultValues = 18;

    var pageViewObject;

    beforeEach(function() {
      pageViewObject = getPageViewObject();
    });

    it('configures a universal tracker', function() {
      expect(window.ga).toHaveBeenCalledWith('create', 'universal-id', {'cookieDomain': '.www.gov.uk'});
    });

    it('sets the device pixel ratio', function() {
      expect(Object.keys(pageViewObject)).toContain('dimension11');
    });

    it('sets the HTTP status code', function() {
      expect(Object.keys(pageViewObject)).toContain('dimension15');
    });

    it('tracks a pageview in universal', function() {
      expect(window.ga).toHaveBeenCalledWith('send', 'pageview', pageViewObject);
    });

    it('begins print tracking', function() {
      expect(GOVUK.analyticsPlugins.printIntent).toHaveBeenCalled();
    });

    it('begins error tracking', function() {
      expect(GOVUK.analyticsPlugins.error).toHaveBeenCalled();
    });

    describe('when there are govuk: meta tags', function() {
      beforeEach(function() {
        window.ga.calls.reset();
      });

      afterEach(function() {
        $('head').find('meta[name^="govuk:"]').remove();
      });

      it('sets A/B meta tags as dimensions', function() {
        $('head').append('\
          <meta name="govuk:ab-test" content="name-of-test:name-of-ab-bucket" data-analytics-dimension="42">\
          <meta name="govuk:ab-test" content="name-of-other-test:name-of-other-ab-bucket" data-analytics-dimension="48">\
        ');

        analytics = new GOVUK.StaticAnalytics({universalId: 'universal-id'});
        pageViewObject = getPageViewObject();

        expect(pageViewObject.dimension42).toEqual('name-of-test:name-of-ab-bucket');
        expect(pageViewObject.dimension48).toEqual('name-of-other-test:name-of-other-ab-bucket');
      });

      it('ignores A/B meta tags with invalid dimensions', function () {
        $('head').append('\
          <meta name="govuk:ab-test" content="name-of-test:some-bucket">\
          <meta name="govuk:ab-test" content="name-of-test:some-bucket" data-analytics-dimension="not a number">\
        ');

        analytics = new GOVUK.StaticAnalytics({universalId: 'universal-id'});
        pageViewObject = getPageViewObject();

        expect(Object.keys(pageViewObject).length).toEqual(numberOfDimensionsWithDefaultValues);
      });

      [
        {
          name: 'themes',
          number: 3,
          defaultValue: 'other'
        },
        {
          name: 'navigation-page-type',
          number: 32,
          defaultValue: 'none'
        },
        {
          name: 'user-journey-stage',
          number: 33,
          defaultValue: 'thing'
        },
        {
          name: 'navigation-document-type',
          number: 34,
          defaultValue: 'other'
        },
        {
          name: 'content-id',
          number: 4,
          defaultValue: '00000000-0000-0000-0000-000000000000'<commit_msg>Make a-b test meta-tag test more robust<commit_after>describe("GOVUK.StaticAnalytics", function() {
  var analytics;

  beforeEach(function() {
    window.ga = function() {};
    spyOn(window, 'ga');
    spyOn(GOVUK.analyticsPlugins, 'printIntent');
    spyOn(GOVUK.analyticsPlugins, 'error');
    analytics = new GOVUK.StaticAnalytics({
      universalId: 'universal-id',
      cookieDomain: '.www.gov.uk'
    });
  });

  describe('when created', function() {
    // The number of setup arguments which are set before the dimensions
    const numberOfDimensionsWithDefaultValues = 18;

    var pageViewObject;

    beforeEach(function() {
      pageViewObject = getPageViewObject();
    });

    it('configures a universal tracker', function() {
      expect(window.ga).toHaveBeenCalledWith('create', 'universal-id', {'cookieDomain': '.www.gov.uk'});
    });

    it('sets the device pixel ratio', function() {
      expect(Object.keys(pageViewObject)).toContain('dimension11');
    });

    it('sets the HTTP status code', function() {
      expect(Object.keys(pageViewObject)).toContain('dimension15');
    });

    it('tracks a pageview in universal', function() {
      expect(window.ga).toHaveBeenCalledWith('send', 'pageview', pageViewObject);
    });

    it('begins print tracking', function() {
      expect(GOVUK.analyticsPlugins.printIntent).toHaveBeenCalled();
    });

    it('begins error tracking', function() {
      expect(GOVUK.analyticsPlugins.error).toHaveBeenCalled();
    });

    describe('when there are govuk: meta tags', function() {
      beforeEach(function() {
        window.ga.calls.reset();
      });

      afterEach(function() {
        $('head').find('meta[name^="govuk:"]').remove();
      });

      it('sets A/B meta tags as dimensions', function() {
        $('head').append('\
          <meta name="govuk:ab-test" content="name-of-test:name-of-ab-bucket" data-analytics-dimension="42">\
          <meta name="govuk:ab-test" content="name-of-other-test:name-of-other-ab-bucket" data-analytics-dimension="48">\
        ');

        analytics = new GOVUK.StaticAnalytics({universalId: 'universal-id'});
        pageViewObject = getPageViewObject();

        expect(pageViewObject.dimension42).toEqual('name-of-test:name-of-ab-bucket');
        expect(pageViewObject.dimension48).toEqual('name-of-other-test:name-of-other-ab-bucket');
      });

      it('ignores A/B meta tags with invalid dimensions', function () {
        $('head').append('\
          <meta name="govuk:ab-test" content="name-of-test:some-bucket">\
          <meta name="govuk:ab-test" content="name-of-test:some-other-bucket" data-analytics-dimension="not a number">\
        ');

        analytics = new GOVUK.StaticAnalytics({universalId: 'universal-id'});
        pageViewObject = getPageViewObject();

        // 1. check the dimensions haven't been created by using the "value" of data-analytics-dimension
        expect(pageViewObject.hasOwnProperty('dimensionnot a number')).toEqual(false);
        expect(pageViewObject.hasOwnProperty('dimensionundefined')).toEqual(false);

        // 2. check the values haven't been used at all
        var values = [];
        for (key in pageViewObject) {
          values.push(pageViewObject[key]);
        }
        expect(values).not.toContain('name-of-test:some-bucket');
        expect(values).not.toContain('name-of-test:some-other-bucket');
      });

      [
        {
          name: 'themes',
          number: 3,
          defaultValue: 'other'
        },
        {
          name: 'navigation-page-type',
          number: 32,
          defaultValue: 'none'
        },
        {
          name: 'user-journey-stage',
          number: 33,
          defaultValue: 'thing'
        },
        {
          name: 'navigation-document-type',
          number: 34,
          defaultValue: 'other'
        },
        {
          name: 'content-id',
          number: 4,
          defaultValue: '00000000-0000-0000-0000-000000000000'
{'fraction_non_alphanumeric': 0.15386677389089934, 'fraction_numerical': 0.014743331993030425, 'mean_word_length': 2.731, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, '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': '5825747', 'n_tokens_mistral': 2334, 'n_tokens_neox': 2198, 'n_words': 387}