wineater-bot 1.7.4 → 1.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,20 @@
1
+ const DEFAULT_URL_PATTERNS = {
2
+ PRODUCT_PAGES: /producto\/[^\/]+\/$/, // Matches any product page like 'producto/any-product-name/'
3
+ // CART_PAGE: /carrito\/$/ // Matches the cart page like 'carrito/'
4
+ };
5
+
6
+ // Retrieve custom or default URL patterns from wineaterData
7
+ const urlPatterns = {
8
+ PRODUCT_PAGES: window.wineaterData?.PRODUCT_PAGES || DEFAULT_URL_PATTERNS.PRODUCT_PAGES,
9
+ CART_PAGE: window.wineaterData?.CART_PAGE || DEFAULT_URL_PATTERNS?.CART_PAGE
10
+ };
11
+
12
+ export function shouldOpenChatAutomatically() {
13
+ const currentURL = window.location.href;
14
+ console.log(urlPatterns);
15
+
16
+ if (urlPatterns.PRODUCT_PAGES.test(currentURL) || urlPatterns.CART_PAGE.test(currentURL)) {
17
+ return true;
18
+ }
19
+ return false;
20
+ }
package/src/js/ui.js CHANGED
@@ -1,16 +1,19 @@
1
1
 
2
- import { trackChatbotOpen, trackChatbotClose } from './analytics.js';
2
+ import { trackChatbotOpen, trackChatbotClose, trackChatbotOpenAuto, setCookie, getCookie, deleteCookie } from './analytics.js';
3
+
4
+ const MAX_CHAT_CLOSURES = 3;
3
5
 
4
6
  export function toggleChatWindow() {
5
7
  const chatWindow = document.getElementById('chat-window');
6
8
  const chatIcon = document.getElementById('chat-icon');
9
+
7
10
 
8
11
  // Check if the chat window is currently visible
9
12
  const isWindowOpen = chatWindow.classList.contains('visible');
10
13
 
11
14
  if (isWindowOpen) {
12
15
  trackChatbotClose();
13
- chatWindow.classList.remove('visible');
16
+ closeChatWindow();
14
17
  chatIcon.style.display = 'flex'; // Show the chat icon/button
15
18
  } else {
16
19
  trackChatbotOpen();
@@ -20,13 +23,30 @@ export function toggleChatWindow() {
20
23
  }
21
24
 
22
25
  export function closeChatWindow() {
26
+ console.log('ghbdtn');
23
27
  trackChatbotClose();
24
28
  const chatWindow = document.getElementById('chat-window');
25
29
  chatWindow.classList.remove('visible');
30
+
31
+ let closeCount = parseInt(getCookie('chatCloseCount')) || 0;
32
+ closeCount += 1;
33
+
34
+ if (closeCount >= MAX_CHAT_CLOSURES) {
35
+ console.log(closeCount);
36
+ setCookie('disableAutoOpen', 'true', 1); // Disable auto-opening for 1 day
37
+ deleteCookie('chatCloseCount'); // Reset close count
38
+ } else {
39
+ console.log(closeCount);
40
+ setCookie('chatCloseCount', closeCount, 1); // Update the close count cookie
41
+ }
26
42
  }
27
43
 
28
- export function openChatWindow() {
29
- trackChatbotOpen();
44
+ export function openChatWindow(fromUrl = null) {
45
+ if (!!fromUrl) {
46
+ trackChatbotOpenAuto(fromUrl);
47
+ } else {
48
+ trackChatbotOpen();
49
+ }
30
50
  const chatWindow = document.getElementById('chat-window');
31
51
  chatWindow.classList.add('visible');
32
52
  }