diff --git a/app/assets/javascripts/analytics-ga4/ga4-finder-tracker.js b/app/assets/javascripts/analytics-ga4/ga4-finder-tracker.js index f0f0b6c98..e4ef216d6 100644 --- a/app/assets/javascripts/analytics-ga4/ga4-finder-tracker.js +++ b/app/assets/javascripts/analytics-ga4/ga4-finder-tracker.js @@ -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) diff --git a/app/assets/javascripts/modules/mobile-filters-modal.js b/app/assets/javascripts/modules/mobile-filters-modal.js index b93a6f7e1..1eea20775 100644 --- a/app/assets/javascripts/modules/mobile-filters-modal.js +++ b/app/assets/javascripts/modules/mobile-filters-modal.js @@ -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 })) } diff --git a/spec/javascripts/components/expander-spec.js b/spec/javascripts/components/expander-spec.js index 70dc665c3..6c31840c8 100644 --- a/spec/javascripts/components/expander-spec.js +++ b/spec/javascripts/components/expander-spec.js @@ -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) diff --git a/spec/javascripts/modules/mobile-filters-modal.spec.js b/spec/javascripts/modules/mobile-filters-modal.spec.js index 42da78329..72fa767aa 100644 --- a/spec/javascripts/modules/mobile-filters-modal.spec.js +++ b/spec/javascripts/modules/mobile-filters-modal.spec.js @@ -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)) })