Skip to content

Commit

Permalink
Merge pull request #1962 from alphagov/fix-bespoke-details-tracking
Browse files Browse the repository at this point in the history
Fix tracking in details.js
  • Loading branch information
alex-ju authored Mar 8, 2021
2 parents c626d1e + 545a9e0 commit ab6e01d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
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

0 comments on commit ab6e01d

Please sign in to comment.