Tawk.to is getting popular very quickly as a free chat web application. Here’s an easy way to add the service to your website through Google Tag Manager and send an event to Google Analytics when a chat starts.
Let’s begin by adding the Tawk.to widget to our site with GTM. Go to Admin and copy your widget code:
Now we’ll create a custom HTML tag in GTM and fire it on all pages.
This will show the Tawk.to chat pop up on every page of the site.
Let’s add the chat interaction tracking in another custom HTML tag:
Here’s the code I’m using:
<script type="text/javascript">
Tawk_API.onChatStarted = function(){
if(Tawk_API.isVisitorEngaged()){
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({'event': 'chat-started'});
}
};
</script>
There’s also Tag Sequencing setting to fire our main Tawk.to tag before this Tawk.to engagement tag.
And the last tag we’ll create is the GA event tag for chat interaction, which will fire on the chat-started event:
We can go to Preview mode and test it. When we started a chat, the chat-started event appeared in the events column of the GTM Debug console and our Chat engagement GA tag was fired:
We also see the event coming in Google Analytics real-time reports:
From here you can use the event to setup a goal in GA, import it into AdWords or add AdWords / Facebook conversion tracking for the chat interaction activity. Hope you’ll find this useful and try it yourself.






Hi Margarita
What is the trigger configuration which allows to fire a tag for chat engadgement?
Looking for your reply.
Thanks
Hey Stephen, the trigger for the first two tags is All Pages, and the trigger for the Chat engagement tag is custom event = chat-started, like this: http://prntscr.com/drvx45
I am still confused here. For the Normal Tawk Tag, you want to have all pages trigger. For Engagement Tag it will be a chat-started trigger and for GA it will be all pages trigger??
https://snipboard.io/fF4EIl.jpg This is how my tags are firing, I don’t think it was supposed to do that.
Hi Margarita:
I have a question, in the step “Chat engagement (the last one)” in “label” you refer the URL of the page where that chat online is hosted?
Hi Rosa, the label in the Chat engagement tag is for the page the chat originated from. If you’ve enabled the chat on all pages, it will show the specific page the visitor was on, when they started the chat.
Thank You, Margarita.
Hello,
I am looking for an alternative method that does not include using GTM to place the widget on the site. I tried to setting the Tawk.to engagement tag to fire at an interval, but this did not work.
Do you know how I could get this to work?
No, sorry. But you probably can reach out to their support for help.
Hi Zander,
Maybe this page could help.
https://www.tawk.to/knowledgebase/advanced-features/using-a-text-link-or-button-to-open-the-chat-widget/
Thank you so much! This worked! It took me forever… but after looking at the link in your first comment, that helped dummy old me figure it out!
I just added the Event as a Goal in GA. I should know if it works soon but for the label, do I do the same: {{Page URL}}
?
THANKS!
Hi Kristi, if you want to see from which page the chat started, you can do {{Page URL}} as in my example.
Hi Margrita,
Nice article but dont you think it should be
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({‘event’: ‘chat-started’});
as Simo mentioned here https://www.simoahava.com/gtm-tips/datalayer-declaration-vs-push/
Hey Jaideep, it seems both could work: https://twitter.com/maggieto/status/896078499319918592
But I’ll modify my example to be on the safe side. Thanks!
Hi Margarita,
Thanks for this article.
The tag for chat-started is firing however the event for Chat Engagement is not.
Please assist
I figured it out. Thanks again!
Great to hear that, Rachel!
Hi Margarita,
When im configuring the last lag (UA)
The only option I get for a trigger is “All pages”
I can’t figure out how to put there “chat started”
Thanks.
Hernán
Hi Hernán,
You need to create a new trigger by clicking on the + sign in the top right corner of the triggers list. Give it a name, select custom event as type and enter the chat-started for value.
Hello Margarita,
I haven’t figured out how to create the last tag (GA). I don’t know what to write in every field, for example “Value”and “Hit with no interaction”
https://www.dropbox.com/s/0v71hlwhvdqtpb7/Screen%20Shot%202017-12-14%20at%207.30.47%20PM.png?dl=0
Hi Lili, just leave the last two fields empty – nothing for value and false for non-interaction hit. Cheers!
It works. Thank you for your guides!
That worked. Short and sweet. Thanks!
Hey thank you for the article! The chat-started event is not being pushed for me and I’m thinking maybe it’s because the second tag “Chat engagement” is being fired right away and the user is not yet engaged? (isVisitorEngaged( ) is rendering false)
Read through the previous comments and looked at the screenshot and everything seems to be setup as shown.
Hey Conor, it shouldn’t really matter that the tag is fired before the actual interaction, as it’s just a listener. You can try what Ryan is suggesting here: http://www.ryanpraski.com/drift-google-analytics-tracking/
Hi Margarita,
Thanks for the article. Everything seems to be working fine except for when I’m trying to track the “Chat Maximize” on mobile devices. I am unable to trigger this event using the below code. Kindly let me know if there is anything i need to change.
Tawk_API = Tawk_API || {};
Tawk_API.onChatMaximized = function(){
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({‘event’: ‘chat-maximized’});
};
Hi Aaron, is this code executed after the main Tawk.to script? If yes, you may try contacting their support.
Hi Margarita,
The tracking seems to be working fine for the desktop website, but i am unable to track “Chat Maximize” for mobile users. Can you help me out with this?
Tawk_API.onChatMaximized = function(){
This is the function i am using.
Thanks.
Thanks for your help!!! Great article!
Hi Margarita,
Thanks for the article. Where I get the Tranking ID ?
Hi Arturo, in GA Admin under Property, there’s an option Tracking info -> Tracking code that shows your tracking ID.
what you mean “uaid” ?
uaid = Universal Analytics ID, or your GA tracking code ID
Hey Margarita
Do i need to configure anything in google analytics account for this to work? I just added in my website and still confused.
Can’t seem to get the Chat Engagement tag to fire, other two are firing, any help please.
Great Help
Any help? Chat Engagement tag doesn’t seem to work anymore
Maybe you can contact their support for guidance.
Hi, i have the same problem
Chat engagement tag is not getting fired for my website. Is there any code that I have to use in my website like dataLayer.push(). Can You help me on how to use code in website with sample example?