Tutorials

Tracking HubSpot Live Chat Conversions with Google Tag Manager

October 6, 2025

If you use HubSpot’s live chat widget on your website, you’re sitting on valuable intent signals that often go untracked.
Two moments in particular are gold for marketers:

  1. When a visitor starts a chat conversation
  2. When they submit their details (become a contact)

By tracking these events in Google Tag Manager (GTM), you can send them to marketing platforms (Google Ads, Meta, LinkedIn, etc.) as conversion events – improving attribution and enabling smarter optimization.

Why Track HubSpot Chat Events?

  • Conversion optimization – Chat interactions often correlate with high purchase intent.
  • Better audience targeting – Create retargeting segments of visitors who engaged with chat but didn’t convert.
  • Full-funnel insights – See how chat contributes to lead generation and sales.

The Script

We use a small JavaScript snippet that listens to HubSpot’s “conversationStarted” and “contactAssociated” events via the Chat widget SDK.
This script pushes events to the GTM dataLayer, which you can then use as triggers for conversion tags.

This is the code we use:

<script type="text/javascript">
// HubSpot Chat Widget Listener - by Terrific Digital
function onConversationsAPIReady() {
    window.HubSpotConversations.on('conversationStarted', function(payload) {
        window.dataLayer.push({
            'event': 'hubspot_live_chat',
            'action': 'conversation_started',
            'chat_id': payload.conversation.conversationId
        });
    });
    window.HubSpotConversations.on('contactAssociated', function(payload) {
        window.dataLayer.push({
            'event': 'hubspot_live_chat',
            'action': 'contact_associated',
            'data': payload
        });
    });
}
if (window.HubSpotConversations) onConversationsAPIReady();
else window.hsConversationsOnReady = [onConversationsAPIReady];
</script>

How It Works

  • onConversationsAPIReady() – Runs when the HubSpot Conversations API is ready.
  • conversationStarted listener – Fires when a visitor starts a chat, pushing an event to the dataLayer with a chat_id.
  • contactAssociated listener – Fires when a visitor submits their details, pushing another dataLayer event with their contact data.
  • Initialization – Checks if the API is already available; otherwise, waits until it’s ready.

GTM Configuration

Once the script is running on your site (via GTM or directly in the code), you can:

  1. Create Triggers in GTM:
    • Trigger 1: Custom Event → Event name = “hubspot_live_chat” → Condition: “action” equals “conversation_started”.
    • Trigger 2: Custom Event → Event name = “hubspot_live_chat” → Condition: “action” equals “contact_associated”.
  2. Attach Conversion Tags:
    • For Google Ads, Meta Pixel, LinkedIn, etc.
    • Send events as conversions or custom events.