Skip to content

Commit 635b477

Browse files
authored
Merge pull request #1440 from alphagov/update-details-ga-event-structure
Update event structure for details_opened GA event
2 parents 01d8b6b + 36e3272 commit 635b477

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

app/frontend/javascript/utils/google-analytics/index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,12 @@ export function attachDetailsOpenTracker () {
105105
const summary = detailsElement.querySelector('summary')
106106
if (detailsElement.open) {
107107
window.dataLayer.push({
108-
event: 'details_opened',
109-
url: window.location,
110-
text: summary.textContent
108+
event: 'event_data',
109+
event_data: {
110+
event_name: 'details_opened',
111+
url: window.location,
112+
text: summary.textContent
113+
}
111114
})
112115
}
113116
})

app/frontend/javascript/utils/google-analytics/index.test.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,12 @@ describe('google_tag.mjs', () => {
206206
document.querySelector('details').querySelector('summary').click()
207207

208208
expect(window.dataLayer).toContainEqual({
209-
event: 'details_opened',
210-
url: document.location,
211-
text: summaryText
209+
event: 'event_data',
210+
event_data: {
211+
event_name: 'details_opened',
212+
url: document.location,
213+
text: summaryText
214+
}
212215
})
213216
})
214217
})

0 commit comments

Comments
 (0)