From ce4f5e4c03231fc105bb9668bcca9be78e58a9f7 Mon Sep 17 00:00:00 2001
From: insssomniac <insssomniac@gmail.com>
Date: Thu, 30 Nov 2023 15:02:02 +0200
Subject: [PATCH] RZ-9295 same approach for the link in the last message and
 final button

---
 package-lock.json  |  4 ++--
 src/lib/chat-ui.js | 13 +++++++++++++
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/package-lock.json b/package-lock.json
index ef2b355..ee8528d 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
 {
   "name": "1ff-chat-ui",
-  "version": "1.0.46",
+  "version": "1.0.47",
   "lockfileVersion": 2,
   "requires": true,
   "packages": {
     "": {
       "name": "1ff-chat-ui",
-      "version": "1.0.46",
+      "version": "1.0.47",
       "license": "ISC",
       "dependencies": {
         "socket.io-client": "^4.6.1"
diff --git a/src/lib/chat-ui.js b/src/lib/chat-ui.js
index a15c05a..ee0ee25 100644
--- a/src/lib/chat-ui.js
+++ b/src/lib/chat-ui.js
@@ -214,10 +214,12 @@ const ChatUi = {
 
     if (this.link) {
       this.setCtaButton();
+      this.attachLinkEventListener();
       if(getTerm() === experimentsPrompt.finalPage){
         this.link.remove();
       }
     }
+
     if (content.includes(intentionType.email)) {
       this.setEmailVisibility();
     }
@@ -377,6 +379,7 @@ const ChatUi = {
       this.link = constructLink(this.boldedText);
       if (this.link) {
         this.setCtaButton();
+        this.attachLinkEventListener();
       }
 
       let strongTaggedText = this.boldedText.replace('{', '').replace('}', '');
@@ -501,6 +504,16 @@ const ChatUi = {
     });
   },
 
+  attachLinkEventListener() {
+    const links = document.querySelectorAll('.js-assistant-message a');
+    const link = links[links.length - 1];
+
+    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.