wineater-bot 1.4.2 → 1.4.4
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 +87 -90
- package/dist/wineater-chatbot.umd.js +9 -9
- package/package.json +1 -1
- package/src/js/analytics.js +12 -7
|
@@ -276,43 +276,40 @@ const f = `
|
|
|
276
276
|
}`, p = document.createElement("style");
|
|
277
277
|
p.textContent = f;
|
|
278
278
|
document.head.appendChild(p);
|
|
279
|
-
function b(n,
|
|
279
|
+
function b(n, e, t) {
|
|
280
280
|
let o = "";
|
|
281
|
-
if (
|
|
281
|
+
if (t) {
|
|
282
282
|
const i = /* @__PURE__ */ new Date();
|
|
283
|
-
i.setTime(i.getTime() +
|
|
283
|
+
i.setTime(i.getTime() + t * 24 * 60 * 60 * 1e3), o = "; expires=" + i.toUTCString();
|
|
284
284
|
}
|
|
285
|
-
document.cookie = n + "=" + (
|
|
285
|
+
document.cookie = n + "=" + (e || "") + o + "; path=/; secure; samesite=strict";
|
|
286
286
|
}
|
|
287
287
|
function r(n) {
|
|
288
|
-
const
|
|
289
|
-
if (
|
|
290
|
-
return
|
|
291
|
-
}
|
|
292
|
-
function d(n,
|
|
293
|
-
|
|
294
|
-
event: n,
|
|
295
|
-
properties: {
|
|
296
|
-
token: e,
|
|
297
|
-
...t
|
|
298
|
-
}
|
|
299
|
-
};
|
|
300
|
-
fetch(o, {
|
|
288
|
+
const t = `; ${document.cookie}`.split(`; ${n}=`);
|
|
289
|
+
if (t.length === 2)
|
|
290
|
+
return t.pop().split(";").shift();
|
|
291
|
+
}
|
|
292
|
+
function d(n, e) {
|
|
293
|
+
fetch("https://api-eu.mixpanel.com/track", {
|
|
301
294
|
method: "POST",
|
|
302
295
|
headers: {
|
|
303
|
-
"Content-Type": "application/json"
|
|
296
|
+
"Content-Type": "application/json",
|
|
297
|
+
Authentication: "6f3d90d5b02720f58de3663e3ef675fe"
|
|
304
298
|
},
|
|
305
|
-
body: JSON.stringify(
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
299
|
+
body: JSON.stringify({
|
|
300
|
+
event: n,
|
|
301
|
+
properties: e
|
|
302
|
+
})
|
|
303
|
+
}).then((a) => {
|
|
304
|
+
a.ok || console.error("Mixpanel tracking failed", a);
|
|
305
|
+
}).catch((a) => {
|
|
306
|
+
console.error("Mixpanel tracking error", a);
|
|
310
307
|
});
|
|
311
308
|
}
|
|
312
|
-
function
|
|
309
|
+
function h() {
|
|
313
310
|
d("Chatbot Opened", { distinct_id: r("chatbotToken") });
|
|
314
311
|
}
|
|
315
|
-
function
|
|
312
|
+
function g() {
|
|
316
313
|
d("Chatbot Closed", { distinct_id: r("chatbotToken") });
|
|
317
314
|
}
|
|
318
315
|
function y(n) {
|
|
@@ -325,58 +322,58 @@ function x(n) {
|
|
|
325
322
|
d("Product Clicked", { distinct_id: r("chatbotToken"), product_id: n });
|
|
326
323
|
}
|
|
327
324
|
function u() {
|
|
328
|
-
const n = document.getElementById("chat-window"),
|
|
329
|
-
n.classList.contains("visible") ? (
|
|
325
|
+
const n = document.getElementById("chat-window"), e = document.getElementById("chat-icon");
|
|
326
|
+
n.classList.contains("visible") ? (g(), n.classList.remove("visible"), e.style.display = "flex") : (h(), n.classList.add("visible"), e.style.display = "none");
|
|
330
327
|
}
|
|
331
328
|
function v() {
|
|
332
|
-
|
|
329
|
+
g(), document.getElementById("chat-window").classList.remove("visible");
|
|
333
330
|
}
|
|
334
331
|
function k() {
|
|
335
|
-
|
|
332
|
+
h(), document.getElementById("chat-window").classList.add("visible");
|
|
336
333
|
}
|
|
337
334
|
document.addEventListener("DOMContentLoaded", () => {
|
|
338
335
|
setupCloseButton(), setupOutsideClick();
|
|
339
336
|
});
|
|
340
337
|
const C = ["climats", "telckel", "biobio", "weinpoint"], E = "OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";
|
|
341
338
|
class m {
|
|
342
|
-
constructor(
|
|
343
|
-
var
|
|
344
|
-
this.baseURL = "https://api.wineater.com/", this.store = C.find((o) => window.location.href.includes(o)), this.token = ((
|
|
339
|
+
constructor(e) {
|
|
340
|
+
var t;
|
|
341
|
+
this.baseURL = "https://api.wineater.com/", this.store = C.find((o) => window.location.href.includes(o)), this.token = ((t = window == null ? void 0 : window.wineaterData) == null ? void 0 : t.CLIENT_TOKEN) || E;
|
|
345
342
|
}
|
|
346
|
-
async getStoreConfig(
|
|
347
|
-
console.log(
|
|
343
|
+
async getStoreConfig(e) {
|
|
344
|
+
console.log(e);
|
|
348
345
|
try {
|
|
349
|
-
const
|
|
346
|
+
const t = await fetch(`${this.baseURL}stores/store`, {
|
|
350
347
|
method: "POST",
|
|
351
348
|
headers: {
|
|
352
349
|
"Content-Type": "application/json",
|
|
353
350
|
Authorization: `Bearer ${this.token}`
|
|
354
351
|
},
|
|
355
|
-
body: JSON.stringify({ store:
|
|
352
|
+
body: JSON.stringify({ store: e })
|
|
356
353
|
});
|
|
357
|
-
if (!
|
|
358
|
-
throw new Error(`HTTP error! Status: ${
|
|
359
|
-
return await
|
|
360
|
-
} catch (
|
|
361
|
-
throw console.error("Error fetching store configuration:",
|
|
354
|
+
if (!t.ok)
|
|
355
|
+
throw new Error(`HTTP error! Status: ${t.status}`);
|
|
356
|
+
return await t.json();
|
|
357
|
+
} catch (t) {
|
|
358
|
+
throw console.error("Error fetching store configuration:", t), t;
|
|
362
359
|
}
|
|
363
360
|
}
|
|
364
|
-
async getWineRecommendations(
|
|
361
|
+
async getWineRecommendations(e) {
|
|
365
362
|
console.log(window.location.href);
|
|
366
363
|
try {
|
|
367
|
-
const
|
|
364
|
+
const t = await fetch(`${this.baseURL}dish/recommendations`, {
|
|
368
365
|
method: "POST",
|
|
369
366
|
headers: {
|
|
370
367
|
"Content-Type": "application/json",
|
|
371
368
|
Authorization: `Bearer ${this.token}`
|
|
372
369
|
},
|
|
373
|
-
body: JSON.stringify({ text:
|
|
374
|
-
}), o = await
|
|
375
|
-
if (!
|
|
376
|
-
throw new Error(`API call failed with status ${
|
|
370
|
+
body: JSON.stringify({ text: e, store: this.store ? this.store.toString().charAt(0).toUpperCase() + this.store.slice(1) : void 0 })
|
|
371
|
+
}), o = await t.json();
|
|
372
|
+
if (!t.ok)
|
|
373
|
+
throw new Error(`API call failed with status ${t.status}: ${o.message || "No additional error information"}`);
|
|
377
374
|
return o;
|
|
378
|
-
} catch (
|
|
379
|
-
throw console.error("Fetching wine recommendations failed:",
|
|
375
|
+
} catch (t) {
|
|
376
|
+
throw console.error("Fetching wine recommendations failed:", t.message), new Error(`Error in getWineRecommendations: ${t.message}`);
|
|
380
377
|
}
|
|
381
378
|
}
|
|
382
379
|
}
|
|
@@ -421,40 +418,40 @@ class I {
|
|
|
421
418
|
}
|
|
422
419
|
};
|
|
423
420
|
}
|
|
424
|
-
async fetchConfig(
|
|
425
|
-
if (
|
|
426
|
-
const
|
|
427
|
-
this.language =
|
|
421
|
+
async fetchConfig(e) {
|
|
422
|
+
if (e) {
|
|
423
|
+
const t = await this.api.getStoreConfig(e);
|
|
424
|
+
this.language = t.lang;
|
|
428
425
|
}
|
|
429
426
|
}
|
|
430
|
-
translate(
|
|
431
|
-
return this.translations[this.language][
|
|
427
|
+
translate(e) {
|
|
428
|
+
return this.translations[this.language][e] || e;
|
|
432
429
|
}
|
|
433
430
|
}
|
|
434
|
-
const
|
|
431
|
+
const s = new I();
|
|
435
432
|
class T {
|
|
436
433
|
constructor() {
|
|
437
|
-
this.api = new m(), this.displayFirstMessage(
|
|
434
|
+
this.api = new m(), this.displayFirstMessage(s.translate("welcomeMessage"));
|
|
438
435
|
}
|
|
439
436
|
initialize() {
|
|
440
437
|
document.getElementById("send-button").addEventListener("click", () => this.handleUserInput()), document.getElementById("user-input").addEventListener("keypress", (o) => {
|
|
441
438
|
o.key === "Enter" && this.handleUserInput();
|
|
442
439
|
});
|
|
443
440
|
}
|
|
444
|
-
displayFirstMessage(
|
|
441
|
+
displayFirstMessage(e, t = "api") {
|
|
445
442
|
const o = document.getElementById("message-container"), i = document.createElement("div");
|
|
446
|
-
i.className = `message ${
|
|
443
|
+
i.className = `message ${t}`, i.textContent = e, o.appendChild(i), o.scrollTop = o.scrollHeight;
|
|
447
444
|
}
|
|
448
445
|
async handleUserInput() {
|
|
449
|
-
const
|
|
450
|
-
if (
|
|
451
|
-
this.displayMessage(
|
|
446
|
+
const e = document.getElementById("user-input"), t = e.value.trim();
|
|
447
|
+
if (t) {
|
|
448
|
+
this.displayMessage(t, "user"), e.value = "", this.showTypingIndicator();
|
|
452
449
|
try {
|
|
453
|
-
y(
|
|
454
|
-
const o = await this.api.getWineRecommendations(
|
|
450
|
+
y(t);
|
|
451
|
+
const o = await this.api.getWineRecommendations(t);
|
|
455
452
|
this.hideTypingIndicator(), o && o.length ? this.displayResults(o) : this.displayMessage("No results found.", "api");
|
|
456
453
|
} catch {
|
|
457
|
-
this.hideTypingIndicator(), this.displayMessage(
|
|
454
|
+
this.hideTypingIndicator(), this.displayMessage(s.translate("somethingWentWrong"), "api");
|
|
458
455
|
}
|
|
459
456
|
}
|
|
460
457
|
}
|
|
@@ -464,29 +461,29 @@ class T {
|
|
|
464
461
|
hideTypingIndicator() {
|
|
465
462
|
document.getElementById("typing-indicator").classList.remove("visible");
|
|
466
463
|
}
|
|
467
|
-
displayMessage(
|
|
464
|
+
displayMessage(e, t) {
|
|
468
465
|
const o = document.getElementById("message-container"), i = document.createElement("div");
|
|
469
|
-
i.textContent =
|
|
466
|
+
i.textContent = e, i.className = "message " + t, o.appendChild(i), o.scrollTop = o.scrollHeight;
|
|
470
467
|
}
|
|
471
|
-
sendAnalytics(
|
|
472
|
-
x(
|
|
468
|
+
sendAnalytics(e) {
|
|
469
|
+
x(e);
|
|
473
470
|
}
|
|
474
|
-
displayResults(
|
|
475
|
-
const
|
|
476
|
-
w(
|
|
471
|
+
displayResults(e) {
|
|
472
|
+
const t = document.getElementById("message-container");
|
|
473
|
+
w(e.map((o) => o.Title)), e.forEach((o) => {
|
|
477
474
|
const i = document.createElement("div");
|
|
478
475
|
i.className = "wine-item";
|
|
479
|
-
const
|
|
480
|
-
|
|
476
|
+
const a = document.createElement("img");
|
|
477
|
+
a.src = o.Image, i.appendChild(a);
|
|
481
478
|
const c = document.createElement("div");
|
|
482
479
|
c.innerHTML = `
|
|
483
480
|
<strong>${o.Title}</strong><br>
|
|
484
|
-
${
|
|
485
|
-
${
|
|
486
|
-
${
|
|
487
|
-
<a href="${o.Url}" onclick="sendAnalytics(${o.Title})" target="_blank">${
|
|
488
|
-
`, i.appendChild(c),
|
|
489
|
-
}),
|
|
481
|
+
${s.translate("price")}: ${o.Price}<br>
|
|
482
|
+
${s.translate("region")}: ${o.Region}<br>
|
|
483
|
+
${s.translate("type")}: ${o.Type}<br>
|
|
484
|
+
<a href="${o.Url}" onclick="sendAnalytics(${o.Title})" target="_blank">${s.translate("moreInfo")}</a>
|
|
485
|
+
`, i.appendChild(c), t.appendChild(i);
|
|
486
|
+
}), t.scrollTop = t.scrollHeight;
|
|
490
487
|
}
|
|
491
488
|
}
|
|
492
489
|
document.addEventListener("DOMContentLoaded", () => {
|
|
@@ -497,7 +494,7 @@ function B() {
|
|
|
497
494
|
<div id="chatbot-container">
|
|
498
495
|
<div id="chat-icon" onclick="toggleChatWindow()">
|
|
499
496
|
<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 -->
|
|
500
|
-
<span>${
|
|
497
|
+
<span>${s.translate("chatButton")}</span>
|
|
501
498
|
</div>
|
|
502
499
|
|
|
503
500
|
<div id="chat-window" class="hidden">
|
|
@@ -514,8 +511,8 @@ function B() {
|
|
|
514
511
|
<span></span><span></span><span></span>
|
|
515
512
|
</div>
|
|
516
513
|
<div id="input-container">
|
|
517
|
-
<input type="text" id="user-input" placeholder="${
|
|
518
|
-
<button id="send-button">${
|
|
514
|
+
<input type="text" id="user-input" placeholder="${s.translate("inputPlaceholder")}">
|
|
515
|
+
<button id="send-button">${s.translate("sendButton")}</button>
|
|
519
516
|
</div>
|
|
520
517
|
</div>
|
|
521
518
|
</div>
|
|
@@ -527,23 +524,23 @@ function L() {
|
|
|
527
524
|
}
|
|
528
525
|
function P() {
|
|
529
526
|
window.addEventListener("click", function(n) {
|
|
530
|
-
const
|
|
531
|
-
!
|
|
527
|
+
const e = document.getElementById("chat-window"), t = document.getElementById("chat-icon");
|
|
528
|
+
!e.contains(n.target) && !t.contains(n.target) && (e.classList.remove("visible"), t.style.display = "flex");
|
|
532
529
|
});
|
|
533
530
|
}
|
|
534
531
|
function W(n) {
|
|
535
532
|
console.log(n);
|
|
536
|
-
const
|
|
537
|
-
|
|
533
|
+
const e = document.getElementById("chat-icon"), t = document.getElementById("chat-window");
|
|
534
|
+
e.className = "", t.className = "", n === "right-center" ? (e.classList.add("chat-icon-right-center"), t.classList.add("right-center-aligned")) : e.classList.add("chat-icon-bottom-right");
|
|
538
535
|
}
|
|
539
536
|
var l;
|
|
540
537
|
if (typeof window < "u") {
|
|
541
538
|
const n = ((l = window.wineaterData) == null ? void 0 : l.POSITION) || "bottom-right";
|
|
542
539
|
window.addEventListener("DOMContentLoaded", async () => {
|
|
543
|
-
var
|
|
544
|
-
const
|
|
540
|
+
var a;
|
|
541
|
+
const t = ["climats", "telckel", "biobio", "weinpoint"].find((c) => window.location.href.includes(c)) || null;
|
|
545
542
|
let o;
|
|
546
|
-
|
|
543
|
+
t && (o = t.charAt(0).toUpperCase() + t.slice(1)), await s.fetchConfig(o || null), B(), L(), P(), W(n), b("chatbotToken", (a = window.wineaterData) == null ? void 0 : a.CLIENT_TOKEN, 365), new T().initialize();
|
|
547
544
|
});
|
|
548
545
|
}
|
|
549
546
|
export {
|
|
@@ -273,17 +273,17 @@
|
|
|
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 x(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){const e=`; ${document.cookie}`.split(`; ${n}=`);if(e.length===2)return e.pop().split(";").shift()}function l(n,t){
|
|
276
|
+
}`,g=document.createElement("style");g.textContent=d,document.head.appendChild(g);function x(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){const e=`; ${document.cookie}`.split(`; ${n}=`);if(e.length===2)return e.pop().split(";").shift()}function l(n,t){fetch("https://api-eu.mixpanel.com/track",{method:"POST",headers:{"Content-Type":"application/json",Authentication:"6f3d90d5b02720f58de3663e3ef675fe"},body:JSON.stringify({event:n,properties:t})}).then(s=>{s.ok||console.error("Mixpanel tracking failed",s)}).catch(s=>{console.error("Mixpanel tracking error",s)})}function u(){l("Chatbot Opened",{distinct_id:c("chatbotToken")})}function m(){l("Chatbot Closed",{distinct_id:c("chatbotToken")})}function v(n){l("Message Sent",{distinct_id:c("chatbotToken"),message_content:n})}function k(n){l("Message Sent",{distinct_id:c("chatbotToken"),products:n})}function C(n){l("Product Clicked",{distinct_id:c("chatbotToken"),product_id:n})}function h(){const n=document.getElementById("chat-window"),t=document.getElementById("chat-icon");n.classList.contains("visible")?(m(),n.classList.remove("visible"),t.style.display="flex"):(u(),n.classList.add("visible"),t.style.display="none")}function f(){m(),document.getElementById("chat-window").classList.remove("visible")}function b(){u(),document.getElementById("chat-window").classList.add("visible")}document.addEventListener("DOMContentLoaded",()=>{setupCloseButton(),setupOutsideClick()});const E=["climats","telckel","biobio","weinpoint"],I="OuhXJRleF6sROjsQZPWx1yqjrL6APeJxmHswqyOBWbgIqtXcht3MDadvI9DtOOoL";class y{constructor(t){var e;this.baseURL="https://api.wineater.com/",this.store=E.find(o=>window.location.href.includes(o)),this.token=((e=window==null?void 0:window.wineaterData)==null?void 0:e.CLIENT_TOKEN)||I}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 T{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 a=new T;class B{constructor(){this.api=new y,this.displayFirstMessage(a.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{v(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(a.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){C(t)}displayResults(t){const e=document.getElementById("message-container");k(t.map(o=>o.Title)),t.forEach(o=>{const i=document.createElement("div");i.className="wine-item";const s=document.createElement("img");s.src=o.Image,i.appendChild(s);const p=document.createElement("div");p.innerHTML=`
|
|
277
277
|
<strong>${o.Title}</strong><br>
|
|
278
|
-
${
|
|
279
|
-
${
|
|
280
|
-
${
|
|
281
|
-
<a href="${o.Url}" onclick="sendAnalytics(${o.Title})" target="_blank">${
|
|
278
|
+
${a.translate("price")}: ${o.Price}<br>
|
|
279
|
+
${a.translate("region")}: ${o.Region}<br>
|
|
280
|
+
${a.translate("type")}: ${o.Type}<br>
|
|
281
|
+
<a href="${o.Url}" onclick="sendAnalytics(${o.Title})" target="_blank">${a.translate("moreInfo")}</a>
|
|
282
282
|
`,i.appendChild(p),e.appendChild(i)}),e.scrollTop=e.scrollHeight}}document.addEventListener("DOMContentLoaded",()=>{window.toggleChatWindow=h,window.closeChatWindow=f,window.openChatWindow=b});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 -->
|
|
286
|
-
<span>${
|
|
286
|
+
<span>${a.translate("chatButton")}</span>
|
|
287
287
|
</div>
|
|
288
288
|
|
|
289
289
|
<div id="chat-window" class="hidden">
|
|
@@ -300,9 +300,9 @@
|
|
|
300
300
|
<span></span><span></span><span></span>
|
|
301
301
|
</div>
|
|
302
302
|
<div id="input-container">
|
|
303
|
-
<input type="text" id="user-input" placeholder="${
|
|
304
|
-
<button id="send-button">${
|
|
303
|
+
<input type="text" id="user-input" placeholder="${a.translate("inputPlaceholder")}">
|
|
304
|
+
<button id="send-button">${a.translate("sendButton")}</button>
|
|
305
305
|
</div>
|
|
306
306
|
</div>
|
|
307
307
|
</div>
|
|
308
|
-
`;document.body.insertAdjacentHTML("beforeend",n)}function W(){document.getElementById("close-btn").addEventListener("click",h)}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 S(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=((w=window.wineaterData)==null?void 0:w.POSITION)||"bottom-right";window.addEventListener("DOMContentLoaded",async()=>{var
|
|
308
|
+
`;document.body.insertAdjacentHTML("beforeend",n)}function W(){document.getElementById("close-btn").addEventListener("click",h)}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 S(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=((w=window.wineaterData)==null?void 0:w.POSITION)||"bottom-right";window.addEventListener("DOMContentLoaded",async()=>{var s;const e=["climats","telckel","biobio","weinpoint"].find(p=>window.location.href.includes(p))||null;let o;e&&(o=e.charAt(0).toUpperCase()+e.slice(1)),await a.fetchConfig(o||null),L(),W(),P(),S(n),x("chatbotToken",(s=window.wineaterData)==null?void 0:s.CLIENT_TOKEN,365),new B().initialize()})}r.closeChatWindow=f,r.openChatWindow=b,r.toggleChatWindow=h,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
package/src/js/analytics.js
CHANGED
|
@@ -15,25 +15,30 @@ function setCookie(name, value, days) {
|
|
|
15
15
|
const parts = value.split(`; ${name}=`);
|
|
16
16
|
if (parts.length === 2) return parts.pop().split(';').shift();
|
|
17
17
|
}
|
|
18
|
+
|
|
19
|
+
// Function to URL encode the data
|
|
20
|
+
function urlEncodeData(data) {
|
|
21
|
+
return Object.keys(data)
|
|
22
|
+
.map(key => encodeURIComponent(key) + '=' + encodeURIComponent(data[key]))
|
|
23
|
+
.join('&');
|
|
24
|
+
}
|
|
18
25
|
|
|
19
26
|
// Функция для отправки событий в Mixpanel
|
|
20
27
|
function trackEvent(event, properties) {
|
|
21
28
|
const token = '6f3d90d5b02720f58de3663e3ef675fe'; // Замените на ваш Mixpanel токен
|
|
22
|
-
const endpoint = 'https://api.mixpanel.com/track';
|
|
29
|
+
const endpoint = 'https://api-eu.mixpanel.com/track';
|
|
23
30
|
const data = {
|
|
24
31
|
event: event,
|
|
25
|
-
properties:
|
|
26
|
-
token: token,
|
|
27
|
-
...properties
|
|
28
|
-
}
|
|
32
|
+
properties: properties
|
|
29
33
|
};
|
|
30
34
|
|
|
31
35
|
fetch(endpoint, {
|
|
32
36
|
method: 'POST',
|
|
33
37
|
headers: {
|
|
34
|
-
'Content-Type': 'application/
|
|
38
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
39
|
+
'Authentication': token
|
|
35
40
|
},
|
|
36
|
-
body:
|
|
41
|
+
body: urlEncodeData(data)
|
|
37
42
|
}).then(response => {
|
|
38
43
|
if (!response.ok) {
|
|
39
44
|
console.error('Mixpanel tracking failed', response);
|