Hubspot Livechat on Google Tag Manager

Hi, @RiccardoPisani.

Thanks for sharing your code.

It sounds like you are expecting your code to trigger a custom HubSpot event named hs_chat_started. Is that correct?

If so, the following JavaScript will not do that:

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

because dataLayer.push({'event': 'hs_chat_started'}); only communicates with Google Tag Manager.

If you wish to trigger a HubSpot event on your page, you must use this Events JavaScript API method.

Add the following to your “New HubSpot Conversation listener” tag, after dataLayer.push({'event': 'hs_chat_started'});:

_hsq.push(["trackEvent", {
 id: {YOUR_HS_EVENT_ID}
 }]);