Plugin Directory

Changeset 3484619


Ignore:
Timestamp:
03/17/2026 09:45:24 AM (11 days ago)
Author:
bastho
Message:

Track FAQ visits in Matomo

Location:
faqtastic/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • faqtastic/trunk/build/chatbot/chatbot.asset.php

    r3471016 r3484619  
    1 <?php return array('dependencies' => array('react-dom', 'react-jsx-runtime', 'wp-components', 'wp-element', 'wp-hooks', 'wp-i18n'), 'version' => 'b5d64d93354ed3ef1e5c');
     1<?php return array('dependencies' => array('react-dom', 'react-jsx-runtime', 'wp-components', 'wp-element', 'wp-hooks', 'wp-i18n'), 'version' => 'cd78f84dc260318a07c1');
  • faqtastic/trunk/build/chatbot/chatbot.js

    r3471016 r3484619  
    1 (()=>{"use strict";var t={n:e=>{var a=e&&e.__esModule?()=>e.default:()=>e;return t.d(a,{a}),a},d:(e,a)=>{for(var o in a)t.o(a,o)&&!t.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:a[o]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)};const e=window.ReactDOM;var a=t.n(e);const o=window.wp.element,s=window.wp.components,c=window.wp.i18n,n=window.wp.hooks,l=window.ReactJSXRuntime,i="faqtastic-chatbot-history",r="faqtastic-chatbot-status",h=({dataset:t})=>{const[e,a]=(0,o.useState)(null),n=t.chatbotHeaderText||"Chatbot",i=t.chatbotHeaderSubtitle||"",h=t.chatbotFirstMsg||"Ask me a question",d=t.chatInputPlaceholder||"Type your question...",f=t.chatbotPosition||"bottom-right",p=t.toggleIconType||"dashicon",b=t.toggleIconDashicon||"format-chat",g=t.toggleIconSvg||"",m=t.toggleIconImageUrl||"";(0,o.useEffect)(()=>{"open"===localStorage.getItem(r)&&a(!0)},[]);const q=t=>{localStorage.setItem(r,t?"open":"closed"),a(t)};return(0,l.jsxs)("div",{className:"faqtastic-chatbot-wrapper","data-position":f,children:[e&&(0,l.jsx)(u,{onClose:()=>q(!1),chatbotHeaderText:n,chatbotHeaderSubtitle:i,chatbotFirstMsg:h,chatInputPlaceholder:d,dataset:t}),(0,l.jsx)("button",{className:"faqtastic-chatbot-toggle",onClick:()=>q(!e),"aria-label":(0,c.__)("Open chatbot","faqtastic"),children:"image"===p&&m?(0,l.jsx)("img",{src:m,alt:"",className:"faqtastic-chatbot-custom-image"}):"svg"===p&&g?(0,l.jsx)("span",{className:"faqtastic-chatbot-custom-icon",dangerouslySetInnerHTML:{__html:g}}):(0,l.jsx)(s.Dashicon,{icon:b||"format-chat"})})]})},d=t=>t&&t.$$typeof&&"Symbol(react.element)"===t.$$typeof.toString()?t:null;function u({onClose:t,chatbotHeaderText:e,chatbotHeaderSubtitle:a,chatbotFirstMsg:s,chatInputPlaceholder:r,dataset:h}){const[u,f]=(0,o.useState)(""),[p,b]=(0,o.useState)([]),[g,m]=(0,o.useState)([]),[q,x]=(0,o.useState)(-1),[y,w]=(0,o.useState)(!1),j={type:"bot",text:s};(0,o.useEffect)(()=>{(()=>{let t=JSON.parse(localStorage.getItem(i))||[j];m(t)})()},[]);const v=t=>{m(e=>{const a=[...e,t];return(t=>{let e=JSON.parse(localStorage.getItem(i))||[j];e.push(t),localStorage.setItem(i,JSON.stringify(e))})(t),a})};(0,o.useEffect)(()=>{if(!y){const t=document.querySelector(".faqtastic-chatbot-input");t&&t.focus(),w(!0)}},[y]),(0,o.useEffect)(()=>{let t;if(!(u.length<2))return t=setTimeout(()=>{fetch(`${faqtastic_ajax.ajax_url}?action=faqtastic_chatbot_suggestions&nonce=${faqtastic_ajax.nonce}&term=${encodeURIComponent(u)}`).then(t=>t.json()).then(t=>b(t)).catch(()=>b([]))},300),()=>clearTimeout(t);b([])},[u]);const S=t=>{v({type:"user",text:t.title}),b([]),f(t.title),fetch(`${faqtastic_ajax.ajax_url}?action=faqtastic_chatbot_get_answer&nonce=${faqtastic_ajax.nonce}&id=${t.id}`).then(t=>t.json()).then(t=>{v({type:"bot",text:t.content||(0,c.__)("No answer found.","faqtastic")}),f(""),x(-1)}).catch(()=>{v({type:"bot",text:(0,c.__)("An error occurred. Please try again.","faqtastic")})})};(0,o.useEffect)(()=>{const t=document.querySelector(".faqtastic-chatbot-conversation");t&&(t.scrollTop=t.scrollHeight)},[g]),(0,o.useEffect)(()=>{const t=t=>{0!==p.length&&("ArrowDown"===t.key?(t.preventDefault(),x(t=>(t+1)%p.length)):"ArrowUp"===t.key?(t.preventDefault(),x(t=>(t-1+p.length)%p.length)):"Enter"===t.key&&(t.preventDefault(),q>=0&&q<p.length&&S(p[q])))};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[p,q]);const _={term:u,setTerm:f,suggestions:p,setSuggestions:b,conversation:g,setConversation:m,addMessage:v,dataset:h};return(0,l.jsxs)("div",{className:"faqtastic-chatbot-window",children:[(0,l.jsxs)("div",{className:"faqtastic-chatbot-header",children:[(0,l.jsxs)("div",{className:"faqtastic-chatbot-header-text",children:[d((0,n.applyFilters)("faqtastic.chatbot.front.header.before",null,_)),(0,l.jsx)("span",{className:"faqtastic-chatbot-title",children:e}),a&&(0,l.jsx)("span",{className:"faqtastic-chatbot-subtitle",children:a}),d((0,n.applyFilters)("faqtastic.chatbot.front.header.after",null,_))]}),(0,l.jsx)("button",{onClick:t,className:"faqtastic-close-btn",children:"×"})]}),(0,l.jsxs)("div",{className:"faqtastic-chatbot-conversation",children:[d((0,n.applyFilters)("faqtastic.chatbot.front.conversation.before",null,_)),g.map((t,e)=>(0,l.jsx)("div",{className:`faqtastic-chatbot-bubble ${t.type}`,dangerouslySetInnerHTML:{__html:t.text}},e)),d((0,n.applyFilters)("faqtastic.chatbot.front.conversation.after",null,_))]}),(0,l.jsx)("input",{type:"text",className:"faqtastic-chatbot-input",placeholder:r,value:u,onChange:t=>f(t.target.value),autoComplete:"off",onFocus:()=>w(!0)}),d((0,n.applyFilters)("faqtastic.chatbot.front.input.after",null,_)),p.length>0&&(0,l.jsx)("ul",{className:"faqtastic-chatbot-suggestions",children:p.map(t=>(0,l.jsx)("li",{onClick:()=>S(t),className:q===p.indexOf(t)?"selected":"",children:t.title},t.id))}),d((0,n.applyFilters)("faqtastic.chatbot.front.end",null,_))]})}document.addEventListener("DOMContentLoaded",()=>{document.body.classList.contains("wp-admin")||document.querySelectorAll(".faqtastic-chatbot").forEach(t=>{a().render((0,l.jsx)(h,{dataset:t.dataset}),t)})})})();
     1(()=>{"use strict";var t={n:e=>{var a=e&&e.__esModule?()=>e.default:()=>e;return t.d(a,{a}),a},d:(e,a)=>{for(var o in a)t.o(a,o)&&!t.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:a[o]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)};const e=window.ReactDOM;var a=t.n(e);const o=window.wp.element,s=window.wp.components,c=window.wp.i18n,n=window.wp.hooks,l=window.ReactJSXRuntime,r="faqtastic-chatbot-history",i="faqtastic-chatbot-status",h=({dataset:t})=>{const[e,a]=(0,o.useState)(null),n=t.chatbotHeaderText||"Chatbot",r=t.chatbotHeaderSubtitle||"",h=t.chatbotFirstMsg||"Ask me a question",d=t.chatInputPlaceholder||"Type your question...",f=t.chatbotPosition||"bottom-right",b=t.toggleIconType||"dashicon",p=t.toggleIconDashicon||"format-chat",g=t.toggleIconSvg||"",m=t.toggleIconImageUrl||"";(0,o.useEffect)(()=>{"open"===localStorage.getItem(i)&&a(!0)},[]);const q=t=>{localStorage.setItem(i,t?"open":"closed"),a(t)};return(0,l.jsxs)("div",{className:"faqtastic-chatbot-wrapper","data-position":f,children:[e&&(0,l.jsx)(u,{onClose:()=>q(!1),chatbotHeaderText:n,chatbotHeaderSubtitle:r,chatbotFirstMsg:h,chatInputPlaceholder:d,dataset:t}),(0,l.jsx)("button",{className:"faqtastic-chatbot-toggle",onClick:()=>q(!e),"aria-label":(0,c.__)("Open chatbot","faqtastic"),children:"image"===b&&m?(0,l.jsx)("img",{src:m,alt:"",className:"faqtastic-chatbot-custom-image"}):"svg"===b&&g?(0,l.jsx)("span",{className:"faqtastic-chatbot-custom-icon",dangerouslySetInnerHTML:{__html:g}}):(0,l.jsx)(s.Dashicon,{icon:p||"format-chat"})})]})},d=t=>t&&t.$$typeof&&"Symbol(react.element)"===t.$$typeof.toString()?t:null;function u({onClose:t,chatbotHeaderText:e,chatbotHeaderSubtitle:a,chatbotFirstMsg:s,chatInputPlaceholder:i,dataset:h}){const[u,f]=(0,o.useState)(""),[b,p]=(0,o.useState)([]),[g,m]=(0,o.useState)([]),[q,w]=(0,o.useState)(-1),[x,y]=(0,o.useState)(!1),j={type:"bot",text:s};(0,o.useEffect)(()=>{(()=>{let t=JSON.parse(localStorage.getItem(r))||[j];m(t)})()},[]);const v=t=>{m(e=>{const a=[...e,t];return(t=>{let e=JSON.parse(localStorage.getItem(r))||[j];e.push(t),localStorage.setItem(r,JSON.stringify(e))})(t),a})};(0,o.useEffect)(()=>{if(!x){const t=document.querySelector(".faqtastic-chatbot-input");t&&t.focus(),y(!0)}},[x]),(0,o.useEffect)(()=>{let t;if(!(u.length<2))return t=setTimeout(()=>{fetch(`${faqtastic_ajax.ajax_url}?action=faqtastic_chatbot_suggestions&nonce=${faqtastic_ajax.nonce}&term=${encodeURIComponent(u)}`).then(t=>t.json()).then(t=>p(t)).catch(()=>p([]))},300),()=>clearTimeout(t);p([])},[u]);const S=t=>{v({type:"user",text:t.title}),p([]),f(t.title),fetch(`${faqtastic_ajax.ajax_url}?action=faqtastic_chatbot_get_answer&nonce=${faqtastic_ajax.nonce}&id=${t.id}`).then(t=>t.json()).then(e=>{v({type:"bot",text:e.content||(0,c.__)("No answer found.","faqtastic")}),f(""),w(-1),e.url&&window.Matomo&&(window.Matomo.getTracker().trackPageView(e.url),window.Matomo.getTracker().trackEvent("Chatbot","FAQ Clicked",t.title,e.url))}).catch(()=>{v({type:"bot",text:(0,c.__)("An error occurred. Please try again.","faqtastic")})})};(0,o.useEffect)(()=>{const t=document.querySelector(".faqtastic-chatbot-conversation");t&&(t.scrollTop=t.scrollHeight)},[g]),(0,o.useEffect)(()=>{const t=t=>{0!==b.length&&("ArrowDown"===t.key?(t.preventDefault(),w(t=>(t+1)%b.length)):"ArrowUp"===t.key?(t.preventDefault(),w(t=>(t-1+b.length)%b.length)):"Enter"===t.key&&(t.preventDefault(),q>=0&&q<b.length&&S(b[q])))};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[b,q]);const _={term:u,setTerm:f,suggestions:b,setSuggestions:p,conversation:g,setConversation:m,addMessage:v,dataset:h};return(0,l.jsxs)("div",{className:"faqtastic-chatbot-window",children:[(0,l.jsxs)("div",{className:"faqtastic-chatbot-header",children:[(0,l.jsxs)("div",{className:"faqtastic-chatbot-header-text",children:[d((0,n.applyFilters)("faqtastic.chatbot.front.header.before",null,_)),(0,l.jsx)("span",{className:"faqtastic-chatbot-title",children:e}),a&&(0,l.jsx)("span",{className:"faqtastic-chatbot-subtitle",children:a}),d((0,n.applyFilters)("faqtastic.chatbot.front.header.after",null,_))]}),(0,l.jsx)("button",{onClick:t,className:"faqtastic-close-btn",children:"×"})]}),(0,l.jsxs)("div",{className:"faqtastic-chatbot-conversation",children:[d((0,n.applyFilters)("faqtastic.chatbot.front.conversation.before",null,_)),g.map((t,e)=>(0,l.jsx)("div",{className:`faqtastic-chatbot-bubble ${t.type}`,dangerouslySetInnerHTML:{__html:t.text}},e)),d((0,n.applyFilters)("faqtastic.chatbot.front.conversation.after",null,_))]}),(0,l.jsx)("input",{type:"text",className:"faqtastic-chatbot-input",placeholder:i,value:u,onChange:t=>f(t.target.value),autoComplete:"off",onFocus:()=>y(!0)}),d((0,n.applyFilters)("faqtastic.chatbot.front.input.after",null,_)),b.length>0&&(0,l.jsx)("ul",{className:"faqtastic-chatbot-suggestions",children:b.map(t=>(0,l.jsx)("li",{onClick:()=>S(t),className:q===b.indexOf(t)?"selected":"",children:t.title},t.id))}),d((0,n.applyFilters)("faqtastic.chatbot.front.end",null,_))]})}document.addEventListener("DOMContentLoaded",()=>{document.body.classList.contains("wp-admin")||document.querySelectorAll(".faqtastic-chatbot").forEach(t=>{a().render((0,l.jsx)(h,{dataset:t.dataset}),t)})})})();
  • faqtastic/trunk/faqtastic.php

    r3471085 r3484619  
    346346
    347347    if($faq && $faq->post_type === 'faqtastic-qa') {
    348         wp_send_json(['content' => wp_kses_post($faq->post_content)]);
     348        wp_send_json(['content' => wp_kses_post($faq->post_content), 'url' => get_permalink($faq), 'context' => get_post_meta($faq->ID, 'faq_context', true)]);
    349349    }
    350350
  • faqtastic/trunk/src/chatbot/chatbot.jsx

    r3471016 r3484619  
    158158                setTerm('');
    159159                setKeyboardSelectedIndex(-1);
     160                if(data.url && window.Matomo) {
     161                    window.Matomo.getTracker().trackPageView(data.url);
     162                    window.Matomo.getTracker().trackEvent('Chatbot', 'FAQ Clicked', faq.title, data.url);
     163                }
    160164            })
    161165            .catch(() => {
Note: See TracChangeset for help on using the changeset viewer.