From a030156c5ff5ab07673b72b7bb36ee24caad5311 Mon Sep 17 00:00:00 2001 From: Vadym Shevchuk <42058438+insssomniac@users.noreply.github.com> Date: Thu, 21 Dec 2023 10:45:13 +0200 Subject: [PATCH] RZ-9295 same approach for the link in the last message and final button (#59) * RZ-9295 same approach for the link in the last message and final button * RZ-9295 fix link event listener logic --- src/lib/chat-ui.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/lib/chat-ui.js b/src/lib/chat-ui.js index a15c05a..6aede34 100644 --- a/src/lib/chat-ui.js +++ b/src/lib/chat-ui.js @@ -218,6 +218,7 @@ const ChatUi = { this.link.remove(); } } + if (content.includes(intentionType.email)) { this.setEmailVisibility(); } @@ -480,6 +481,7 @@ const ChatUi = { */ setCtaButton() { this.elements.ctaButton.classList.remove('hidden'); + this.attachLinkEventListener(); if (getTerm() === experimentsPrompt.finalPage) { this.setCtaButtonToClose(); } else { @@ -501,6 +503,18 @@ const ChatUi = { }); }, + attachLinkEventListener() { + const links = document.querySelectorAll('.js-assistant-message a'); + const link = links[links.length - 1]; + + if (link) { + link.addEventListener('click', () => { + this.track(customEventTypes.linkClicked); + this.closeWidget(); + }); + } + }, + /** * Sets custom variables and applies them to the main container element and font family. * Theme-specific properties are handled separately.