{"id":4722,"date":"2020-09-15T15:32:44","date_gmt":"2020-09-15T12:32:44","guid":{"rendered":"https:\/\/trackingchef.com\/?p=4722"},"modified":"2023-07-02T11:46:14","modified_gmt":"2023-07-02T08:46:14","slug":"hubspot-chat-conversions-in-gtm","status":"publish","type":"post","link":"https:\/\/trackingchef.com\/google-tag-manager\/hubspot-chat-conversions-in-gtm\/","title":{"rendered":"Reporting Hubspot Chat conversions in external platforms"},"content":{"rendered":"\n

Hubspot’s Chat is one tool my clients love to use to drive conversions on their sites.<\/p>\n\n\n\n

This tool, introduced at the INBOUND 2017 event, plays a major role in Hubspot’s concept of Conversational Marketing.<\/p>\n\n\n\n

Over the years, multiple options have been added to automate the chat and trigger it selectively, making it a powerful Lead Generation and Support tool. As with other Hubspot features, these interactions are reported in detail within the platform. But if you want to report on these elsewhere, for example for optimizing a LinkedIn Ads campaign, you can’t easily connect the dots for proper attribution.<\/p>\n\n\n\n

After running into this issue myself, I’ve contacted Hubspot’s support and they’ve shown me this neat trick that I wanted to share.<\/p>\n\n\n\n

The basic gist is to use Hubspot’s Chat API to trigger the various events. The events captured in the script below are two:<\/p>\n\n\n\n

    \n
  1. conversationStarted – A visitor has entered their first message in a conversation<\/li>\n\n\n\n
  2. contactAssociated – The visitor has submitted their email<\/li>\n<\/ol>\n\n\n\n
    <script>\nfunction onConversationsAPIReady() {\n    window.HubSpotConversations.on('contactAssociated', function(payload) {\n        \/\/ Some code to run\n    });\n    window.HubSpotConversations.on('conversationStarted', function(payload) {\n        \/\/ Some other code to run\n    });\n}\nif (window.HubSpotConversations) {\n    onConversationsAPIReady();\n} else {\n    window.hsConversationsOnReady = [onConversationsAPIReady];\n}\n<\/script><\/code><\/pre>\n\n\n\n

    Generic Chat tracking in GTM<\/h2>\n\n\n\n

    If you’re using Google Tag Manager (GTM) you can set up a Custom Event to indicate chat interactions.<\/p>\n\n\n\n

    In GTM, create a new tag of the type Custom HTML. Paste into the tag the following script:<\/p>\n\n\n\n

    <script type=\"text\/javascript\">\r\nfunction onConversationsAPIReady() {\r\n    window.HubSpotConversations.on('contactAssociated', function(payload) {\r\n        window.dataLayer.push({\r\n            'event': 'hubspot_chat_lead',\r\n            'chat_id': payload.conversation.conversationId\r\n        })\r\n    });\r\n    window.HubSpotConversations.on('conversationStarted', function(payload) {\r\n        window.dataLayer.push({\r\n            'event': 'hubspot_chat_started',\r\n            'chat_id': payload.conversation.conversationId\r\n        })\r\n    });\r\n}\r\nif (window.HubSpotConversations) {\r\n    onConversationsAPIReady();\r\n} else {\r\n    window.hsConversationsOnReady = [onConversationsAPIReady];\r\n}\r\n<\/script><\/code><\/pre>\n\n\n
    \n
    \"\"
    Custom HTML Tag to track Hubspot Chat interactions<\/figcaption><\/figure><\/div>\n\n\n

    Trigger the tag on ‘All Pages’.<\/p>\n\n\n\n

    This tag will now trigger a Custom Event on each Contact Associated (hubspot_chat_lead<\/em>) and Conversation Started (hubspot_chat_started<\/em>) event. Use these events to create new Custom Event triggers,<\/p>\n\n\n\n

    \"\"<\/figure>\n\n\n\n

    To complete the setup for GA4, you can create a new GA4 Event tag with the event’s name set to {{Event}} and the chat’s ID captured as an event parameter (using a DataLater variable of that name).<\/p>\n\n\n

    \n
    \"\"<\/figure><\/div>\n\n\n

    This Custom Event can now be used to trigger additional platforms such as LinkedIn Ads or Google Analytics.<\/p>\n\n\n\n

    Chat tracking without GTM<\/h2>\n\n\n\n

    In case you don’t use GTM, you can still use this method to track chat conversions.<\/p>\n\n\n\n

    Simply add the following snippet to your site’s code:<\/p>\n\n\n\n

    <script>\nfunction onConversationsAPIReady() {\n    window.HubSpotConversations.on('contactAssociated', function(payload) {\n   fbq('track', 'Lead');\u200e\n   gtag('event', 'hubspot_chat_lead', {'chat_id' : payload.conversation.conversationId});\n    });\n    window.HubSpotConversations.on('conversationStarted', function(payload) {\n   gtag('event', 'hubspot_chat_started', {'event_category' : 'hubspot chat', 'chat_id' : payload.conversation.conversationId});\n    });\n}\nif (window.HubSpotConversations) {\n    onConversationsAPIReady();\n} else {\n    window.hsConversationsOnReady = [onConversationsAPIReady];\n}\n<\/script><\/code><\/pre>\n\n\n\n

    This example will trigger the event to Google Analytics and Facebook but can be also used to trigger LinkedIn or Google Ads conversions just the same.<\/p>\n","protected":false},"excerpt":{"rendered":"

    Hubspot’s Chat is one tool my clients love to use to drive conversions on their sites. This tool, introduced at the INBOUND 2017 event, plays a major role in Hubspot’s concept of Conversational Marketing. Over the years, multiple options have been added to automate the chat and trigger it selectively, making it a powerful Lead […]<\/p>\n","protected":false},"author":5,"featured_media":4736,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[39,42],"tags":[],"_links":{"self":[{"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/posts\/4722"}],"collection":[{"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/comments?post=4722"}],"version-history":[{"count":12,"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/posts\/4722\/revisions"}],"predecessor-version":[{"id":5662,"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/posts\/4722\/revisions\/5662"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/media\/4736"}],"wp:attachment":[{"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/media?parent=4722"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/categories?post=4722"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/tags?post=4722"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}