Hi! Thank you for the script. Do you mind telling me how you got it in a GMT trigger, so that it can fire?
Do you add the script you provided as a custom HTML tag in Tag Manager that fires on “All Pages” (the Page View trigger)?
It does not seem to fire any events when I set it up this way.
I entered your code and not seeing data come through in GA, any tips? Also, I need to push multiple converion pixels though this code, what is the best way to do this? Copy and paste the code multiple times, our append the code at the end to fire all the pixels I need fired?
Hello,
I have met your post and we have managed to send sales to Google Ads, Analytics and send click and lead event with the HubSpot chat.
I am not a technician but it still helps you with your development team.
1. We collect variables such as clientid and gclid in each user’s session cookie (client with Google Analytics and Google Ads, and gclid to attribute sales to campaigns in Ads).
2. You must save this information as a contact property in HubSpot. And save it as a hidden field in a form.
3. With this information you can generate a Webhook that you can send to the different platforms by API in Google Ads (complicated by Google documentation) and Measurement protocol by Google Analytics (I do not know if there is another way but surely this is the easiest ).
In this way you can send the information in a workflow and webhook when there is a sale, lead or any action (for example).
4. For the chat, we have recently been able to send all user information. To do this you must activate the possibility of creating contacts in HubSpot without the need for email. Then after a chat action event (click or conversation), send the information via the HubSpot API and create a form with the user token to associate the Chat conversation and the information collected with the contact. (look this post)
Then in the logic of the chat you can send a webhook to Google Analytics or Google Ads to send the event.
In short, this is what we have implemented to be able to collect and send events with the integral and measured funnel.
Your post and requirement has time, but I hope it helps you or someone else.
![]()
Is this still the best method for tracking Chat in GTM?
More recently HS have released “Conversation Live Chat Widget API” (https://community.hubspot.com/t5/APIs-Integrations/Hubspot-Livechat-on-Google-Tag-Manager/m-p/293219/highlight/true#M27362)
However it seems less straightforward than the solution in this thread.
@znicholson both will likely work. Probably best to use the public API though. Do you have specific questions about how to use it? HubSpot writes their JavaScript docs using ES6 syntax which isn’t natively supported in all browsers and it can look a little odd. See below for a more supported JS syntax:
<script>window.HubSpotConversations.on('conversationStarted', function(payload){
dataLayer.push({'event': 'hs_chat_started'}); // This will need customized to your particular needs.
});</script>
I’ve used both snippets below to push a GA event whenever a conversation is started, but neither seem to work. Do you know what I’m doing wrong here?
//Option A
<script type="text/javascript">
window.HubSpotConversations.on('conversationStarted', payload => { ga('send', 'event', 'Beacon', 'chat-started', 'Hubspot'); });
</script>
//Option B
<script type="text/javascript">
window.HubSpotConversations.on('conversationStarted', function(payload){ ga('send', 'event', 'Beacon', 'chat-started', 'Hubspot'); });
</script>
@jamesthrasher do you have a URL where you are attempting this?
It should be on any page here: https://www.atlasrfidstore.com/
I tried a third snippet found here, and it didn’t work either for some reason: https://gist.github.com/robwent/0375f2926d175d99224d8725d6e39d7b
I was able to get it working on my site. Would anyone be interested in a pre-made GTM recipe that leverages the Conversations API events?
Edit: You can track the Conversation API events from the HubSpot Live Chat widget using this GTM recipe.
Yes send de json to me please, or paste here GTM prints… ![]()
This recipe is brilliant, but we really need it to include “contactAssociated” for conversion tracking, is there any update on this?
Most of the replies so far have involved using the Conversations API event listeners.
@derekcavaliero’s reply being the accepted solution.
I just wanted to add to this that HubSpot have now introduced a `contactAssociated` event.
I have just implemented a usage for this to push an AdWords conversion event when triggered by our Chat Flow setup which asked for name and email, thus creating/associating a contact from the chat user. We are considering this as conversion rather than just starting a chat conversation.
An approximation of what I implemented:
function onConversationsAPIReady() {
window.HubSpotConversations.on('conversationStarted', function(payload){
//console.log("HubSpot Conversation Started");
// Do something here to track if necessary
});
window.HubSpotConversations.on('contactAssociated', function(payload){
//console.log("HubSpot Contact Associated");
// Do whatever you like here to track
if(typeof window.gtag === 'function'){
//Event snippet for Chat Contact Associated conversion page
window.gtag('event', 'conversion', {'send_to': 'YOUR/CONVERSION/ID/HERE'});
}
});
}
Hope this helps!
@adampatpattison good catch, definately useful.
I will say it is best practice to push an event to something like GTMs dataLayer rather than explicitly pushing to a platform in the event listener itself. That keeps your tracking tags visible inside GTM and auditable/testable using its debug and preview tools.