Skip to main content

Freshchat GTM Event Listener

Track Freshchat (Freshdesk Messaging) interactions in GTM. Monitor widget open/close, conversations, messages, and bot interactions with freshEvent_type variable.

freshchatfreshdeskfreshworkschatgtmga4supportsaas

Event fired

freshChat_Event

Key variable

freshEvent_type

Freshchat

Overview

Freshchat (part of Freshworks) is a customer messaging platform with AI-powered chatbots, live chat, and team inbox. This listener hooks into Freshchat's JavaScript widget API to track interactions.

Event fired: freshChat_Event Variable: freshEvent_type

Tracked Events

freshEvent_typeDescription
widget openedChat widget opens
widget closedWidget closes
conversation startedNew chat initiated
message sentVisitor message
message receivedAgent/bot reply
bot message receivedBot sends automated message
conversation resolvedChat marked resolved
csat submittedCustomer satisfaction rating
email capturedUser provides email

Installation

html
<!-- GTM Custom HTML Tag: Freshchat Listener -->
<script>
(function() {
  function freshPush(type, extra) {
    window.dataLayer = window.dataLayer || [];
    window.dataLayer.push(Object.assign({
      'event': 'freshChat_Event',
      'freshEvent_type': type
    }, extra || {}));
  }

  var initFresh = function() {
    if (typeof window.fcWidget === 'undefined') return;
    fcWidget.on('widget:opened', function() { freshPush('widget opened'); });
    fcWidget.on('widget:closed', function() { freshPush('widget closed'); });
    fcWidget.on('conversation:started', function(data) {
      freshPush('conversation started', {
        conversationId: data && data.response && data.response.conversationId
      });
    });
    fcWidget.on('message:sent', function(data) {
      freshPush('message sent');
    });
    fcWidget.on('message:received', function(data) {
      var isBotMsg = data && data.message && data.message.actorType === 'bot';
      freshPush(isBotMsg ? 'bot message received' : 'message received');
    });
    fcWidget.on('conversation:end', function() { freshPush('conversation resolved'); });
    fcWidget.on('csat:submitted', function(data) {
      freshPush('csat submitted', { csatScore: data && data.score });
    });
  };

  if (window.fcWidget) {
    initFresh();
  } else {
    window.addEventListener('load', initFresh);
  }
})();
</script>

Data Layer Output

json
{
  "event": "freshChat_Event",
  "freshEvent_type": "conversation started",
  "conversationId": "conv_12345"
}

Trigger Configuration

Trigger Type: Custom Event Event Name: freshChat_Event

Variables to Capture

Variable NameDL KeyExample
DLV – Freshchat Event TypefreshEvent_type"conversation started"
DLV – Freshchat CSAT ScorecsatScore5

GA4 Mapping

GA4 EventConditionParameters
chat_widget_openwidget openedchat_platform: "freshchat"
chat_ratingcsat submittedrating_value

Related Listeners