Running a code snippet before a chatflow ends (Sending an event to Google Analytics)
SOLVE
Hello, has anyone tried adding an automation action (run a code snippet) right before the Hubspot Chatflow ends?
I've seen other threads on using GTM to track conversations started on the live chat, but not many on automated chatflows that can be used to collect contact information for a sales team to follow up with.
For eg. a chatflow that asks for the visitor's name, contact number, and time to call back, and sends that data to the team. But right before the chatflow ends, it sends an event to Google Analytics (like the below code snippet) so that that conversion can be recorded as a goal on GA.
Although I suspect since this code is executed within the chatflow, there's no need to add an event listener. This ensures that only when the user has submitted their details, would this code execute and send to GA as a goal completion.
My main challenge is not knowing where to insert the code within the code snippet and how to write the code. Pretty sure it's not just copying and pasting the javascript code inside...
I'm guessing can remove the callback function, since it's supposed to be just one-way (from Hubspot to GA), and the code should go right before the responseJson. And I might even be able to remove the responseJson portion.
Hope the above makes sense, and I'm not a developer so trying to get some help here. Thank in advance to whoever can help!
So you can use the below code to register your event on conversationStarted, so when a conversation gets started this event will immediately fire, you can add your code snippet on this event by registering it.
So you can use the below code to register your event on conversationStarted, so when a conversation gets started this event will immediately fire, you can add your code snippet on this event by registering it.