Skip to content

Commit

Permalink
Merge pull request #1090 from alphagov/track-number-links-in-whitehal…
Browse files Browse the repository at this point in the history
…l-finders

Track number of links on Whitehall finder pages
  • Loading branch information
carvil authored Jul 20, 2017
2 parents 5689671 + 66ee76b commit ffee2a9
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/assets/javascripts/analytics/custom-dimensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@
var policyAreaLinks =
$('section.document-block a').length +
$('section .collection-list h2 a').length
var whitehallFinderPageLinks =
$('.document-list .document-row h3 a').length;

var linksCount =
relatedLinks ||
Expand All @@ -133,7 +135,8 @@
leafLinks ||
browsePageLinks ||
topicPageLinks ||
policyAreaLinks;
policyAreaLinks ||
whitehallFinderPageLinks;

return linksCount;
}
Expand Down
47 changes: 47 additions & 0 deletions spec/javascripts/analytics/static-analytics-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,53 @@ describe("GOVUK.StaticAnalytics", function() {
expect(pageViewObject.dimension26).toEqual('2');
});
});

describe('on a whitehall finder page (e.g Announcements)', function() {
beforeEach(function() {
$('body').append('\
<div class="test-fixture">\
<ol class="document-list">\
<li class="document-row">\
<h3>\
<a href="/government/news/news-article-1">\
Creative sector receives record boost of £700 million pounds\
</a>\
</h3>\
</li>\
<li class="document-row">\
<h3>\
<a href="/government/news/news-article-2">\
Dangerous occurrence at Broad Oak level crossing\
</a>\
</h3>\
</li>\
<li class="document-row">\
<h3>\
<a href="/government/news/news-article-3">\
Outbreaks of Koi herpesvirus (KHV) disease in 2017\
</a>\
</h3>\
</li>\
</div>\
');
});

afterEach(function() {
$('.test-fixture').remove();
});

it('tracks the number of sections', function() {
analytics = new GOVUK.StaticAnalytics({universalId: 'universal-id'});
pageViewObject = getPageViewObject();
expect(pageViewObject.dimension26).toEqual('0');
});

it('tracks the total number of links', function() {
analytics = new GOVUK.StaticAnalytics({universalId: 'universal-id'});
pageViewObject = getPageViewObject();
expect(pageViewObject.dimension27).toEqual('3');
});
});
});
});

Expand Down

0 comments on commit ffee2a9

Please sign in to comment.