I'd like to integrate tawk.to chat into my Angular 6 website.
Tawk.to provides the following code:
<!--Start of Tawk.to Script-->
<script type="text/javascript"> 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/17f35g40afc2c34e96e75909/default'; s1.charset='UTF-8'; s1.setAttribute('crossorigin','*'); s0.parentNode.insertBefore(s1,s0); })(); </script>
<!--End of Tawk.to Script-->
The code basically creates divs in my page:
But naturally when I navigate to another route the html widget gets destroyed.
I'm thinking of using a service for fetching the external script and a component for displaying the widget. But I'm not sure how well it is going to work.
What's the best approach to integrate tawk.to live chat into an angular app ?
First Create your own tawk.to account
After you can receive some code form there like as Once the code is active on your website, you will be able to chat with visitors. then go to your
index.html
and Paste the code below on your website the before the</body>
tag.sample code
You can add script files in body tags at index.html
Adding CSS and JavaScript. The temptation is to add the external files directly to your index.html file.
in case anyone else is struggling with this I managed to make some progress, my stack is ionic 5 and angular 8, first I created a component in charge of loading Tawk to my PWA, with this simple code
The referenced the component on my app.component.html like this
Then found out from here https://www.tawk.to/knowledgebase/advanced-features/using-a-text-link-or-button-to-open-the-chat-widget/ that you can set the widget as hidden by default.
Finally, just call this function whenever you want to open the chat
Also, you can use this._window.Tawk_API to access any of the method defined on https://www.tawk.to/javascript-api/#onChatStarted
Only limitation that I'm still facing, is the following
Client opens the chat and sends a message
Operator receives the message and is typing a response
Client closes the chat before receiving response
operator sends the response
WebApp makes a soft click noise but no notification.
I guess I'll need to make some sort of workaround through push notification, so when an operator is chatting with someone and the person closes the chat, a notification is sent "manually"
<a id="bottom-right-corner" href="javascript:void(Tawk_API.toggle())"></a>
#bottom-right-corner { position: fixed; bottom: 0; right: 0; margin-bottom: 20px; //specify your margins, this is example. margin-right: 20px; }