diff --git a/libs/blocks/modal/modal.js b/libs/blocks/modal/modal.js index 443ff92c29..bb4949feb0 100644 --- a/libs/blocks/modal/modal.js +++ b/libs/blocks/modal/modal.js @@ -32,11 +32,6 @@ export function closeModal(modal) { const { id } = modal; const closeEvent = new Event('milo:modal:closed'); window.dispatchEvent(closeEvent); - const localeModal = id?.includes('locale-modal') ? 'localeModal' : 'milo'; - const analyticsEventName = window.location.hash ? window.location.hash.replace('#', '') : localeModal; - const closeEventAnalytics = new Event(`${analyticsEventName}:modalClose:buttonClose`); - - sendAnalytics(closeEventAnalytics); document.querySelectorAll(`#${id}`).forEach((mod) => { if (mod.classList.contains('dialog-modal')) { @@ -102,7 +97,13 @@ export async function getModal(details, custom) { if (custom) getCustomModal(custom, dialog); if (details) await getPathModal(details.path, dialog); - const close = createTag('button', { class: 'dialog-close', 'aria-label': 'Close' }, CLOSE_ICON); + const localeModal = id?.includes('locale-modal') ? 'localeModal' : 'milo'; + const analyticsEventName = window.location.hash ? window.location.hash.replace('#', '') : localeModal; + const close = createTag('button', { + class: 'dialog-close', + 'aria-label': 'Close', + 'daa-ll': `${analyticsEventName}:modalClose:buttonClose`, + }, CLOSE_ICON); const focusVisible = { focusVisible: true }; const focusablesOnLoad = [...dialog.querySelectorAll(FOCUSABLES)]; diff --git a/test/blocks/modals/modals.test.js b/test/blocks/modals/modals.test.js index daf6ddc950..ef5e9ad860 100644 --- a/test/blocks/modals/modals.test.js +++ b/test/blocks/modals/modals.test.js @@ -40,6 +40,7 @@ describe('Modals', () => { window.location.hash = '#milo'; await waitForElement('#milo'); const close = document.querySelector('.dialog-close'); + expect(close.getAttribute('daa-ll')).to.equal('milo:modalClose:buttonClose'); close.click(); await waitForRemoval('#milo'); expect(window.location.hash).to.be.empty;