Track Tawk.to Chat Engagement in Google Analytics through Google Tag Manager

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:

widget-code

Now we’ll create a custom HTML tag in GTM and fire it on all pages.

tawkto-main-tag

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:

tawkto-engagement

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:

chat-started-tag

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:

gtm-debug-mode

We also see the event coming in Google Analytics real-time reports:

events-real-time

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.

5 Google Analytics posts you don’t want to miss in October

Here’s again the last post of the month saved for the top 5 interesting Google Analytics related resources I found on other sites. Here’s the selection for October – you may want to bookmark those as they can be very useful:

How to A/B Test with Google Tag Manager | Measureschool

In this video, Justin shows how to use Google Tag Manager as A/B testing tool and avoid paying for Optimizely or VWO. With this implementation the data will be sent to Google Analytics and you’ll need to calculate the winner additionally.

How to Find and Purge Personally Identifiable Information from Your Google Analytics

This post explains what constitutes as personal identifiable information (PII) and how to avoid passing this information to Google Analytics using different methods.

9 things you need to know about tracking social media with Google Analytics

Learn how social media is automatically tracked by GA, how to correctly track your paid social campaigns, use the social reports available in GA, and more!

How to Use Search Analytics in Google Sheets for Better SEO Insights

This small guide shows how to use the Search Analytics for Sheets add-on to fetch data from Google Search Console (via its API), grouped and filtered to your liking, and create automated monthly backups.

Spotlight on Google Tag Manager: Open and Secure Tag Management

Google introduced new third-party tag templates for GTM and added the recommendation to split the container snippet into two parts: a JS snippet to be placed in the <head> of the pages, and an iframe snippet that should be implemented just after the opening <body> tag.

P.S. Got a Google Analytics question? Send it to me and I’ll try to answer it on the blog.

5 Google Analytics posts you don’t want to miss in September

Here’s again the last post of the month saved for the top 5 interesting Google Analytics related resources I found on other sites.

So much good stuff this month! It’s hard to pick up only 5 blogs to share. Here’s the selection for September – you may want to bookmark those as they can be very useful:

Magically track forms using Google Analytics

In this post Benjamin shows how to use Komito Analytics to track form abandonment and interactions fast and easy. It’s JavaScript that you can add in Google Tag Manager and automatically track a number of custom interactions.

Tracking Multiple Categories in Google Analytics for Content Pages

A step-by-step tutorial how to track articles that are associated with multiple tags and categories in Google Analytics. You’ll create a custom dimension for each page category and a custom metric to track how often each category is viewed.

Get the Recipe: Hover Tracking in Google Tag Manager

Google Tag Manager doesn’t automatically listen for hover events and the awesome guys at LunaMetrics provided a recipe that you can download and import into your GTM container. Follow the extra instructions and start tracking hover events!

10 JavaScript Concepts For Web Analytics Implementation

This blog from Simo follows a conference talk he gave at MeasureCamp IX, London earlier this month. I agree that understanding the JavaScript basics are extremely important in web analytics implementation. Go through the 10 JS concepts presented and if you’re still feeling lost, go ot Codecademy, get a book about JS and practice!

Google updates – there were so many amazing announcements from the GA team: you can move GA properties (extremely useful for agencies that have all their customers GA sites under one account), work with the improved unique events metric and sign up for the free Google Optimize!

P.S. Got a Google Analytics question? Send it to me and I’ll try to answer it on the blog.

Track onclick event handler value with Google Tag Manager

It’s not very common but you may stumble upon a case where you need to record the value of an onclick event handler.

Usually you have a JavaScript function and the “onClick” event handler executes a piece of JS when an element is clicked on. It can be added to elements like <a> tags, form buttons, check boxes, <div> tags, etc. Here’s an actual example:

&lt;script&gt;
function inform(){
alert("You have activated me by clicking the grey button! Note that the event handler is added within the event that it handles, in this case, the form button event tag")
}
&lt;/script&gt;

&lt;form&gt;
&lt;input id="click-me-button" type="button" name="test" value="Click me" onclick="inform()"&gt;
&lt;/form&gt;

On this test page we have a button that will show an alert when clicked. And we want to record an event with some category that we define and the onclick value as action (it will dynamically change if you have different onclick event handlers).

Let’s build our variable first:

function() {
var field = {{Click Element}}.getAttribute('onclick');
return field;
}

It will get the onclick value of the element you’re clicking.

onclick variable

Now let’s enter Preview & Debug mode and see if it does what we need – click on the button and explore the variables list:

onclick GTM preview

Looks good! Now we can build a simple event tag in GTM, firing on the click of this button:

tag settings

Publish the workspace and start gathering data:

real time results

So, that’s it! What kind of onclick event handlers do you need to track?

5 Google Analytics posts you don’t want to miss in August

Here’s again the last post of the month saved for the top 5 interesting Google Analytics related resources I found on other sites. Here are the five for August – you may want to bookmark those as they can be very useful:

Introducing the Google Analytics Demo Account

In the beginning of the month Google Analytics launched a fully functional Demo Account, available to everyone, with real ecommerce data from the Google Merchandise Store. Avinash published a great post about it, explaining how to get access and jump-start your learning: Be Real-World Smart: A Beginner’s Advanced Google Analytics Guide

Two Steps To Correctly Tracking Subdomains in Google Analytics

This LunaMetrics article shows how to properly implement subdomain tracking in Google Tag Manager, along with example scenarios. Check out the reasons why you need (or don’t) subdomain tracking and what to do next.

Troubleshooting Cross-Domain Tracking In Google Analytics

In this post Simo shows the easiest way to implement cross-domain tracking – through Google Tag Manager. You can use his short checklist to identify issues and make sure cross-domain tracking is working.

GTM Match Table Variable Generator (Lookup Tables & Beyond)

Despite being an extremely useful feature in Google Tag Manager, the lookup table Variable can be tedious to configure and it supports exact-match only. You can use this template by Seer Interactive to easily create a big lookup table or get regex support.

Enterprise-Class Tag Management: Announcing Workspaces

Google announced a major update to Google Tag Manager introducing workspaces and interface changes. Simo Ahava published two quite comprehensive articles on the same day which can be used as walk-throughs for the new features:

P.S. Got a Google Analytics question? Send it to me and I’ll try to answer it on the blog.