Use the code snippet below for Google Analytics event tracking with Freshchat:

<script>
window.fcSettings = {
onInit: function() {
if (typeof(ga) === "function") {
ga('create', '<GA TRACKING ID>', 'auto', 'FreshchatEvents');
window.fcWidget.on("widget:opened", function(resp) {
ga('FreshchatEvents.send', 'event', 'Freshchat widget', 'GadgetGod', 'Widget Open');
});
window.fcWidget.on("widget:closed", function(resp) {
ga('FreshchatEvents.send', 'event', 'Freshchat widget', 'GadgetGod', 'Widget Close');
});
window.fcWidget.on('message:received', function(resp) {
ga('FreshchatEvents.send', 'event', 'Freshchat widget', 'GadgetGod', 'Received');
});
window.fcWidget.on('message:sent', function(resp) {
ga('FreshchatEvents.send', 'event', 'Freshchat widget', 'GadgetGod', 'Sent');
});
window.fcWidget.on('user:statechange', function(resp) {
if (resp && resp.data && resp.data.userState === "created") {
ga('FreshchatEvents.send', 'event', 'Freshchat widget', 'GadgetGod', 'User Create');
}
if (resp && resp.data && resp.data.userState === "loaded") {
ga('FreshchatEvents.send', 'event', 'Freshchat widget', 'GadgetGod', 'User Loaded');
}
if (resp && resp.data && resp.data.userState === "identified") {
ga('FreshchatEvents.send', 'event', 'Freshchat widget', 'GadgetGod', 'User Identified');
}
if (resp && resp.data && resp.data.userState === "restored") {
ga('FreshchatEvents.send', 'event', 'Freshchat widget', 'GadgetGod', 'User Restored');
}
});
}
else {
console.log('Google Analytics not loaded');
}
}
}
</script>

<script src='//fw-cdn.com/1*****7/2*****4.js' chat='true'></script>


Note: To find the tracking code that you need to include before the  tag of the web pages you want to integrate, navigate to Admin Settings > Channels > Web Chat > Click Copy



The above code will load the Freshchat Conversations Widget (web messenger), and only if the Google Analytics code is also enabled will it track the following events:

  • Widget Open
  • Widget Closed
  • Messages Sent
  • Messages Received
  • User Create
  • User Loaded
  • User Identified
  • User Restored

You only need to replace two parameters in the script - your Web Chat Token and Google Analytics Tracking ID.