LiveChat GTM Event Listener
Track LiveChat widget interactions in Google Tag Manager. Monitor window open/close, messages, form submissions, ratings, and greeting interactions. Capture chatAction and greetingId.
livechatchatgtmga4supportecommerce
Event fired
livechat interactionKey variable
chatActionLiveChat
Overview
LiveChat (LiveChat, Inc.) is a popular customer service platform. This listener uses LiveChat's JavaScript API (LiveChatWidget) to track 12+ distinct interactions including visibility changes, greeting displays, form submissions, message exchanges, and chat ratings.
Event fired: livechat interaction
Variables: chatAction, greetingId
Tracked Events
| chatAction Value | Trigger |
|---|---|
chat window maximized | Visitor expands chat |
chat window minimized | Visitor minimizes |
chat window hidden | Chat hidden |
pre-chat survey submitted | Pre-chat form |
post-chat survey submitted | Post-chat rating |
ticket form submitted | Offline ticket |
new message sent | Visitor message |
new event received | Rich event received |
greeting displayed | Proactive greeting shown |
greeting hidden | Greeting dismissed |
greeting button clicked | Greeting CTA clicked |
rating submitted | Chat rated |
rich message button clicked | Rich message interaction |
Installation
html
<!-- GTM Custom HTML Tag: LiveChat Listener -->
<script>
(function() {
function lcPush(action, extra) {
window.dataLayer = window.dataLayer || [];
window.dataLayer.push(Object.assign({
'event': 'livechat interaction',
'chatAction': action
}, extra || {}));
}
window.LiveChatWidget.on('visibility_changed', function(data) {
var actions = { maximized: 'chat window maximized', minimized: 'chat window minimized', hidden: 'chat window hidden' };
lcPush(actions[data.visibility] || data.visibility);
});
window.LiveChatWidget.on('form_submitted', function(data) {
var formActions = { 'pre-chat': 'pre-chat survey submitted', 'post-chat': 'post-chat survey submitted', ticket: 'ticket form submitted' };
lcPush(formActions[data.type] || 'form submitted');
});
window.LiveChatWidget.on('new_event', function(data) {
if (data.event.type === 'message') lcPush('new message sent');
else lcPush('new event received');
});
window.LiveChatWidget.on('rating_submitted', function(data) {
lcPush('rating submitted', { chatRating: data.value });
});
window.LiveChatWidget.on('greeting_displayed', function(data) {
lcPush('greeting displayed', { greetingId: data.id });
});
window.LiveChatWidget.on('greeting_hidden', function(data) {
lcPush('greeting hidden', { greetingId: data.id });
});
window.LiveChatWidget.on('rich_message_button_clicked', function(data) {
lcPush('rich message button clicked', { chatButtonText: data.element.label });
});
})();
</script>Fire on: Window Loaded. Requires
LiveChatWidgetto be initialized.
Data Layer Output
json
{
"event": "livechat interaction",
"chatAction": "greeting displayed",
"greetingId": "greeting_123"
}Trigger Configuration
Trigger Type: Custom Event
Event Name: livechat interaction
Conversion-specific:
Condition: DLV – Chat Action | matches RegEx | (pre-chat survey submitted|new message sent)
Variables to Capture
| Variable Name | DL Key | Example |
|---|---|---|
| DLV – LiveChat Action | chatAction | "new message sent" |
| DLV – LiveChat Greeting ID | greetingId | "greeting_123" |
| DLV – LiveChat Rating | chatRating | "good" |
GA4 Mapping
| GA4 Event | Condition | Parameters |
|---|---|---|
chat_widget_open | chat window maximized | chat_platform: "livechat" |
generate_lead | pre-chat survey submitted | chat_platform |
chat_rating | rating submitted | rating_value |