wineater-bot 1.5.5 → 1.5.6
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 +96 -101
- package/dist/wineater-chatbot.umd.js +4 -4
- package/package.json +1 -1
- package/src/js/analytics.js +9 -9
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const m = `
|
|
2
2
|
@font-face {
|
|
3
3
|
font-family: 'Poppins';
|
|
4
4
|
src: url('https://fonts.googleapis.com/css2?family=Poppins:wght@400&display=swap');
|
|
@@ -273,32 +273,27 @@ const f = `
|
|
|
273
273
|
.typing-indicator.visible {
|
|
274
274
|
visibility: visible;
|
|
275
275
|
height: 50px;
|
|
276
|
-
}`,
|
|
277
|
-
|
|
278
|
-
document.head.appendChild(
|
|
279
|
-
function
|
|
276
|
+
}`, l = document.createElement("style");
|
|
277
|
+
l.textContent = m;
|
|
278
|
+
document.head.appendChild(l);
|
|
279
|
+
function f(n, t, e) {
|
|
280
280
|
let o = "";
|
|
281
|
-
if (
|
|
281
|
+
if (e) {
|
|
282
282
|
const i = /* @__PURE__ */ new Date();
|
|
283
|
-
i.setTime(i.getTime() +
|
|
283
|
+
i.setTime(i.getTime() + e * 24 * 60 * 60 * 1e3), o = "; expires=" + i.toUTCString();
|
|
284
284
|
}
|
|
285
|
-
document.cookie = n + "=" + (
|
|
285
|
+
document.cookie = n + "=" + (t || "") + o + "; path=/; secure; samesite=strict";
|
|
286
286
|
}
|
|
287
|
-
function r(n) {
|
|
288
|
-
const
|
|
289
|
-
if (t.length === 2)
|
|
290
|
-
return t.pop().split(";").shift();
|
|
291
|
-
}
|
|
292
|
-
function d(n, e) {
|
|
293
|
-
const t = "6f3d90d5b02720f58de3663e3ef675fe", o = "https://api-eu.mixpanel.com/track", i = {
|
|
287
|
+
function r(n, t) {
|
|
288
|
+
const e = "6f3d90d5b02720f58de3663e3ef675fe", o = "https://api-eu.mixpanel.com/track", i = {
|
|
294
289
|
event: n,
|
|
295
|
-
properties:
|
|
290
|
+
properties: {
|
|
291
|
+
token: e,
|
|
292
|
+
...t
|
|
293
|
+
}
|
|
296
294
|
};
|
|
297
295
|
fetch(o, {
|
|
298
296
|
method: "POST",
|
|
299
|
-
headers: {
|
|
300
|
-
Auth: "Basic " + btoa(`${t}:`)
|
|
301
|
-
},
|
|
302
297
|
body: JSON.stringify(i)
|
|
303
298
|
}).then((s) => {
|
|
304
299
|
s.ok || console.error("Mixpanel tracking failed", s);
|
|
@@ -306,80 +301,80 @@ function d(n, e) {
|
|
|
306
301
|
console.error("Mixpanel tracking error", s);
|
|
307
302
|
});
|
|
308
303
|
}
|
|
309
|
-
function
|
|
310
|
-
|
|
304
|
+
function p() {
|
|
305
|
+
r("Chatbot Opened", {});
|
|
311
306
|
}
|
|
312
307
|
function g() {
|
|
313
|
-
|
|
308
|
+
r("Chatbot Closed", {});
|
|
314
309
|
}
|
|
315
310
|
function y(n) {
|
|
316
|
-
|
|
311
|
+
r("Message Sent", { message_content: n });
|
|
317
312
|
}
|
|
318
|
-
function
|
|
319
|
-
|
|
313
|
+
function b(n) {
|
|
314
|
+
r("Message Sent", { products: n });
|
|
320
315
|
}
|
|
321
|
-
function
|
|
322
|
-
|
|
316
|
+
function w(n) {
|
|
317
|
+
r("Product Clicked", { product_id: n });
|
|
323
318
|
}
|
|
324
|
-
function
|
|
325
|
-
const n = document.getElementById("chat-window"),
|
|
326
|
-
n.classList.contains("visible") ? (g(), n.classList.remove("visible"),
|
|
319
|
+
function h() {
|
|
320
|
+
const n = document.getElementById("chat-window"), t = document.getElementById("chat-icon");
|
|
321
|
+
n.classList.contains("visible") ? (g(), n.classList.remove("visible"), t.style.display = "flex") : (p(), n.classList.add("visible"), t.style.display = "none");
|
|
327
322
|
}
|
|
328
|
-
function
|
|
323
|
+
function x() {
|
|
329
324
|
g(), document.getElementById("chat-window").classList.remove("visible");
|
|
330
325
|
}
|
|
331
|
-
function
|
|
332
|
-
|
|
326
|
+
function v() {
|
|
327
|
+
p(), document.getElementById("chat-window").classList.add("visible");
|
|
333
328
|
}
|
|
334
329
|
document.addEventListener("DOMContentLoaded", () => {
|
|
335
330
|
setupCloseButton(), setupOutsideClick();
|
|
336
331
|
});
|
|
337
|
-
const
|
|
338
|
-
class
|
|
339
|
-
constructor(
|
|
340
|
-
var
|
|
341
|
-
this.baseURL = "https://api.wineater.com/", this.store =
|
|
332
|
+
const k = ["climats", "telckel", "biobio", "weinpoint"], E = "OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";
|
|
333
|
+
class u {
|
|
334
|
+
constructor(t) {
|
|
335
|
+
var e;
|
|
336
|
+
this.baseURL = "https://api.wineater.com/", this.store = k.find((o) => window.location.href.includes(o)), this.token = ((e = window == null ? void 0 : window.wineaterData) == null ? void 0 : e.CLIENT_TOKEN) || E;
|
|
342
337
|
}
|
|
343
|
-
async getStoreConfig(
|
|
344
|
-
console.log(
|
|
338
|
+
async getStoreConfig(t) {
|
|
339
|
+
console.log(t);
|
|
345
340
|
try {
|
|
346
|
-
const
|
|
341
|
+
const e = await fetch(`${this.baseURL}stores/store`, {
|
|
347
342
|
method: "POST",
|
|
348
343
|
headers: {
|
|
349
344
|
"Content-Type": "application/json",
|
|
350
345
|
Authorization: `Bearer ${this.token}`
|
|
351
346
|
},
|
|
352
|
-
body: JSON.stringify({ store:
|
|
347
|
+
body: JSON.stringify({ store: t })
|
|
353
348
|
});
|
|
354
|
-
if (!
|
|
355
|
-
throw new Error(`HTTP error! Status: ${
|
|
356
|
-
return await
|
|
357
|
-
} catch (
|
|
358
|
-
throw console.error("Error fetching store configuration:",
|
|
349
|
+
if (!e.ok)
|
|
350
|
+
throw new Error(`HTTP error! Status: ${e.status}`);
|
|
351
|
+
return await e.json();
|
|
352
|
+
} catch (e) {
|
|
353
|
+
throw console.error("Error fetching store configuration:", e), e;
|
|
359
354
|
}
|
|
360
355
|
}
|
|
361
|
-
async getWineRecommendations(
|
|
356
|
+
async getWineRecommendations(t) {
|
|
362
357
|
console.log(window.location.href);
|
|
363
358
|
try {
|
|
364
|
-
const
|
|
359
|
+
const e = await fetch(`${this.baseURL}dish/recommendations`, {
|
|
365
360
|
method: "POST",
|
|
366
361
|
headers: {
|
|
367
362
|
"Content-Type": "application/json",
|
|
368
363
|
Authorization: `Bearer ${this.token}`
|
|
369
364
|
},
|
|
370
|
-
body: JSON.stringify({ text:
|
|
371
|
-
}), o = await
|
|
372
|
-
if (!
|
|
373
|
-
throw new Error(`API call failed with status ${
|
|
365
|
+
body: JSON.stringify({ text: t, store: this.store ? this.store.toString().charAt(0).toUpperCase() + this.store.slice(1) : void 0 })
|
|
366
|
+
}), o = await e.json();
|
|
367
|
+
if (!e.ok)
|
|
368
|
+
throw new Error(`API call failed with status ${e.status}: ${o.message || "No additional error information"}`);
|
|
374
369
|
return o;
|
|
375
|
-
} catch (
|
|
376
|
-
throw console.error("Fetching wine recommendations failed:",
|
|
370
|
+
} catch (e) {
|
|
371
|
+
throw console.error("Fetching wine recommendations failed:", e.message), new Error(`Error in getWineRecommendations: ${e.message}`);
|
|
377
372
|
}
|
|
378
373
|
}
|
|
379
374
|
}
|
|
380
|
-
class
|
|
375
|
+
class C {
|
|
381
376
|
constructor() {
|
|
382
|
-
this.api = new
|
|
377
|
+
this.api = new u(), this.language = "en", this.translations = {
|
|
383
378
|
fr: {
|
|
384
379
|
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?",
|
|
385
380
|
noResultsFound: "Aucun résultat trouvé.",
|
|
@@ -418,37 +413,37 @@ class I {
|
|
|
418
413
|
}
|
|
419
414
|
};
|
|
420
415
|
}
|
|
421
|
-
async fetchConfig(
|
|
422
|
-
if (
|
|
423
|
-
const
|
|
424
|
-
this.language =
|
|
416
|
+
async fetchConfig(t) {
|
|
417
|
+
if (t) {
|
|
418
|
+
const e = await this.api.getStoreConfig(t);
|
|
419
|
+
this.language = e.lang;
|
|
425
420
|
}
|
|
426
421
|
}
|
|
427
|
-
translate(
|
|
428
|
-
return this.translations[this.language][
|
|
422
|
+
translate(t) {
|
|
423
|
+
return this.translations[this.language][t] || t;
|
|
429
424
|
}
|
|
430
425
|
}
|
|
431
|
-
const a = new
|
|
432
|
-
class
|
|
426
|
+
const a = new C();
|
|
427
|
+
class I {
|
|
433
428
|
constructor() {
|
|
434
|
-
this.api = new
|
|
429
|
+
this.api = new u(), this.displayFirstMessage(a.translate("welcomeMessage"));
|
|
435
430
|
}
|
|
436
431
|
initialize() {
|
|
437
432
|
document.getElementById("send-button").addEventListener("click", () => this.handleUserInput()), document.getElementById("user-input").addEventListener("keypress", (o) => {
|
|
438
433
|
o.key === "Enter" && this.handleUserInput();
|
|
439
434
|
});
|
|
440
435
|
}
|
|
441
|
-
displayFirstMessage(
|
|
436
|
+
displayFirstMessage(t, e = "api") {
|
|
442
437
|
const o = document.getElementById("message-container"), i = document.createElement("div");
|
|
443
|
-
i.className = `message ${
|
|
438
|
+
i.className = `message ${e}`, i.textContent = t, o.appendChild(i), o.scrollTop = o.scrollHeight;
|
|
444
439
|
}
|
|
445
440
|
async handleUserInput() {
|
|
446
|
-
const
|
|
447
|
-
if (
|
|
448
|
-
this.displayMessage(
|
|
441
|
+
const t = document.getElementById("user-input"), e = t.value.trim();
|
|
442
|
+
if (e) {
|
|
443
|
+
this.displayMessage(e, "user"), t.value = "", this.showTypingIndicator();
|
|
449
444
|
try {
|
|
450
|
-
y(
|
|
451
|
-
const o = await this.api.getWineRecommendations(
|
|
445
|
+
y(e);
|
|
446
|
+
const o = await this.api.getWineRecommendations(e);
|
|
452
447
|
this.hideTypingIndicator(), o && o.length ? this.displayResults(o) : this.displayMessage("No results found.", "api");
|
|
453
448
|
} catch {
|
|
454
449
|
this.hideTypingIndicator(), this.displayMessage(a.translate("somethingWentWrong"), "api");
|
|
@@ -461,36 +456,36 @@ class T {
|
|
|
461
456
|
hideTypingIndicator() {
|
|
462
457
|
document.getElementById("typing-indicator").classList.remove("visible");
|
|
463
458
|
}
|
|
464
|
-
displayMessage(
|
|
459
|
+
displayMessage(t, e) {
|
|
465
460
|
const o = document.getElementById("message-container"), i = document.createElement("div");
|
|
466
|
-
i.textContent =
|
|
461
|
+
i.textContent = t, i.className = "message " + e, o.appendChild(i), o.scrollTop = o.scrollHeight;
|
|
467
462
|
}
|
|
468
|
-
sendAnalytics(
|
|
469
|
-
|
|
463
|
+
sendAnalytics(t) {
|
|
464
|
+
w(t);
|
|
470
465
|
}
|
|
471
|
-
displayResults(
|
|
472
|
-
const
|
|
473
|
-
|
|
466
|
+
displayResults(t) {
|
|
467
|
+
const e = document.getElementById("message-container");
|
|
468
|
+
b(t.map((o) => o.Title)), t.forEach((o) => {
|
|
474
469
|
const i = document.createElement("div");
|
|
475
470
|
i.className = "wine-item";
|
|
476
471
|
const s = document.createElement("img");
|
|
477
472
|
s.src = o.Image, i.appendChild(s);
|
|
478
|
-
const
|
|
479
|
-
|
|
473
|
+
const d = document.createElement("div");
|
|
474
|
+
d.innerHTML = `
|
|
480
475
|
<strong>${o.Title}</strong><br>
|
|
481
476
|
${a.translate("price")}: ${o.Price}<br>
|
|
482
477
|
${a.translate("region")}: ${o.Region}<br>
|
|
483
478
|
${a.translate("type")}: ${o.Type}<br>
|
|
484
479
|
<a href="${o.Url}" onclick="sendAnalytics(${o.Title})" target="_blank">${a.translate("moreInfo")}</a>
|
|
485
|
-
`, i.appendChild(
|
|
486
|
-
}),
|
|
480
|
+
`, i.appendChild(d), e.appendChild(i);
|
|
481
|
+
}), e.scrollTop = e.scrollHeight;
|
|
487
482
|
}
|
|
488
483
|
}
|
|
489
484
|
const B = "OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";
|
|
490
485
|
document.addEventListener("DOMContentLoaded", () => {
|
|
491
|
-
window.toggleChatWindow =
|
|
486
|
+
window.toggleChatWindow = h, window.closeChatWindow = x, window.openChatWindow = v;
|
|
492
487
|
});
|
|
493
|
-
function
|
|
488
|
+
function T() {
|
|
494
489
|
const n = `
|
|
495
490
|
<div id="chatbot-container">
|
|
496
491
|
<div id="chat-icon" onclick="toggleChatWindow()">
|
|
@@ -520,32 +515,32 @@ function L() {
|
|
|
520
515
|
`;
|
|
521
516
|
document.body.insertAdjacentHTML("beforeend", n);
|
|
522
517
|
}
|
|
523
|
-
function
|
|
524
|
-
document.getElementById("close-btn").addEventListener("click",
|
|
518
|
+
function L() {
|
|
519
|
+
document.getElementById("close-btn").addEventListener("click", h);
|
|
525
520
|
}
|
|
526
|
-
function
|
|
521
|
+
function P() {
|
|
527
522
|
window.addEventListener("click", function(n) {
|
|
528
|
-
const
|
|
529
|
-
!
|
|
523
|
+
const t = document.getElementById("chat-window"), e = document.getElementById("chat-icon");
|
|
524
|
+
!t.contains(n.target) && !e.contains(n.target) && (t.classList.remove("visible"), e.style.display = "flex");
|
|
530
525
|
});
|
|
531
526
|
}
|
|
532
|
-
function
|
|
527
|
+
function W(n) {
|
|
533
528
|
console.log(n);
|
|
534
|
-
const
|
|
535
|
-
|
|
529
|
+
const t = document.getElementById("chat-icon"), e = document.getElementById("chat-window");
|
|
530
|
+
t.className = "", e.className = "", n === "right-center" ? (t.classList.add("chat-icon-right-center"), e.classList.add("right-center-aligned")) : t.classList.add("chat-icon-bottom-right");
|
|
536
531
|
}
|
|
537
|
-
var
|
|
532
|
+
var c;
|
|
538
533
|
if (typeof window < "u") {
|
|
539
|
-
const n = ((
|
|
534
|
+
const n = ((c = window.wineaterData) == null ? void 0 : c.POSITION) || "bottom-right";
|
|
540
535
|
window.addEventListener("DOMContentLoaded", async () => {
|
|
541
536
|
var s;
|
|
542
|
-
const
|
|
537
|
+
const e = ["climats", "telckel", "biobio", "weinpoint"].find((d) => window.location.href.includes(d)) || null;
|
|
543
538
|
let o;
|
|
544
|
-
|
|
539
|
+
e && (o = e.charAt(0).toUpperCase() + e.slice(1)), await a.fetchConfig(o || null), T(), L(), P(), W(n), f("chatbotToken", ((s = window.wineaterData) == null ? void 0 : s.CLIENT_TOKEN) || B, 365), new I().initialize();
|
|
545
540
|
});
|
|
546
541
|
}
|
|
547
542
|
export {
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
543
|
+
x as closeChatWindow,
|
|
544
|
+
v as openChatWindow,
|
|
545
|
+
h as toggleChatWindow
|
|
551
546
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
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
|
|
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 b;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');
|
|
@@ -273,13 +273,13 @@
|
|
|
273
273
|
.typing-indicator.visible {
|
|
274
274
|
visibility: visible;
|
|
275
275
|
height: 50px;
|
|
276
|
-
}`,g=document.createElement("style");g.textContent=d,document.head.appendChild(g);function
|
|
276
|
+
}`,g=document.createElement("style");g.textContent=d,document.head.appendChild(g);function w(n,t,e){let o="";if(e){const i=new Date;i.setTime(i.getTime()+e*24*60*60*1e3),o="; expires="+i.toUTCString()}document.cookie=n+"="+(t||"")+o+"; path=/; secure; samesite=strict"}function c(n,t){const e="6f3d90d5b02720f58de3663e3ef675fe",o="https://api-eu.mixpanel.com/track",i={event:n,properties:{token:e,...t}};fetch(o,{method:"POST",body:JSON.stringify(i)}).then(a=>{a.ok||console.error("Mixpanel tracking failed",a)}).catch(a=>{console.error("Mixpanel tracking error",a)})}function h(){c("Chatbot Opened",{})}function u(){c("Chatbot Closed",{})}function x(n){c("Message Sent",{message_content:n})}function v(n){c("Message Sent",{products:n})}function k(n){c("Product Clicked",{product_id:n})}function p(){const n=document.getElementById("chat-window"),t=document.getElementById("chat-icon");n.classList.contains("visible")?(u(),n.classList.remove("visible"),t.style.display="flex"):(h(),n.classList.add("visible"),t.style.display="none")}function m(){u(),document.getElementById("chat-window").classList.remove("visible")}function f(){h(),document.getElementById("chat-window").classList.add("visible")}document.addEventListener("DOMContentLoaded",()=>{setupCloseButton(),setupOutsideClick()});const C=["climats","telckel","biobio","weinpoint"],E="OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";class y{constructor(t){var e;this.baseURL="https://api.wineater.com/",this.store=C.find(o=>window.location.href.includes(o)),this.token=((e=window==null?void 0:window.wineaterData)==null?void 0:e.CLIENT_TOKEN)||E}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})}),o=await e.json();if(!e.ok)throw new Error(`API call failed with status ${e.status}: ${o.message||"No additional error information"}`);return o}catch(e){throw console.error("Fetching wine recommendations failed:",e.message),new Error(`Error in getWineRecommendations: ${e.message}`)}}}class I{constructor(){this.api=new y,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"},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"}}}async fetchConfig(t){if(t){const e=await this.api.getStoreConfig(t);this.language=e.lang}}translate(t){return this.translations[this.language][t]||t}}const s=new I;class T{constructor(){this.api=new y,this.displayFirstMessage(s.translate("welcomeMessage"))}initialize(){document.getElementById("send-button").addEventListener("click",()=>this.handleUserInput()),document.getElementById("user-input").addEventListener("keypress",o=>{o.key==="Enter"&&this.handleUserInput()})}displayFirstMessage(t,e="api"){const o=document.getElementById("message-container"),i=document.createElement("div");i.className=`message ${e}`,i.textContent=t,o.appendChild(i),o.scrollTop=o.scrollHeight}async handleUserInput(){const t=document.getElementById("user-input"),e=t.value.trim();if(e){this.displayMessage(e,"user"),t.value="",this.showTypingIndicator();try{x(e);const o=await this.api.getWineRecommendations(e);this.hideTypingIndicator(),o&&o.length?this.displayResults(o):this.displayMessage("No results found.","api")}catch{this.hideTypingIndicator(),this.displayMessage(s.translate("somethingWentWrong"),"api")}}}showTypingIndicator(){document.getElementById("typing-indicator").classList.add("visible")}hideTypingIndicator(){document.getElementById("typing-indicator").classList.remove("visible")}displayMessage(t,e){const o=document.getElementById("message-container"),i=document.createElement("div");i.textContent=t,i.className="message "+e,o.appendChild(i),o.scrollTop=o.scrollHeight}sendAnalytics(t){k(t)}displayResults(t){const e=document.getElementById("message-container");v(t.map(o=>o.Title)),t.forEach(o=>{const i=document.createElement("div");i.className="wine-item";const a=document.createElement("img");a.src=o.Image,i.appendChild(a);const l=document.createElement("div");l.innerHTML=`
|
|
277
277
|
<strong>${o.Title}</strong><br>
|
|
278
278
|
${s.translate("price")}: ${o.Price}<br>
|
|
279
279
|
${s.translate("region")}: ${o.Region}<br>
|
|
280
280
|
${s.translate("type")}: ${o.Type}<br>
|
|
281
281
|
<a href="${o.Url}" onclick="sendAnalytics(${o.Title})" target="_blank">${s.translate("moreInfo")}</a>
|
|
282
|
-
`,i.appendChild(
|
|
282
|
+
`,i.appendChild(l),e.appendChild(i)}),e.scrollTop=e.scrollHeight}}const B="OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";document.addEventListener("DOMContentLoaded",()=>{window.toggleChatWindow=p,window.closeChatWindow=m,window.openChatWindow=f});function L(){const n=`
|
|
283
283
|
<div id="chatbot-container">
|
|
284
284
|
<div id="chat-icon" onclick="toggleChatWindow()">
|
|
285
285
|
<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 -->
|
|
@@ -305,4 +305,4 @@
|
|
|
305
305
|
</div>
|
|
306
306
|
</div>
|
|
307
307
|
</div>
|
|
308
|
-
`;document.body.insertAdjacentHTML("beforeend",n)}function
|
|
308
|
+
`;document.body.insertAdjacentHTML("beforeend",n)}function W(){document.getElementById("close-btn").addEventListener("click",p)}function P(){window.addEventListener("click",function(n){const t=document.getElementById("chat-window"),e=document.getElementById("chat-icon");!t.contains(n.target)&&!e.contains(n.target)&&(t.classList.remove("visible"),e.style.display="flex")})}function O(n){console.log(n);const t=document.getElementById("chat-icon"),e=document.getElementById("chat-window");t.className="",e.className="",n==="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 n=((b=window.wineaterData)==null?void 0:b.POSITION)||"bottom-right";window.addEventListener("DOMContentLoaded",async()=>{var a;const e=["climats","telckel","biobio","weinpoint"].find(l=>window.location.href.includes(l))||null;let o;e&&(o=e.charAt(0).toUpperCase()+e.slice(1)),await s.fetchConfig(o||null),L(),W(),P(),O(n),w("chatbotToken",((a=window.wineaterData)==null?void 0:a.CLIENT_TOKEN)||B,365),new T().initialize()})}r.closeChatWindow=m,r.openChatWindow=f,r.toggleChatWindow=p,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
package/src/js/analytics.js
CHANGED
|
@@ -22,14 +22,14 @@ function setCookie(name, value, days) {
|
|
|
22
22
|
const endpoint = 'https://api-eu.mixpanel.com/track';
|
|
23
23
|
const data = {
|
|
24
24
|
event: event,
|
|
25
|
-
properties
|
|
25
|
+
properties: {
|
|
26
|
+
token: token,
|
|
27
|
+
...properties
|
|
28
|
+
}
|
|
26
29
|
};
|
|
27
30
|
|
|
28
31
|
fetch(endpoint, {
|
|
29
32
|
method: 'POST',
|
|
30
|
-
headers: {
|
|
31
|
-
'Auth': 'Basic ' + btoa(`${token}:`)
|
|
32
|
-
},
|
|
33
33
|
body: JSON.stringify(data)
|
|
34
34
|
}).then(response => {
|
|
35
35
|
if (!response.ok) {
|
|
@@ -41,23 +41,23 @@ function setCookie(name, value, days) {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
function trackChatbotOpen() {
|
|
44
|
-
trackEvent('Chatbot Opened', {
|
|
44
|
+
trackEvent('Chatbot Opened', {});
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
function trackChatbotClose() {
|
|
48
|
-
trackEvent('Chatbot Closed', {
|
|
48
|
+
trackEvent('Chatbot Closed', {});
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
function trackMessageSent(message) {
|
|
52
|
-
trackEvent('Message Sent', {
|
|
52
|
+
trackEvent('Message Sent', { message_content: message });
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
function trackRecommendationsGet(products) {
|
|
56
|
-
trackEvent('Message Sent', {
|
|
56
|
+
trackEvent('Message Sent', { products: products });
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
function trackProductClick(productId) {
|
|
60
|
-
trackEvent('Product Clicked', {
|
|
60
|
+
trackEvent('Product Clicked', { product_id: productId });
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
export { setCookie, getCookie, trackChatbotOpen, trackMessageSent, trackProductClick, trackChatbotClose, trackRecommendationsGet };
|