Track Hubspot Chats In Google Analytics with GTM [4 Simple Steps]

Dillon Jones
4 min readJun 11, 2022

--

If you’re using Hubspot to power your live chat (or have a Chat bot running), you might be wondering how you can track engagement in Google Analytics. Luckily, it’s relatively easy to set up tracking for Hubspot chat sessions in GA.

Let’s jump right into it 👇

What You Will Need:

You will need edit access in Google analytics and publish access in Google Tag Manager to allow you to publish your changes. You will also need a Hubspot chatflow setup on the website (live chat or chatbot both work with these instructions).

  1. Google Analytics
  2. Google Tag Manager
  3. Hubspot Chat on your website

Overview Of The Steps Involved:

  1. Create Event Variables in GTM
  2. Create a custom HTML tag in GTM for the chat listener
  3. Create a GTM trigger that fires on Hubspot chat engagement
  4. Create the Google Analytics event in Tag Manager
  5. Create Goals in Google Analytics (optional)

Step 1: Create event variables in Google Tag Manager

In this step, we are going to create 3 new Data layer variables.

  1. Go to variables in your GTM container
  2. Under ‘User-Defined Variables’ click ‘New’
  3. Select ‘Data Layer Variable’ > Name it eventCategory > under ‘Data Layer Variable Name’ enter eventCategory > Save
  4. Select ‘Data Layer Variable’ > Name it eventAction > under ‘Data Layer Variable Name’ enter eventAction > Save
  5. Select ‘Data Layer Variable’ > Name it eventLabel > under ‘Data Layer Variable Name’ enter eventLabel > Save

It should now look like this:

Step 2: Create a custom HTML tag in GTM for the chat listener

  1. Create a new tag in GTM and name it Chat Listener — Hubspot
  2. Under Tag Configuration, select Custom HTML
  3. Paste this code
<script>
function onConversationsAPIReady() {
window.HubSpotConversations.on('contactAssociated', function(payload) {
window.dataLayer.push({
'event': 'ga_event',
'eventCategory': 'hubspot chat',
'eventAction': 'contact associated',
'eventLabel': ''
})
});
window.HubSpotConversations.on('conversationStarted', function(payload) {
window.dataLayer.push({
'event': 'ga_event',
'eventCategory': 'hubspot chat',
'eventAction': 'conversation started',
'eventLabel': payload.conversation.conversationId
})
});
}
if (window.HubSpotConversations) {
onConversationsAPIReady();
} else {
window.hsConversationsOnReady = [onConversationsAPIReady];
}
</script>

4. Set the trigger to fire on all pages

Hubspot chat listener tag

5. Save your tag

Step 3: Create a trigger in GTM to fire on chat engagement

  1. Create a new Trigger in Google Tag Manager and name it Hubspot — Chat — Engagement
  2. Under Trigger Type, select ‘Custom Event’
  3. Create a trigger in GTM and name it GA Event— Hubspot— Chat
  4. In the Event Name field, enter: ga_event
  5. Under ‘This trigger fires on’, select ‘Some Custom Events’
  6. Select eventCategory from the dropdown > select equals > enter: hubspot-chat

Your trigger in GTM should look like this:

Hubspot chat trigger

Step 4: Setup a tag for the Google Analytics event

  1. Go to tags > new > Universal Analytics
  2. Category: Hubspot Chat
  3. Action: {{eventAction}}
  4. Label: {{Page URL}}
  5. Select your GA account under settings
  6. Under ‘Triggering’ add the Hubspot — Chat — Engagement trigger we created on the last step
  7. Save

Here is what your GA event tag it should look like:

Hubspot chat event for Google Analytics

Hubspot chat engagement will now push into Google Analytics as events.

Here is what that will end up looking like in GA. You can start running a variety of reports to track chat engagement across your website now.

  • conversation started = A user began a conversation
  • contact associated = A contact was created in Hubspot or was matched with an existing user (based on email address entered by the user)
    - NOTE: This only fires when an email reaches the ‘email’ property in Hubspot. It works every time for chat bots because you generally save the “what's your email?” automated question to the “email” property. For live chat, Hubspot wont pick up that its an email in normal conversation, the user would need to enter their email into a field like this —

[optional] Step 5: Setup a goal in Google Analytics when an email is associated from chat

  1. In Google Analytics > Admin > Goals > New Goal
  2. Goal setup = Custom
  3. Goal description:
    - Name = Chat — contact associated
    - Type = Event
  4. Goal details:
    -Category > Equals to > Hubspot Chat
    - Action > Equals to > contact associated
  5. Save

Now your goal reporting will include when contacts are associated via chat:

There are a ton of ways you can tailor steps outlined in this article based on your tracking needs. Hopefully this article was helpful to set the foundation of tracking Hubspot chats in Google Analytics.

Head here if you need to track Hubspot Forms in Google Analytics

If this helped you, be sure to leave a clap! 👏👏👏

--

--