Skip to main content

Olark Chat GTM Event Listener

Track Olark chat interactions in GTM. Monitor chat start, messages, operator availability, and offline messages with chatAction and chatMessage variables.

olarkchatgtmga4supportecommercesmall-business

Event fired

OlarkChatAction

Key variable

chatAction

Olark Chat

Overview

Olark is a live chat tool known for its accessibility features and detailed operator insights. This listener uses Olark's olark.api.chat.onMessageToVisitor and related event hooks to track interactions.

Event fired: OlarkChatAction Variables: chatAction, chatMessage

Tracked Events

chatActionDescription
chat startedConversation begins
message sentVisitor sends message
message receivedOperator replies
operator availableAgent online
operator unavailableAgent offline
chat endedSession ends
offline message sentVisitor sends offline msg

Installation

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

  var initOlark = function() {
    if (typeof window.olark === 'undefined') return;
    olark.configure('system.ask_for_name', false);
    
    olark('api.chat.onBeginConversation', function() { olarkPush('chat started'); });
    olark('api.chat.onMessageToOperator', function(event) {
      olarkPush('message sent', { chatMessage: event.body });
    });
    olark('api.chat.onMessageToVisitor', function(event) {
      olarkPush('message received', { chatMessage: event.body });
    });
    olark('api.chat.onOfflineMessageToOperator', function(event) {
      olarkPush('offline message sent', { chatMessage: event.body });
    });
    olark('api.visitor.onOperatorAvailabilityChange', function(event) {
      olarkPush(event.available ? 'operator available' : 'operator unavailable');
    });
  };

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

Data Layer Output

json
{
  "event": "OlarkChatAction",
  "chatAction": "message sent",
  "chatMessage": "I need help with my account"
}

Trigger Configuration

Trigger Type: Custom Event Event Name: OlarkChatAction

GA4 Mapping

GA4 EventConditionParameters
chat_widget_openchatAction = chat startedchat_platform: "olark"

Related Listeners