Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track number of links on Whitehall finder pages #1090

Merged
merged 1 commit into from
Jul 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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