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

Fix tracking in details.js #1962

Merged
merged 2 commits into from
Mar 8, 2021
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
useful summary for people upgrading their application, not a replication
of the commit log.

## Unreleased

* Fix tracking in `details.js` ([PR #1962](https://github.com/alphagov/govuk_publishing_components/pull/1962))

## 24.4.0

* Add border option to breadcrumb ([PR #1952](https://github.com/alphagov/govuk_publishing_components/pull/1952)) MINOR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};

// If a custom label has been provided, we can simply call the tracking module
if (customTrackLabel) {
var trackDetails = new window.GOVUK.Modules.TrackClick()
var trackDetails = new window.GOVUK.Modules.GemTrackClick()
trackDetails.start($module)
} else {
// If no custom label is set, we use the open/close status as the label
Expand Down
10 changes: 2 additions & 8 deletions spec/javascripts/components/details-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,14 @@
describe('Details component', function () {
var FIXTURE

var callback = jasmine.createSpy()
GOVUK.Modules.TrackClick = function () {
this.start = function () {
callback()
}
}

function loadDetailsComponent () {
var details = new GOVUK.Modules.GovukDetails()
details.start($('.gem-c-details'))
}

beforeEach(function () {
spyOn(GOVUK.analytics, 'trackEvent')
spyOn(GOVUK.Modules, 'GemTrackClick').and.callFake(function () { this.start = function () {} })

FIXTURE =
'<details class="gem-c-details govuk-details govuk-!-margin-bottom-3" data-track-category="track-category" data-track-action="track-action" data-track-label="track-label" data-module="govuk-details">' +
Expand All @@ -41,7 +35,7 @@ describe('Details component', function () {
$('.govuk-details__summary').click()

expect(GOVUK.analytics.trackEvent.calls.count()).toEqual(0)
expect(callback).toHaveBeenCalled()
expect(GOVUK.Modules.GemTrackClick.calls.count()).toEqual(1)
})

it('does not fire an event if track category and track action are not present', function () {
Expand Down