Skip to main content

ChatStack GTM Event Listener

Track ChatStack live chat interactions in GTM. Monitor chat open, messages, and offline events with chatStack_Action variable.

chatstackchatgtmga4support

Event fired

chatStackEvent

Key variable

chatStack_Action

ChatStack

Overview

ChatStack is a live chat software solution. This listener hooks into ChatStack's JavaScript API to track widget interactions.

Event fired: chatStackEvent Variable: chatStack_Action

Tracked Events

chatStack_ActionDescription
chat openedWidget opens
chat closedWidget closes
message sentVisitor message
message receivedOperator reply
operator onlineAgent available
operator offlineAgent unavailable
offline messageOffline form submitted

Installation

html
<!-- GTM Custom HTML Tag: ChatStack Listener -->
<script>
(function() {
  function csPush(action, extra) {
    window.dataLayer = window.dataLayer || [];
    window.dataLayer.push(Object.assign({
      'event': 'chatStackEvent',
      'chatStack_Action': action
    }, extra || {}));
  }

  var initCS = function() {
    if (typeof window.ChatStack === 'undefined') return;
    ChatStack.on('open', function() { csPush('chat opened'); });
    ChatStack.on('close', function() { csPush('chat closed'); });
    ChatStack.on('messageSent', function() { csPush('message sent'); });
    ChatStack.on('messageReceived', function() { csPush('message received'); });
    ChatStack.on('operatorOnline', function() { csPush('operator online'); });
    ChatStack.on('operatorOffline', function() { csPush('operator offline'); });
    ChatStack.on('offlineMessage', function() { csPush('offline message'); });
  };

  window.addEventListener('load', initCS);
})();
</script>

Note: ChatStack's API method names may vary. Consult ChatStack documentation for your version.

Data Layer Output

json
{
  "event": "chatStackEvent",
  "chatStack_Action": "message sent"
}

Trigger Configuration

Trigger Type: Custom Event Event Name: chatStackEvent

Related Listeners