wineater-bot 1.5.20 → 1.5.22
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.
- package/dist/wineater-chatbot.mjs +75 -58
- package/dist/wineater-chatbot.umd.js +12 -12
- package/package.json +1 -1
- package/src/index.js +2 -1
- package/src/js/analytics.js +46 -18
- package/src/js/styles.js +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const b = `
|
|
2
2
|
@font-face {
|
|
3
3
|
font-family: 'Poppins';
|
|
4
4
|
src: url('https://fonts.googleapis.com/css2?family=Poppins:wght@400&display=swap');
|
|
@@ -191,7 +191,7 @@ const f = `
|
|
|
191
191
|
}
|
|
192
192
|
|
|
193
193
|
.wine-item a {
|
|
194
|
-
color: #7E27ED;
|
|
194
|
+
color: #7E27ED !important;
|
|
195
195
|
}
|
|
196
196
|
|
|
197
197
|
.wine-item img {
|
|
@@ -277,10 +277,16 @@ const f = `
|
|
|
277
277
|
.typing-indicator.visible {
|
|
278
278
|
visibility: visible;
|
|
279
279
|
height: 50px;
|
|
280
|
-
}`,
|
|
281
|
-
|
|
282
|
-
document.head.appendChild(
|
|
283
|
-
function
|
|
280
|
+
}`, h = document.createElement("style");
|
|
281
|
+
h.textContent = b;
|
|
282
|
+
document.head.appendChild(h);
|
|
283
|
+
function y() {
|
|
284
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(o) {
|
|
285
|
+
const t = Math.random() * 16 | 0;
|
|
286
|
+
return (o === "x" ? t : t & 3 | 8).toString(16);
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
function p(o, t, e) {
|
|
284
290
|
let n = "";
|
|
285
291
|
if (e) {
|
|
286
292
|
const i = /* @__PURE__ */ new Date();
|
|
@@ -288,10 +294,21 @@ function b(o, t, e) {
|
|
|
288
294
|
}
|
|
289
295
|
document.cookie = o + "=" + (t || "") + n + "; path=/; secure; samesite=strict";
|
|
290
296
|
}
|
|
291
|
-
function
|
|
292
|
-
const e =
|
|
293
|
-
|
|
294
|
-
|
|
297
|
+
function s(o) {
|
|
298
|
+
const t = o + "=", e = document.cookie.split(";");
|
|
299
|
+
for (let n = 0; n < e.length; n++) {
|
|
300
|
+
let i = e[n];
|
|
301
|
+
for (; i.charAt(0) === " "; )
|
|
302
|
+
i = i.substring(1, i.length);
|
|
303
|
+
if (i.indexOf(t) === 0)
|
|
304
|
+
return i.substring(t.length, i.length);
|
|
305
|
+
}
|
|
306
|
+
return null;
|
|
307
|
+
}
|
|
308
|
+
function x() {
|
|
309
|
+
const o = "uniqueUserID";
|
|
310
|
+
let t = s(o);
|
|
311
|
+
return t || (t = y(), p(o, t, 365)), t;
|
|
295
312
|
}
|
|
296
313
|
function d(o, t) {
|
|
297
314
|
fetch("https://api.wineater.com/proxy/track", {
|
|
@@ -309,39 +326,39 @@ function d(o, t) {
|
|
|
309
326
|
console.error("Mixpanel tracking error", i);
|
|
310
327
|
});
|
|
311
328
|
}
|
|
312
|
-
function h() {
|
|
313
|
-
d("Chatbot Opened", { distinct_id: r("chatbotToken") });
|
|
314
|
-
}
|
|
315
329
|
function g() {
|
|
316
|
-
d("Chatbot
|
|
330
|
+
d("Chatbot Opened", { distinct_id: s("uniqueUserID"), client: s("chatbotToken") });
|
|
317
331
|
}
|
|
318
|
-
function
|
|
319
|
-
d("
|
|
332
|
+
function u() {
|
|
333
|
+
d("Chatbot Closed", { distinct_id: s("uniqueUserID"), client: s("chatbotToken") });
|
|
320
334
|
}
|
|
321
335
|
function w(o) {
|
|
322
|
-
d("Message Sent", { distinct_id:
|
|
336
|
+
d("Message Sent", { distinct_id: s("uniqueUserID"), message_content: o, client: s("chatbotToken") });
|
|
323
337
|
}
|
|
324
|
-
function
|
|
325
|
-
d("
|
|
338
|
+
function v(o) {
|
|
339
|
+
d("Products Got", { distinct_id: s("uniqueUserID"), products: o, client: s("chatbotToken") });
|
|
326
340
|
}
|
|
327
|
-
function
|
|
341
|
+
function k(o) {
|
|
342
|
+
d("Product Clicked", { distinct_id: s("uniqueUserID"), product_id: o, client: s("chatbotToken") });
|
|
343
|
+
}
|
|
344
|
+
function m() {
|
|
328
345
|
const o = document.getElementById("chat-window"), t = document.getElementById("chat-icon");
|
|
329
|
-
o.classList.contains("visible") ? (
|
|
346
|
+
o.classList.contains("visible") ? (u(), o.classList.remove("visible"), t.style.display = "flex") : (g(), o.classList.add("visible"), t.style.display = "none");
|
|
330
347
|
}
|
|
331
|
-
function
|
|
332
|
-
|
|
348
|
+
function I() {
|
|
349
|
+
u(), document.getElementById("chat-window").classList.remove("visible");
|
|
333
350
|
}
|
|
334
|
-
function
|
|
335
|
-
|
|
351
|
+
function E() {
|
|
352
|
+
g(), document.getElementById("chat-window").classList.add("visible");
|
|
336
353
|
}
|
|
337
354
|
document.addEventListener("DOMContentLoaded", () => {
|
|
338
355
|
setupCloseButton(), setupOutsideClick();
|
|
339
356
|
});
|
|
340
|
-
const
|
|
341
|
-
class
|
|
357
|
+
const C = ["climats", "telckel", "biobio", "weinpoint"], T = "OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";
|
|
358
|
+
class f {
|
|
342
359
|
constructor(t) {
|
|
343
360
|
var e;
|
|
344
|
-
this.baseURL = "https://api.wineater.com/", this.store =
|
|
361
|
+
this.baseURL = "https://api.wineater.com/", this.store = C.find((n) => window.location.href.includes(n)), this.token = ((e = window == null ? void 0 : window.wineaterData) == null ? void 0 : e.CLIENT_TOKEN) || T;
|
|
345
362
|
}
|
|
346
363
|
async getStoreConfig(t) {
|
|
347
364
|
console.log(t);
|
|
@@ -380,9 +397,9 @@ class m {
|
|
|
380
397
|
}
|
|
381
398
|
}
|
|
382
399
|
}
|
|
383
|
-
class
|
|
400
|
+
class B {
|
|
384
401
|
constructor() {
|
|
385
|
-
this.api = new
|
|
402
|
+
this.api = new f(), this.language = "en", this.translations = {
|
|
386
403
|
fr: {
|
|
387
404
|
welcomeMessage: "Sublimez votre expérience gastronomique. Il vous suffit de donner les détails de votre plat, et obtenez la recommandation de compagnon de vin idéale. Que voulez-vous manger?",
|
|
388
405
|
noResultsFound: "Aucun résultat trouvé.",
|
|
@@ -457,10 +474,10 @@ class C {
|
|
|
457
474
|
return this.translations[this.language][t] || t;
|
|
458
475
|
}
|
|
459
476
|
}
|
|
460
|
-
const
|
|
461
|
-
class
|
|
477
|
+
const a = new B();
|
|
478
|
+
class W {
|
|
462
479
|
constructor() {
|
|
463
|
-
this.api = new
|
|
480
|
+
this.api = new f(), this.displayFirstMessage(a.translate("welcomeMessage"));
|
|
464
481
|
}
|
|
465
482
|
initialize() {
|
|
466
483
|
document.getElementById("send-button").addEventListener("click", () => this.handleUserInput()), document.getElementById("user-input").addEventListener("keypress", (n) => {
|
|
@@ -476,11 +493,11 @@ class T {
|
|
|
476
493
|
if (e) {
|
|
477
494
|
this.displayMessage(e, "user"), t.value = "", this.showTypingIndicator();
|
|
478
495
|
try {
|
|
479
|
-
|
|
496
|
+
w(e);
|
|
480
497
|
const n = await this.api.getWineRecommendations(e);
|
|
481
498
|
this.hideTypingIndicator(), n && n.length ? this.displayResults(n) : this.displayMessage("No results found.", "api");
|
|
482
499
|
} catch {
|
|
483
|
-
this.hideTypingIndicator(), this.displayMessage(
|
|
500
|
+
this.hideTypingIndicator(), this.displayMessage(a.translate("somethingWentWrong"), "api");
|
|
484
501
|
}
|
|
485
502
|
}
|
|
486
503
|
}
|
|
@@ -495,36 +512,36 @@ class T {
|
|
|
495
512
|
i.textContent = t, i.className = "message " + e, n.appendChild(i), n.scrollTop = n.scrollHeight;
|
|
496
513
|
}
|
|
497
514
|
sendAnalytics(t) {
|
|
498
|
-
|
|
515
|
+
k(t);
|
|
499
516
|
}
|
|
500
517
|
displayResults(t) {
|
|
501
518
|
const e = document.getElementById("message-container");
|
|
502
|
-
|
|
519
|
+
v(t.map((n) => n.Title)), t.forEach((n) => {
|
|
503
520
|
const i = document.createElement("div");
|
|
504
521
|
i.className = "wine-item";
|
|
505
|
-
const
|
|
506
|
-
|
|
522
|
+
const r = document.createElement("img");
|
|
523
|
+
r.src = n.Image, i.appendChild(r);
|
|
507
524
|
const c = document.createElement("div");
|
|
508
525
|
c.innerHTML = `
|
|
509
526
|
<strong>${n.Title}</strong><br>
|
|
510
|
-
${
|
|
511
|
-
${
|
|
512
|
-
${
|
|
513
|
-
<a href="${n.Url}" onclick="sendAnalytics(${n.Title})" target="_blank">${
|
|
527
|
+
${a.translate("price")}: ${n.Price}<br>
|
|
528
|
+
${a.translate("region")}: ${n.Region}<br>
|
|
529
|
+
${a.translate("type")}: ${n.Type}<br>
|
|
530
|
+
<a href="${n.Url}" onclick="sendAnalytics(${n.Title})" target="_blank">${a.translate("moreInfo")}</a>
|
|
514
531
|
`, i.appendChild(c), e.appendChild(i);
|
|
515
532
|
}), e.scrollTop = e.scrollHeight;
|
|
516
533
|
}
|
|
517
534
|
}
|
|
518
|
-
const
|
|
535
|
+
const P = "OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";
|
|
519
536
|
document.addEventListener("DOMContentLoaded", () => {
|
|
520
|
-
window.toggleChatWindow =
|
|
537
|
+
window.toggleChatWindow = m, window.closeChatWindow = I, window.openChatWindow = E;
|
|
521
538
|
});
|
|
522
|
-
function
|
|
539
|
+
function L() {
|
|
523
540
|
const o = `
|
|
524
541
|
<div id="chatbot-container">
|
|
525
542
|
<div id="chat-icon" onclick="toggleChatWindow()">
|
|
526
543
|
<img src="https://landing-static.s3.eu-central-1.amazonaws.com/images/chat-icon.svg" alt="Chat Icon"> <!-- Update the path to your logo image -->
|
|
527
|
-
<span>${
|
|
544
|
+
<span>${a.translate("chatButton")}</span>
|
|
528
545
|
</div>
|
|
529
546
|
|
|
530
547
|
<div id="chat-window" class="hidden">
|
|
@@ -543,24 +560,24 @@ function W() {
|
|
|
543
560
|
<span></span><span></span><span></span>
|
|
544
561
|
</div>
|
|
545
562
|
<div id="input-container">
|
|
546
|
-
<input type="text" id="user-input" placeholder="${
|
|
547
|
-
<button id="send-button">${
|
|
563
|
+
<input type="text" id="user-input" placeholder="${a.translate("inputPlaceholder")}">
|
|
564
|
+
<button id="send-button">${a.translate("sendButton")}</button>
|
|
548
565
|
</div>
|
|
549
566
|
</div>
|
|
550
567
|
</div>
|
|
551
568
|
`;
|
|
552
569
|
document.body.insertAdjacentHTML("beforeend", o);
|
|
553
570
|
}
|
|
554
|
-
function
|
|
555
|
-
document.getElementById("close-btn").addEventListener("click",
|
|
571
|
+
function S() {
|
|
572
|
+
document.getElementById("close-btn").addEventListener("click", m);
|
|
556
573
|
}
|
|
557
|
-
function
|
|
574
|
+
function O() {
|
|
558
575
|
window.addEventListener("click", function(o) {
|
|
559
576
|
const t = document.getElementById("chat-window"), e = document.getElementById("chat-icon");
|
|
560
577
|
!t.contains(o.target) && !e.contains(o.target) && (t.classList.remove("visible"), e.style.display = "flex");
|
|
561
578
|
});
|
|
562
579
|
}
|
|
563
|
-
function
|
|
580
|
+
function D(o) {
|
|
564
581
|
console.log(o);
|
|
565
582
|
const t = document.getElementById("chat-icon"), e = document.getElementById("chat-window");
|
|
566
583
|
t.className = "", e.className = "", o === "right-center" ? (t.classList.add("chat-icon-right-center"), e.classList.add("right-center-aligned")) : t.classList.add("chat-icon-bottom-right");
|
|
@@ -569,14 +586,14 @@ var l;
|
|
|
569
586
|
if (typeof window < "u") {
|
|
570
587
|
const o = ((l = window.wineaterData) == null ? void 0 : l.POSITION) || "bottom-right";
|
|
571
588
|
window.addEventListener("DOMContentLoaded", async () => {
|
|
572
|
-
var
|
|
589
|
+
var r;
|
|
573
590
|
const e = ["climats", "telckel", "biobio", "weinpoint", "vinigrandi"].find((c) => window.location.href.includes(c)) || null;
|
|
574
591
|
let n;
|
|
575
|
-
e && (n = e.charAt(0).toUpperCase() + e.slice(1)), await
|
|
592
|
+
e && (n = e.charAt(0).toUpperCase() + e.slice(1)), await a.fetchConfig(n || "Demo"), L(), S(), O(), D(o), p("chatbotToken", ((r = window.wineaterData) == null ? void 0 : r.CLIENT_TOKEN) || P, 365), x(), new W().initialize();
|
|
576
593
|
});
|
|
577
594
|
}
|
|
578
595
|
export {
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
596
|
+
I as closeChatWindow,
|
|
597
|
+
E as openChatWindow,
|
|
598
|
+
m as toggleChatWindow
|
|
582
599
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(r,d){typeof exports=="object"&&typeof module<"u"?d(exports):typeof define=="function"&&define.amd?define(["exports"],d):(r=typeof globalThis<"u"?globalThis:r||self,d(r.WineaterChatbot={}))})(this,function(r){"use strict";var w;const d=`
|
|
2
2
|
@font-face {
|
|
3
3
|
font-family: 'Poppins';
|
|
4
4
|
src: url('https://fonts.googleapis.com/css2?family=Poppins:wght@400&display=swap');
|
|
@@ -191,7 +191,7 @@
|
|
|
191
191
|
}
|
|
192
192
|
|
|
193
193
|
.wine-item a {
|
|
194
|
-
color: #7E27ED;
|
|
194
|
+
color: #7E27ED !important;
|
|
195
195
|
}
|
|
196
196
|
|
|
197
197
|
.wine-item img {
|
|
@@ -277,17 +277,17 @@
|
|
|
277
277
|
.typing-indicator.visible {
|
|
278
278
|
visibility: visible;
|
|
279
279
|
height: 50px;
|
|
280
|
-
}`,
|
|
280
|
+
}`,p=document.createElement("style");p.textContent=d,document.head.appendChild(p);function v(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(o){const t=Math.random()*16|0;return(o==="x"?t:t&3|8).toString(16)})}function g(o,t,e){let n="";if(e){const i=new Date;i.setTime(i.getTime()+e*24*60*60*1e3),n="; expires="+i.toUTCString()}document.cookie=o+"="+(t||"")+n+"; path=/; secure; samesite=strict"}function s(o){const t=o+"=",e=document.cookie.split(";");for(let n=0;n<e.length;n++){let i=e[n];for(;i.charAt(0)===" ";)i=i.substring(1,i.length);if(i.indexOf(t)===0)return i.substring(t.length,i.length)}return null}function k(){const o="uniqueUserID";let t=s(o);return t||(t=v(),g(o,t,365)),t}function c(o,t){fetch("https://api.wineater.com/proxy/track",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({event:o,properties:t})}).then(i=>{i.ok||console.error("Mixpanel tracking failed",i)}).catch(i=>{console.error("Mixpanel tracking error",i)})}function m(){c("Chatbot Opened",{distinct_id:s("uniqueUserID"),client:s("chatbotToken")})}function f(){c("Chatbot Closed",{distinct_id:s("uniqueUserID"),client:s("chatbotToken")})}function I(o){c("Message Sent",{distinct_id:s("uniqueUserID"),message_content:o,client:s("chatbotToken")})}function C(o){c("Products Got",{distinct_id:s("uniqueUserID"),products:o,client:s("chatbotToken")})}function E(o){c("Product Clicked",{distinct_id:s("uniqueUserID"),product_id:o,client:s("chatbotToken")})}function u(){const o=document.getElementById("chat-window"),t=document.getElementById("chat-icon");o.classList.contains("visible")?(f(),o.classList.remove("visible"),t.style.display="flex"):(m(),o.classList.add("visible"),t.style.display="none")}function b(){f(),document.getElementById("chat-window").classList.remove("visible")}function y(){m(),document.getElementById("chat-window").classList.add("visible")}document.addEventListener("DOMContentLoaded",()=>{setupCloseButton(),setupOutsideClick()});const T=["climats","telckel","biobio","weinpoint"],W="OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";class x{constructor(t){var e;this.baseURL="https://api.wineater.com/",this.store=T.find(n=>window.location.href.includes(n)),this.token=((e=window==null?void 0:window.wineaterData)==null?void 0:e.CLIENT_TOKEN)||W}async getStoreConfig(t){console.log(t);try{const e=await fetch(`${this.baseURL}stores/store`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.token}`},body:JSON.stringify({store:t})});if(!e.ok)throw new Error(`HTTP error! Status: ${e.status}`);return await e.json()}catch(e){throw console.error("Error fetching store configuration:",e),e}}async getWineRecommendations(t){console.log(window.location.href);try{const e=await fetch(`${this.baseURL}dish/recommendations`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.token}`},body:JSON.stringify({text:t,store:this.store?this.store.toString().charAt(0).toUpperCase()+this.store.slice(1):void 0})}),n=await e.json();if(!e.ok)throw new Error(`API call failed with status ${e.status}: ${n.message||"No additional error information"}`);return n}catch(e){throw console.error("Fetching wine recommendations failed:",e.message),new Error(`Error in getWineRecommendations: ${e.message}`)}}}class B{constructor(){this.api=new x,this.language="en",this.translations={fr:{welcomeMessage:"Sublimez votre expérience gastronomique. Il vous suffit de donner les détails de votre plat, et obtenez la recommandation de compagnon de vin idéale. Que voulez-vous manger?",noResultsFound:"Aucun résultat trouvé.",somethingWentWrong:"Désolé, quelque chose a mal tourné.",chatButton:"Accorder le vin au dîner",inputPlaceholder:"ex., Salade de thon",sendButton:"Accorder",price:"Prix",region:"Région",type:"Type",moreInfo:"Plus d'infos"},de:{welcomeMessage:"Sublimez votre expérience gastronomique. Il vous suffit de donner les détails de votre plat, et obtenez la recommandation de compagnon de vin idéale. Que voulez-vous manger?",noResultsFound:"Aucun résultat trouvé.",somethingWentWrong:"Désolé, quelque chose a mal tourné.",chatButton:"Accorder le vin au dîner",inputPlaceholder:"ex., Salade de thon",sendButton:"Accorder",price:"Prix",region:"Région",type:"Type",moreInfo:"Plus d'infos"},es:{welcomeMessage:"Mejore su experiencia gastronómica. Solo proporcione los detalles de su plato y obtenga la recomendación de vino ideal. ¿Qué le gustaría comer?",noResultsFound:"No se encontraron resultados.",somethingWentWrong:"Lo sentimos, algo salió mal.",chatButton:"Maridar vino con cena",inputPlaceholder:"ej., Ensalada de atún",sendButton:"Maridar",price:"Precio",region:"Región",type:"Tipo",moreInfo:"Más info"},en:{welcomeMessage:"Enhance your dining experience. Just provide your dish details and get the ideal wine pairing. What would you like to eat?",noResultsFound:"No results found.",somethingWentWrong:"Sorry, something went wrong.",chatButton:"Pair wine with dinner",inputPlaceholder:"e.g., Tuna Salad",sendButton:"Pair",price:"Price",region:"Region",type:"Type",moreInfo:"More info"},de:{welcomeMessage:"Verbessern Sie Ihr kulinarisches Erlebnis. Geben Sie einfach die Details Ihres Gerichts an und erhalten Sie die ideale Weinempfehlung. Was möchten Sie essen?",noResultsFound:"Keine Ergebnisse gefunden.",somethingWentWrong:"Entschuldigung, etwas ist schief gelaufen.",chatButton:"Wein zum Abendessen",inputPlaceholder:"z.B., Thunfischsalat",sendButton:"Kombinieren",price:"Preis",region:"Region",type:"Typ",moreInfo:"Mehr Info"}}}async fetchConfig(t="Demo"){try{const e=await this.api.getStoreConfig(t);this.language=e.lang}catch{this.language="en"}}translate(t){return this.translations[this.language][t]||t}}const a=new B;class P{constructor(){this.api=new x,this.displayFirstMessage(a.translate("welcomeMessage"))}initialize(){document.getElementById("send-button").addEventListener("click",()=>this.handleUserInput()),document.getElementById("user-input").addEventListener("keypress",n=>{n.key==="Enter"&&this.handleUserInput()})}displayFirstMessage(t,e="api"){const n=document.getElementById("message-container"),i=document.createElement("div");i.className=`message ${e}`,i.textContent=t,n.appendChild(i),n.scrollTop=n.scrollHeight}async handleUserInput(){const t=document.getElementById("user-input"),e=t.value.trim();if(e){this.displayMessage(e,"user"),t.value="",this.showTypingIndicator();try{I(e);const n=await this.api.getWineRecommendations(e);this.hideTypingIndicator(),n&&n.length?this.displayResults(n):this.displayMessage("No results found.","api")}catch{this.hideTypingIndicator(),this.displayMessage(a.translate("somethingWentWrong"),"api")}}}showTypingIndicator(){document.getElementById("typing-indicator").classList.add("visible")}hideTypingIndicator(){document.getElementById("typing-indicator").classList.remove("visible")}displayMessage(t,e){const n=document.getElementById("message-container"),i=document.createElement("div");i.textContent=t,i.className="message "+e,n.appendChild(i),n.scrollTop=n.scrollHeight}sendAnalytics(t){E(t)}displayResults(t){const e=document.getElementById("message-container");C(t.map(n=>n.Title)),t.forEach(n=>{const i=document.createElement("div");i.className="wine-item";const l=document.createElement("img");l.src=n.Image,i.appendChild(l);const h=document.createElement("div");h.innerHTML=`
|
|
281
281
|
<strong>${n.Title}</strong><br>
|
|
282
|
-
${
|
|
283
|
-
${
|
|
284
|
-
${
|
|
285
|
-
<a href="${n.Url}" onclick="sendAnalytics(${n.Title})" target="_blank">${
|
|
286
|
-
`,i.appendChild(
|
|
282
|
+
${a.translate("price")}: ${n.Price}<br>
|
|
283
|
+
${a.translate("region")}: ${n.Region}<br>
|
|
284
|
+
${a.translate("type")}: ${n.Type}<br>
|
|
285
|
+
<a href="${n.Url}" onclick="sendAnalytics(${n.Title})" target="_blank">${a.translate("moreInfo")}</a>
|
|
286
|
+
`,i.appendChild(h),e.appendChild(i)}),e.scrollTop=e.scrollHeight}}const L="OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";document.addEventListener("DOMContentLoaded",()=>{window.toggleChatWindow=u,window.closeChatWindow=b,window.openChatWindow=y});function S(){const o=`
|
|
287
287
|
<div id="chatbot-container">
|
|
288
288
|
<div id="chat-icon" onclick="toggleChatWindow()">
|
|
289
289
|
<img src="https://landing-static.s3.eu-central-1.amazonaws.com/images/chat-icon.svg" alt="Chat Icon"> <!-- Update the path to your logo image -->
|
|
290
|
-
<span>${
|
|
290
|
+
<span>${a.translate("chatButton")}</span>
|
|
291
291
|
</div>
|
|
292
292
|
|
|
293
293
|
<div id="chat-window" class="hidden">
|
|
@@ -306,9 +306,9 @@
|
|
|
306
306
|
<span></span><span></span><span></span>
|
|
307
307
|
</div>
|
|
308
308
|
<div id="input-container">
|
|
309
|
-
<input type="text" id="user-input" placeholder="${
|
|
310
|
-
<button id="send-button">${
|
|
309
|
+
<input type="text" id="user-input" placeholder="${a.translate("inputPlaceholder")}">
|
|
310
|
+
<button id="send-button">${a.translate("sendButton")}</button>
|
|
311
311
|
</div>
|
|
312
312
|
</div>
|
|
313
313
|
</div>
|
|
314
|
-
`;document.body.insertAdjacentHTML("beforeend",o)}function
|
|
314
|
+
`;document.body.insertAdjacentHTML("beforeend",o)}function O(){document.getElementById("close-btn").addEventListener("click",u)}function M(){window.addEventListener("click",function(o){const t=document.getElementById("chat-window"),e=document.getElementById("chat-icon");!t.contains(o.target)&&!e.contains(o.target)&&(t.classList.remove("visible"),e.style.display="flex")})}function D(o){console.log(o);const t=document.getElementById("chat-icon"),e=document.getElementById("chat-window");t.className="",e.className="",o==="right-center"?(t.classList.add("chat-icon-right-center"),e.classList.add("right-center-aligned")):t.classList.add("chat-icon-bottom-right")}if(typeof window<"u"){const o=((w=window.wineaterData)==null?void 0:w.POSITION)||"bottom-right";window.addEventListener("DOMContentLoaded",async()=>{var l;const e=["climats","telckel","biobio","weinpoint","vinigrandi"].find(h=>window.location.href.includes(h))||null;let n;e&&(n=e.charAt(0).toUpperCase()+e.slice(1)),await a.fetchConfig(n||"Demo"),S(),O(),M(),D(o),g("chatbotToken",((l=window.wineaterData)==null?void 0:l.CLIENT_TOKEN)||L,365),k(),new P().initialize()})}r.closeChatWindow=b,r.openChatWindow=y,r.toggleChatWindow=u,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
// Import your CSS here
|
|
4
4
|
import './js/styles.js';
|
|
5
|
-
import { setCookie } from './js/analytics.js';
|
|
5
|
+
import { setCookie, setUniqueUserCookie } from './js/analytics.js';
|
|
6
6
|
|
|
7
7
|
// Import your JavaScript modules here
|
|
8
8
|
import { toggleChatWindow, closeChatWindow, openChatWindow } from './js/ui.js';
|
|
@@ -111,6 +111,7 @@ if (typeof window !== 'undefined') {
|
|
|
111
111
|
setupOutsideClick();
|
|
112
112
|
toggleChatIconPosition(position);
|
|
113
113
|
setCookie('chatbotToken', window.wineaterData?.CLIENT_TOKEN || DEMO_TOKEN, 365);
|
|
114
|
+
setUniqueUserCookie();
|
|
114
115
|
const myChatbot = new Chatbot();
|
|
115
116
|
myChatbot.initialize();
|
|
116
117
|
});
|
package/src/js/analytics.js
CHANGED
|
@@ -1,20 +1,48 @@
|
|
|
1
1
|
// analytics.js
|
|
2
2
|
|
|
3
|
+
// Function to generate a UUID
|
|
4
|
+
function generateUUID() {
|
|
5
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
|
6
|
+
const r = Math.random() * 16 | 0,
|
|
7
|
+
v = c === 'x' ? r : (r & 0x3 | 0x8);
|
|
8
|
+
return v.toString(16);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Function to set a cookie
|
|
3
13
|
function setCookie(name, value, days) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
document.cookie = name + "=" + (value || "") + expires + "; path=/; secure; samesite=strict";
|
|
14
|
+
let expires = "";
|
|
15
|
+
if (days) {
|
|
16
|
+
const date = new Date();
|
|
17
|
+
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
|
|
18
|
+
expires = "; expires=" + date.toUTCString();
|
|
11
19
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
20
|
+
document.cookie = name + "=" + (value || "") + expires + "; path=/; secure; samesite=strict";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Function to get a cookie by name
|
|
24
|
+
function getCookie(name) {
|
|
25
|
+
const nameEQ = name + "=";
|
|
26
|
+
const ca = document.cookie.split(';');
|
|
27
|
+
for (let i = 0; i < ca.length; i++) {
|
|
28
|
+
let c = ca[i];
|
|
29
|
+
while (c.charAt(0) === ' ') c = c.substring(1, c.length);
|
|
30
|
+
if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Function to set a unique user identifier cookie
|
|
36
|
+
function setUniqueUserCookie() {
|
|
37
|
+
const cookieName = 'uniqueUserID';
|
|
38
|
+
let userId = getCookie(cookieName);
|
|
39
|
+
|
|
40
|
+
if (!userId) {
|
|
41
|
+
userId = generateUUID();
|
|
42
|
+
setCookie(cookieName, userId, 365); // Set cookie to expire in 1 year
|
|
17
43
|
}
|
|
44
|
+
return userId;
|
|
45
|
+
}
|
|
18
46
|
|
|
19
47
|
// Функция для отправки событий в Mixpanel
|
|
20
48
|
function trackEvent(event, properties) {
|
|
@@ -40,24 +68,24 @@ function setCookie(name, value, days) {
|
|
|
40
68
|
}
|
|
41
69
|
|
|
42
70
|
function trackChatbotOpen() {
|
|
43
|
-
trackEvent('Chatbot Opened', { distinct_id: getCookie('chatbotToken') });
|
|
71
|
+
trackEvent('Chatbot Opened', { distinct_id: getCookie('uniqueUserID'), client: getCookie('chatbotToken') });
|
|
44
72
|
}
|
|
45
73
|
|
|
46
74
|
function trackChatbotClose() {
|
|
47
|
-
trackEvent('Chatbot Closed', { distinct_id: getCookie('chatbotToken') });
|
|
75
|
+
trackEvent('Chatbot Closed', { distinct_id: getCookie('uniqueUserID'), client: getCookie('chatbotToken') });
|
|
48
76
|
}
|
|
49
77
|
|
|
50
78
|
function trackMessageSent(message) {
|
|
51
|
-
trackEvent('Message Sent', { distinct_id: getCookie('
|
|
79
|
+
trackEvent('Message Sent', { distinct_id: getCookie('uniqueUserID'), message_content: message, client: getCookie('chatbotToken') });
|
|
52
80
|
}
|
|
53
81
|
|
|
54
82
|
function trackRecommendationsGet(products) {
|
|
55
|
-
trackEvent('
|
|
83
|
+
trackEvent('Products Got', { distinct_id: getCookie('uniqueUserID'), products: products, client: getCookie('chatbotToken') });
|
|
56
84
|
}
|
|
57
85
|
|
|
58
86
|
function trackProductClick(productId) {
|
|
59
|
-
trackEvent('Product Clicked', { distinct_id: getCookie('
|
|
87
|
+
trackEvent('Product Clicked', { distinct_id: getCookie('uniqueUserID'), product_id: productId, client: getCookie('chatbotToken') });
|
|
60
88
|
}
|
|
61
89
|
|
|
62
|
-
export { setCookie, getCookie, trackChatbotOpen, trackMessageSent, trackProductClick, trackChatbotClose, trackRecommendationsGet };
|
|
90
|
+
export { setCookie, getCookie, setUniqueUserCookie, trackChatbotOpen, trackMessageSent, trackProductClick, trackChatbotClose, trackRecommendationsGet };
|
|
63
91
|
|