0

I have tried adding the chat script on .phtml of the custom extension which I have created for integrating my own live chat. But the libraries are showing undefined when the chat plugin loads the minified js.
Please let me know if there is any specific way to define libraries in Magento 2 which are being used in chat js as the same plugin is working on other platforms.

<script type = "text/javascript" >
   function initSupportScript() {
       var t = document.getElementsByTagName("head")[0],
           e = document.createElement("script");
       e.type = "text/javascript", e.src = 'https://www.example.com/plugins/js/chatcustomersupport.v3.min.js', e.onload = initChat, t.appendChild(e)
   }
if ("undefined" == typeof jQuery) {
   var headTag = document.getElementsByTagName("head")[0],
       jqTag = document.createElement("script");
   jqTag.type = "text/javascript", jqTag.src = "https://www.example.com/static/assets/global/plugins/jquery.min.js", jqTag.onload = initSupportScript, headTag.appendChild(jqTag)
} else initSupportScript();

/* Initialize Chat */
function initChat() {
   Chat.initialize({
       customercode: 'xxxxxxxxxxxxxxxxxx', // encrypted customer code 
       key: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', // partner support key
       iv: 'xxxxxxxxxxxxxxxxx', // pseudo random string in hex format
       label: 'Live Support',
       context: 'xxxxxxxxxxxxxxxx',
       success: function() {
           // your callback here (optional)
       },
       error: function(e) {
           console.log(e);
       }
   });
}
</script>

thanks

  • Can you add your error here ? – Aasim Goriya Jan 25 at 6:43
  • error in console - "TypeError: timesync is undefined" - | but timesync minified version is already added in chat js – Genio Jan 25 at 6:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.