diff --git a/app/assets/javascripts/analytics/custom-dimensions.js b/app/assets/javascripts/analytics/custom-dimensions.js
index d1c16c7da..866bcc5de 100644
--- a/app/assets/javascripts/analytics/custom-dimensions.js
+++ b/app/assets/javascripts/analytics/custom-dimensions.js
@@ -82,15 +82,14 @@
}
});
- customDimensions['dimension23'] = $('main[id="content"]').attr('lang') || 'unknown';
-
return customDimensions;
}
function customDimensionsFromDom() {
return {
dimension26: GOVUK.PageContent.getNumberOfSections(),
- dimension27: GOVUK.PageContent.getNumberOfLinks()
+ dimension27: GOVUK.PageContent.getNumberOfLinks(),
+ dimension23: $('main[id="content"]').attr('lang') || 'unknown'
};
}
diff --git a/spec/javascripts/analytics/static-analytics-spec.js b/spec/javascripts/analytics/static-analytics-spec.js
index 49e4fdbcd..ac5bb3739 100644
--- a/spec/javascripts/analytics/static-analytics-spec.js
+++ b/spec/javascripts/analytics/static-analytics-spec.js
@@ -46,33 +46,6 @@ describe("GOVUK.StaticAnalytics", function() {
expect(GOVUK.analyticsPlugins.error).toHaveBeenCalled();
});
- describe('when ecommerce results are present', function() {
- beforeEach(function() {
- window.ga.calls.reset();
- });
-
- afterEach(function() {
- $('.test-fixture').remove();
- });
-
- it('sends the ecommerce fields', function() {
- $('body').append('\
-
\
-
\
- ')
- analytics = new GOVUK.StaticAnalytics({universalId: 'universal-id'});
- pageViewObject = getPageViewObject();
- expect(window.ga).toHaveBeenCalledWith('send', 'pageview', pageViewObject);
- });
- });
-
describe('when there are govuk: meta tags', function() {
beforeEach(function() {
window.ga.calls.reset();
@@ -82,50 +55,6 @@ describe("GOVUK.StaticAnalytics", function() {
$('head').find('meta[name^="govuk:"]').remove();
});
- it('sets them as dimensions', function() {
- $('body').append('\
-
\
- \
-
\
- ');
- $('head').append('\
-
\
-
\
-
\
-
\
-
\
-
\
-
\
-
\
-
\
-
\
- ');
- analytics = new GOVUK.StaticAnalytics({universalId: 'universal-id'});
- pageViewObject = getPageViewObject();
-
- expect(pageViewObject.dimension1).toEqual('section');
- expect(pageViewObject.dimension2).toEqual('format');
- expect(pageViewObject.dimension5).toEqual('1000');
- expect(pageViewObject.dimension6).toEqual('2005-to-2010-labour-government');
- expect(pageViewObject.dimension7).toEqual('historic');
- expect(pageViewObject.dimension9).toEqual('
');
- expect(pageViewObject.dimension10).toEqual('');
- expect(pageViewObject.dimension12).toEqual('withdrawn');
- expect(pageViewObject.dimension17).toEqual('schema-name');
- expect(pageViewObject.dimension23).toEqual('fr');
- expect(pageViewObject.dimension30).toEqual('education')
- });
-
- it('ignores meta tags not set', function() {
- $('head').append('');
-
- analytics = new GOVUK.StaticAnalytics({universalId: 'universal-id'});
- pageViewObject = getPageViewObject();
-
- expect(Object.keys(pageViewObject).length).toEqual(1 + numberOfDimensionsWithDefaultValues);
- expect(pageViewObject.dimension1).toEqual('section');
- });
-
it('sets A/B meta tags as dimensions', function() {
$('head').append('\
\
@@ -139,17 +68,26 @@ describe("GOVUK.StaticAnalytics", function() {
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('\
\
- \
+ \
');
analytics = new GOVUK.StaticAnalytics({universalId: 'universal-id'});
pageViewObject = getPageViewObject();
- expect(Object.keys(pageViewObject).length).toEqual(numberOfDimensionsWithDefaultValues);
+ // 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');
});
[
@@ -202,12 +140,22 @@ describe("GOVUK.StaticAnalytics", function() {
name: 'navigation-legacy',
number: 30,
defaultValue: 'none'
+ },
+ {
+ name: 'withdrawn',
+ number: 12,
+ defaultValue: 'not withdrawn'
+ },
+ {
+ name: 'content-has-history',
+ number: 39,
+ defaultValue: 'false'
}
].forEach(function (dimension) {
it('sets the ' + dimension.name + ' dimension from a meta tag if present', function () {
$('head').append('\
- \
- ');
+ \
+ ');
analytics = new GOVUK.StaticAnalytics({universalId: 'universal-id'});
pageViewObject = getPageViewObject();
@@ -223,270 +171,327 @@ describe("GOVUK.StaticAnalytics", function() {
});
});
- describe('when tracking the number of sections and links on a page', function() {
- describe('on a page with a normal sidebar', function() {
- beforeEach(function() {
- $('head').append('\
- \
- \
- \
-
\
- ')
- $('body').append('\
- \
+ ');
});
- describe('on a page with a taxon sidebar', function() {
- beforeEach(function() {
- $('head').append('\
- \
- \
- \
-
\
- ')
- $('body').append('\
- \
-