APIs & Integrations

piersg
Key Advisor

Hubspot chat widget events not working

SOLVE

Hi there,

 

I'm trying to push to the dataLayer when chat is open/closed etc. but the events, specifically window.HubSpotConversations.on, aren't working. I can open and close the chat widget with

 

window.HubSpotConversations.widget.open();
window.HubSpotConversations.widget.close();

 

 

but when I try and do anything with the supported events I get nothing e.g.

 

window.HubSpotConversations.on('conversationStarted', payload => {
  console.log(payload);
});

 

 

This is what I've implemented (in GTM) to push to the dataLayer.

 

<script type="text/javascript">
  function onConversationsAPIReady() {
    window.HubSpotConversations.on( 'conversationStarted', function(payload) {
      window.dataLayer.push({
        'event': 'hubspot-chat-started',
        'hs-chat-id': payload.conversation.conversationId
      })
    });
  }

  if (window.HubSpotConversations) {
    onConversationsAPIReady();
  } else {
    window.hsConversationsOnReady = [onConversationsAPIReady];
  }
 </script>

 

 

The page I'm testing the chat widget on: https://www.mews.com/en/campaigns/test 

 

@IsaacTakushi I know you've spoken a fair about this in the forum as I've read about it quite a lot. Anything you can think of?

0 Upvotes
1 Accepted solution
piersg
Solution
Key Advisor

Hubspot chat widget events not working

SOLVE

Ah never mind, I was being silly. conversationStarted is triggered when the user sends the first message, not when they open the chat widget. My bad (I'd had a long day, I swear!)

View solution in original post

1 Reply 1
piersg
Solution
Key Advisor

Hubspot chat widget events not working

SOLVE

Ah never mind, I was being silly. conversationStarted is triggered when the user sends the first message, not when they open the chat widget. My bad (I'd had a long day, I swear!)