Send chat activity to your analytics
Forward chat opens, messages, form submissions and ratings to Google Analytics or any tracker.
Last updated
help.ai already counts how visitors use the widget, under Analytics → Deployments. To see chat activity next to the rest of your site's data, such as in Google Analytics, forward the widget's events to your tracker.
This is the other direction from Report your site's events to help.ai, which sends your page's events to help.ai.
Pick the events you need#
message.text and a form's values are what the visitor typed. Keep them out of trackers that mustn't hold personal data: send the role or the formId instead.
Send them to Google Analytics#
With the Quick install script tag, put this after your Google tag. It works before and after the widget's script has loaded:
<script>
window.HelpAI = window.HelpAI || function () { (HelpAI.q = HelpAI.q || []).push(arguments); };
HelpAI('hook', 'default', 'open', () => gtag('event', 'chat_open'));
HelpAI('hook', 'default', 'message', (chat, event, data) => {
if (data.role === 'user') gtag('event', 'chat_message_sent');
});
HelpAI('hook', 'default', 'formSubmit', (chat, event, data) => {
gtag('event', 'chat_form', { form_id: data.formId, skipped: data.skipped });
});
</script>HelpAI('hook', widget, event, callback) calls you back with the widget, the event's name and its data. Use '*' as the widget to hear every widget on the page. '*' as the event hears every event, including many you won't want in reports, so name the ones you need.
Listen from your own code#
const chat = await HelpAI.ready();
const stop = chat.on('messageFeedback', ({ value }) => {
if (value) analytics.track('Chat reply rated', { value });
});on()returns a function that stops listening.- With the NPM package,
init()also takesonOpen,onClose,onMessageandonErrorcallbacks. HelpAI('hook', …)doesn't hear a<web-ai-chat>element: callon()on the element instead.- A callback that throws an error can't break the widget.
Every event and its data is in the API reference (opens another site).