0

how to init Freshdesk online chat widget after 5 seconds?

settimeout(function(e) {
    function initFreshChat() {

        window.fcWidget.init({
            token: "token number",
            host: "https://wchat.freshchat.com"
       });
    }

    function initialize(i,t){var e;i.getElementById(t)?initFreshChat():((e=i.createElement("script")).id=t,e.async=!0,e.src="https://wchat.freshchat.com/js/widget.js",e.onload=initFreshChat,i.head.appendChild(e))}function initiateCall(){initialize(document,"freshchat-js-sdk")}window.addEventListener?window.addEventListener("load",initiateCall,!1):window.attachEvent("load",initiateCall,!1);
}, 5000);

Not working...

1 Answers1

2

You can use this snippet. Make sure you enter the token value

<script>
  function initFreshChat() {
    window.fcWidget.init({
      token: "<FC_TOKEN>",
      host: "https://wchat.freshchat.com"
    });
  }
  function initialize(i, t) { var e; i.getElementById(t) ? initFreshChat() : ((e = i.createElement("script")).id = t, e.async = !0, e.src = "https://wchat.freshchat.com/js/widget.js", e.onload = initFreshChat, i.head.appendChild(e)) } function initiateCall() { setTimeout(() => { initialize(document, "freshchat-js-sdk") }, 5000) } window.addEventListener ? window.addEventListener("load", initiateCall, !1) : window.attachEvent("load", initiateCall, !1);
</script>

The setTimeout is placed inside initiateCall() function enter image description here

Why wrapping everything inside a setTimeout wouldn't work?

Wrapping the initialization snippet inside setTimeout wouldn't work as it defers registration of load event (thereby the load event listener not being not fired). The callback for load event listener is initiateCall(). It makes sense to place the setTimeout() inside initiateCall() to achieve the expected outcome

enter image description here

hem
  • 1,012
  • 6
  • 11