Skip to content

Commit

Permalink
Merge pull request #3189 from alphagov/flatten-ga4-data
Browse files Browse the repository at this point in the history
Flatten GA4 data attributes
  • Loading branch information
andysellick authored Oct 27, 2023
2 parents 74b3a0a + 729fcc6 commit 8bff168
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
6 changes: 5 additions & 1 deletion app/assets/javascripts/analytics-ga4/ga4-finder-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,11 @@
try {
var index = button.closest('[data-ga4-index]') || undefined
if (index) {
ga4JSON.index = JSON.parse(index.getAttribute('data-ga4-index'))
var indexData = JSON.parse(index.getAttribute('data-ga4-index'))
// flatten the attributes in index into the main data
for (var prop in indexData) {
ga4JSON[prop] = indexData[prop]
}
} else {
console.warn('No data-ga4-index found on the following element or its parents:')
console.warn(button)
Expand Down
6 changes: 2 additions & 4 deletions app/assets/javascripts/modules/mobile-filters-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
type: 'finder',
text: 'Filter',
section: 'Filter',
index: {
index_section: 0,
index_section_count: indexSectionCount
}
index_section: 0,
index_section_count: indexSectionCount
}))
}

Expand Down
6 changes: 2 additions & 4 deletions spec/javascripts/components/expander-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,8 @@ describe('An expander module', function () {
event_name: 'select_content',
type: 'finder',
section: 'Organisation',
index: {
index_section: 1,
index_section_count: 3
}
index_section: 1,
index_section_count: 3
})

expect($button.attr('data-ga4-event')).toEqual(expected)
Expand Down
6 changes: 2 additions & 4 deletions spec/javascripts/modules/mobile-filters-modal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,8 @@ describe('Mobile filters', function () {
type: 'finder',
text: 'Filter',
section: 'Filter',
index: {
index_section: 0,
index_section_count: 5
}
index_section: 0,
index_section_count: 5
}
expect(button.getAttribute('data-ga4-event')).toEqual(JSON.stringify(expected))
})
Expand Down

0 comments on commit 8bff168

Please sign in to comment.