Hubspot Livechat on Google Tag Manager

Hi @IsaacTakushi I’m really struggling with this too, hoping you can help

I’m trying to get a ‘hs_chat_started’ event pushed into the datalayer when a chat is initiated. I’ve tried your code, but it’s not working:

<script>
window.HubSpotConversations.on('conversationStarted', function (payload) {
dataLayer.push({'event': 'hs_chat_started'});
});
</script>

I have a global form listener (below) which works perfectly:

<script type="text/javascript">
 window.addEventListener("message", function(event) {
 if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormSubmit') {
 window.dataLayer.push({
 'event': 'hubspot-form-success',
 'hs-form-guid': event.data.id
 });
 }
 });
</script>

We are trying to do the same for chat, but I can’t get it to work. All I want to do is use a GTM listener to listen for the ‘conversationStarted’ event and then push the conversation ID into the datalayer.

Are you able to help?

Thank you