Good evening.

I recently started using Buttonizer and so far I am very satisfied. 😀
I would like to put a javascript button around the live chat from Tawk.to. I have made many attempts today and so far have not succeeded.
Does this work at all or has someone already implemented this?
I would be happy about an answer.

Thank you very much.

    Hey Sebastian ,

    First of all, welcome to the Buttonizer Community 🎉

    With our JavaScript API it's very easy to work with widgets we haven't implemented yet.

    If you have not done this yet, select the Custom JavaScript button action and replace the COPY THE BUTTON-ID from the script below with the visible Button ID (see the image below the script).

    window.addEventListener("buttonizer_button_clicked", event => {
      if(event.detail.button_id === "COPY THE BUTTON-ID") {
        window.Tawk_API.maximize()
      }
    });
    
    window.Tawk_API = window.Tawk_API || {};
    Tawk_API.onLoad = function() {
        // If there's an ongoing chat, don't do anything
        // Else, hide the widget
        if(!window.Tawk_API.isChatOngoing()) {
            window.Tawk_API.hideWidget();
        }
    
        // Hide widget if it's minimized
        window.Tawk_API.onChatMinimized = function() {
            window.Tawk_API.hideWidget();
        }
    };

    Then copy the script to your page and your button should work with Tawk.io chat widget 🙂

    Let me know if this works!

    Cheers,
    Jasper

      Hello Jasper.

      Thank you very much for your quick feedback.
      I must confess, I am not a web developer and I have been working with wordpress and building my website piece by piece.
      About my problem: I have so far not had the Tawk plugin installed and with Complianz integrations only run the javascript when the user has agreed to the cookies.
      I have now installed the Tawk plugin, successfully integrated and inserted your script in the javascript code editor. I have only entered the button ID. But unfortunately it still does not work. I have set the exceptions in the W3 Total Cache, then completely disabled for testing. Autoptimize is also disabled. But it still does not work.
      Sorry that I am a beginner and need so much support. 😃
      Thanks for your support.

      The script is executed when the user has agreed.

      var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
      (function(){
      var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
      s1.async=true;
      s1.src='https://embed.tawk.to/......';
      s1.charset='UTF-8';
      s1.setAttribute('crossorigin','*');
      s0.parentNode.insertBefore(s1,s0);
      })();

      Hey Sebastian,

      Apologies for the late reply. That's no problem, Buttonizer is for all kind of knowledge, that's why we've been building the visual editor 😎

      Can you let me know what your site is? Then I'll take a quick look and debug what's the reason it isn't working 🙂

      Cheers,
      Jasper

      I get the following error with your script:

      Uncaught TypeError: window.Tawk_API.maximize is not a function
          at eval (eval at value (frontend__premium_only.js?v=0d6f7e6ce6f1553544acb14682c8eb07&ver=6.0:2:170876), <anonymous>:5:21)
          at t.value (frontend__premium_only.js?v=0d6f7e6ce6f1553544acb14682c8eb07&ver=6.0:2:333652)
          at HTMLAnchorElement.<anonymous> (frontend__premium_only.js?v=0d6f7e6ce6f1553544acb14682c8eb07&ver=6.0:2:231105)
      eval @ VM130:5
      value @ frontend__premium_only.js?v=0d6f7e6ce6f1553544acb14682c8eb07&ver=6.0:2
      (anonym) @ frontend__premium_only.js?v=0d6f7e6ce6f1553544acb14682c8eb07&ver=6.0:2

      I checked the exceptions in W3 Total Cache and Autoptimize and cleared the cache. With the script from Tawk (My post number four) the chat is now started at once.

        Hey Sebastian , hope you've had a great weekend! Thanks for your reply!

        I've checked your site and saw you are using the deprecated custom JavaScript-editor (you can read more about that here). It's easier to edit JavaScript outside the editor as it performs better.

        You get this error as the script probably not initialized yet. Unfortunately it's not possible to load JavaScript files via the custom JavaScript-editor inside Buttonizer (and I don't recommend it as it will include the files every time you click on the button which will make the webpage slow).

        Is it possible to move the scripts outside the editor and use a header-footer plugin for that? You'll need to execute something like this to only load the Tawk widget as soon the compliance widget says it's ready (in some header-footer plugin):

        jQuery(document).on("cmplzEnableScripts", function() {
          var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
          (function(){
            var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
            s1.async=true;
            s1.src='https://embed.tawk.to/......';
            s1.charset='UTF-8';
            s1.setAttribute('crossorigin','*');
            s0.parentNode.insertBefore(s1,s0);
          })();
        });

        (disclaimer, I am not sure if it's the jQuery(document).on("cmplzEnableScripts", function() { you need to use, I wasn't able to find enough information at the moment)

        Where did you paste the script I mentioned here? Jasper ? Also in a headers-footers plugin?

        Let me know!

        Cheers,
        Jasper

        Hello Jaspis,
        thanks for your review first of all.
        I thought the JavaScript editor is made for this and not outdated (your knowledgebase link does not work unfortunately). I will try the script outside, so with a header footer plugin.

        At the beginning I had integrated the script in cmplz. Since the code is integrated in the Buttonizer JavaScript editor, I removed it from cmplz. That's why you couldn't find anything. 😃

        I'll try everything again at my leisure, but definitely don't have time for it in the next four weeks. I will contact you if I need support again. 😀
        Finally I wish you a good time and many many thanks again. Great support!