Recent posts

Mind, Body & Soul
Do Not Whistle at Night: South Africas Strangest Superstitions
26 April 2025

Geek Chic
How to Replace A Broken Lenovo Laptop Screen
24 April 2025

Money Talks
Everything You Need to Know About SASSA Status Check
13 April 2025

Mind, Body & Soul
The Genetic Diversity of Cannabis Seeds
12 April 2025
Popular posts
Extravaganza
Trending Music Hashtags To Get Your Posts Noticed
24 August 2018
Geek Chic
How To Fix iPhone/iPad Only Charging In Certain Positions
05 July 2020
Extravaganza
Trending Wedding Hashtags To Get Your Posts Noticed
18 September 2018
Money Talks
How To Find Coupons & Vouchers Online In South Africa
28 March 2019
How To Track Freshworks Live Chat With GTM
16 April 2023 | 0 comments | Posted by Che Kohler in nichemarket Advice
I was approached by a client recently with a request to track a third-party live chat function on their website. The tool is called Freshchat and is run by the company Freshworks, and it's the standard Live Chat tool you'll find on many sites in the bottom right-hand corner of the screen.
Third-party live chat tools are pretty handy, but they don't always play nice with your GTM and GA, and the Freshworks chat app is no exception. I first tried my hand at click triggers and element visibility triggers to try and create a unique event but had no luck.
GTM had no way of identifying when I was clicking to prompt the Live chat to open.
So I scoured the web for answers, and I managed to come up with a solution using:
- A custom javascript listener
- A custom event trigger
- A trigger grouping
Note: While this tracking solution does work today, it might not work in the future as Freshworks makes changes to it. Also you might not reproduce the same results as I do, so you might need to adjust your triggers based on your data layer.
Creating a custom listener.
The first step in getting your Freshchat to speak to your Google Tag Manager account is to create a bridge between the two, and this is where a custom listener comes in. I managed to find several pages that offered Listeners for this exact issue, but I settled on the following.
Source: GitHub - Knogobert/freshchat.js
If you wish to use their standard version and use your triggers based on the event parameters set in all these custom events, be my guest. It should work just fine; you would simply push every event to your GA using the GeneralEvent custom event and set parameters to capture the event action.
To me, this was a bit of a bother and added additional steps, and the client only wanted to track Live chat opens as a lead, so what I did was customise each GeneralEvent as a custom Event. This makes each click event easier to identify in Tag Manager, and you can set your tags accordingly.
To get started, you can either:
- Edit the custom HTML tag you're using for your Fresha account and paste in this additional code.
- Set up a separate custom HTML tag, paste in the code below with a few changes and set it to fire on either all pages or the pages you have Live chat set up on.
Copy the code below and replace the token section YOUR_FC_TOKEN with the code for your Freshchat account. Also be sure to include an open and close script tag when pasting the code into the tag.
_script_ var messagesSent = 0;
window.fcSettings = {
token: "YOUR_FC_TOKEN",
host: "https://wchat.freshchat.com",
onInit: function() {
if (window.dataLayer !== undefined) {
window.fcWidget.on("widget:loaded", function (resp) {
window.fcWidget.on("widget:opened", function (resp) {
window.dataLayer.push({ event: "Live_Chat_Open", eventCategory: "freshchat",
eventAction: 'Widget Open', eventLabel: window.location.href });
});
window.fcWidget.on("widget:closed", function (resp) {
window.dataLayer.push({ event: "Live_Chat_Close", eventCategory: "freshchat",
eventAction: 'Widget Close', eventLabel: window.location.href });
}); window.fcWidget.on('message:received', function (resp) {
window.dataLayer.push({ event: "Live_Chat_Message_Receive", eventCategory:
"freshchat", eventAction: 'Received', eventLabel: window.location.href });
}); window.fcWidget.on('message:sent', function (resp) {
if (messagesSent === 0) {
window.dataLayer.push({ event: "Live_Chat_First_Chat", eventCategory: "freshchat",
eventAction: 'Sent first chat', eventLabel: window.location.href });
} window.dataLayer.push({ event: "Live_Chat_Sent", eventCategory: "freshchat",
eventAction: 'Sent', eventLabel: window.location.href });
messagesSent++;
}); window.fcWidget.on('user:statechange', function (resp) {
if (resp && resp.data && resp.data.userState === "created") {
window.dataLayer.push({ event: "Live_Chat_User_Create", eventCategory: "freshchat",
eventAction: 'User Create', eventLabel: window.location.href });
} if (resp && resp.data && resp.data.userState === "loaded") {
window.dataLayer.push({ event: "Live_Chat_User_Loaded", eventCategory: "freshchat",
eventAction: 'User Loaded', eventLabel: window.location.href });
} if (resp && resp.data && resp.data.userState === "identified") {
window.dataLayer.push({ event: "Live_Chat_User_Identified", eventCategory:
"freshchat", eventAction: 'User Identified', eventLabel: window.location.href });
} if (resp && resp.data && resp.data.userState === "restored") {
window.dataLayer.push({ event: "Live_Chat_User_Restored", eventCategory:
"freshchat", eventAction: 'User Restored', eventLabel: window.location.href });
}
});
});
}
else {
console.log('Freshchat can’t use Google Tag Manager');
}
}
};
_/script_
_script src="https://wchat.freshchat.com/js/widget.js" async>_script_
Once the listener is active, go ahead and test your data layer by heading to the preview mode and clicking the live chat. You should see three custom events fire upon click.
- Live_Chat_User_Loaded
- Live_Chat_Open
- Live_Chat_Open
So now you're in a bit of a pickle; how do you create a trigger if the custom event fires twice?
I tried tweaking the code, but I couldn't get it to stop double firing, so I opted for the next best thing, using the entire stack to create one trigger.
Since I know that when I click on the open that the event fires twice, and I can constantly reproduce it, I can use this as a unique event using a trigger grouping.
- I created a trigger for the Live_Chat_User_Loaded using the custom event trigger.
- Then I created a trigger for the Live_Chat_Open
If you're unfamiliar with the process, head over to triggers
- Add a new trigger,
- Give your trigger a name - IE Live Chat Loads Trigger and Live Chat Open Trigger
- Select custom event,
- Under event name paste in the custom event - IE Live_Chat_User_Loaded
- Leave it set to all custom events.
- Save the trigger.
- Repeat the process so you have two triggers.
What is a trigger group?
Now, create a trigger grouping.
A trigger group will evaluate the conditions of two or more triggers as one. The trigger group will only fire after all of the selected triggers have fired at least once. If you add more than one instance of a particular trigger, it will need to fire the corresponding number of times before this trigger group will fire.
To create a trigger group:
- Click Triggers New.
- Click Trigger Configuration and choose Trigger Group.
- Give trigger grouping a name.
- Click and select two triggers you have already created.
- Click Add.
- Click Save.
Creating the live chat tracking tag
Now you have all the elements in place; you can go ahead and create the GA4 tag.
- Create a new tag
- Give the tag a name - Live Chat Open Tag
- Select the tag type GA4 event
- Select your GA4 configuration tag
- Give the event a name IE - lead_live_chat
- Select the trigger grouping you named and created earlier
- Click save.
After all that, the last step would be to go back to your GTM, select the preview mode and test that your trigger grouping fires correctly and that you only have one event passing to GA4.
Note: This method above is only for those interested in tracking the live chat open on the first try. If you want more granular tracking, please reach out to us, and we can build a custom set-up for you.
Contact us
If you want to know more about digital marketing or feel this entire GA thing is too much of a bother and you need it sorted by experts, then we’re happy to assist. Simply contact us, and we can sort out your data migration for you.
Are you looking to promote your business?
Business owners can create their free business listing on nichemarket. The more information you provide about your business, the easier it will be for your customers to find you online. Registering with nichemarket is easy; all you will need to do is head over to our sign-up form and follow the instructions.
If you require a more detailed guide on creating your profile or listing, we highly recommend you check out the following articles.
Recommended reading
If you enjoyed this post and have a little extra time to dive deeper down the rabbit hole, why not check out the following posts about Google Analytics?
- How To Track Social Sharing In Google Analytics
- Get Back Your Google Analytics Account With These Simple Steps
- How To Properly Set Up Google Analytics With Shopify Sites
- Google Analytics Interaction Hit Vs Non-Interaction Hit
- How To Track Video Views With Google Analytics
- How To Track Search and Zero Search Queries In Google Analytics
Tags: Tracking, Data Analytics, Big Data
You might also like
Everything You Need to Know About SASSA Status Check
13 April 2025
Posted by Azhar Khanzada in Money Talks
A guide for 2025 for anyone looking to apply for a SASSA grant or would like to keep up to date with the status of your grant from application to red...
Read moreThe Genetic Diversity of Cannabis Seeds
12 April 2025
Posted by Alina Jones in Mind, Body & Soul
A look into the South African heritage of cannabis growing and how the country has taken the plant in terms of growing it into a viable industry & th...
Read more
{{comment.sUserName}}
{{comment.iDayLastEdit}} day ago
{{comment.iDayLastEdit}} days ago